Ansible playbooks

From wikieduonline
Revision as of 07:24, 16 January 2020 by Welcome (talk | contribs) (Created page with "Ansible playbooks<ref>https://docs.ansible.com/ansible/latest/user_guide/playbooks.html</ref> are written in YAML text files and define actions to execute agai...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Ansible playbooks[1] are written in YAML text files and define actions to execute against host/devices, check official Ansible playbook introduction: https://docs.ansible.com/ansible/devel/user_guide/playbooks_intro.html

Task definitions or Playbooks

Task definitions are defined in text files, called playbooks in Ansible terminology, in YAML format. Execution of task definitions or playbooks are make using ansible-playbook command followed by your desired playbook to execute. Playbooks can also use Jinja templates to enable dynamic expressions and access to variables[2].

Ansible Playbook execution:

  • ansible-playbook my_new_created_playbook.yml
  • ansible-playbook my_new_created_playbook.yml -f 10 -f 10 parallelize 10 executions
-f forks

Create "Executable" Playbooks

Add the following line #!/usr/bin/env ansible-playbook at the beginning of your playbooks and make it executable chmod +x /path/to/your/playbook.yml to execute without calling ansible-playbook binary.

Ansible Playbooks Examples

Create a new file touch /tmp/test_file.txt, REMOTE_SERVER should be already present in your Ansible inventory:/etc/ansible/host

Playbook using module file[3]:

- hosts: REMOTE_SERVER_HOSTNAME
  tasks:
  - name: Ansible create a new file called test_fle.txt in /tmp directory
    file:
      path: "/tmp/test_file.txt"
      state: touch

Important Note: dash symbol (-) and indentation has to be properly formatted.

Variables

You can use variables in your playbooks, check official documentation for further information: https://docs.ansible.com/ansible/devel/user_guide/playbooks_variables.html


Activities

See also


Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy.

Source: wikiversity

Advertising: