ansible May 31, 2020

General Commands

Printing out all of the Ansible Facts

ansible -i [inventory file name] [host name] -m setup > [file name]


Running a playbook limiting to certain sections

ansible-playbook [playbook name] -i [inventory host file] --limit [host section name]


Restarting a server

  - name: Set Host name
    register: task_result

  - name: Reboot immediately if there was a change
    when: task_result is changed

  - name: Wait for the reboot to complete if there was a change.
      connect_timeout: 20
      sleep: 5
      delay: 5
      timeout: 300
    when: task_result is changed

Useful Ansible Facts

Fact NamePurposeExampleansible_distributionOS Distribution NameUbuntuansible_distribution_versionVersion number of OS18.04ansible_distribution_releaseRelease name of OSbionic


Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.