General Commands

Printing out all of the Ansible Facts

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

Playbook

Running a playbook limiting to certain sections

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

Scenarios

Restarting a server

  - name: Set Host name
    ...
    register: task_result

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

  - name: Wait for the reboot to complete if there was a change.
    wait_for_connection:
      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