Skip to main content
  1. Notes/
  2. Ansible/

Ansible

169 words
Table of Contents

documentation
#

Most of the needed documentation can be found on the command line:

  • ansible-doc -l: lists all the modules available to you
  • ansible-doc <module>: extensive documentation on your module

Overall documentation can be found on Ansible Docs.

environment
#

  • ANSIBLE_KEEP_REMOTE_FILES=1, do not remove the temporary files
  • ANSIBLE_CONFIG=<filename>, alternative path in ansible.cfg

playbooks
#

  • start with three dashes
  • add name where you can for clarity
  • a playbook can contain multiple plays

reference
#

roles
#

Example layout:

example
├── defaults
│   └── main.yml
├── files
├── handlers
│   └── main.yml
├── meta
│   └── main.yml
├── README.md
├── tasks
│   └── main.yml
├── templates
├── tests
│   ├── inventory
│   └── test.yml
└── vars
    └── main.yml

modules
#

get_url:

- name: download foo.conf
  get_url:
    url: http://example.com/path/file.conf
    dest: /etc/foo.conf
    mode: 0440

stat:

# Obtain the stats of /etc/foo.conf, and check that the file still belongs
# to 'root'. Fail otherwise.
- stat: path=/etc/foo.conf
  register: st
- fail: msg="Whoops! file ownership has changed"
  when: st.stat.pw_name != 'root'
  • stat
  • lineinfile
  • replace
  • command