-> Command to validate Ansible playbook syntax:
ansible-playbook <playbook.yml> --syntax-check
-> Sample playbook to run command in localhost:
---
- name:Sample Ansible playbook
hosts: 127.0.0.1
connection: local
tasks:
- name: Display hostname
command: hostname
register: out
- debug: var=out.stdout_lines
-> Run a playbook:
ansible-playbook <playbook.yml>
-> Run multiple commands using playbook:
---
- name: Run multiple commands
hosts: 127.0.0.1
connection: local
vars:
unix_command: ls
tasks:
- name: Display name of the host
command: hostname
register: task1
- name: Execute {{ unix_command }}
command: {{ unix_command }}
register: task2
- debug: var=task1.stdout_lines
- debug: var=task2.stdout_lines
-> For more info refer: https://spacelift.io/blog/ansible-playbooks
Top comments (1)
Article is a good intro to playbooks. Beginners looking for a more basic intro to Ansible can see devopedia.org/ansible