You can use ansible command line (ad-hoc) to make small changes however the real power lies in it's scripting capabilities using playbooks.
Ansible playbooks are use in Puppet and Chef.
Puppet → Module
Chef → Cookbook
Playbooks are divided into 3 sections:
- Targets Section - defines on which host(s) this playbook will be executed and how it will be executed.
This will be done over ssh
- Variable Section (Optional) - defines your variables which can be used by the playbook.
- Task Section - List all the modules you intend to run.
Here is a sample playbook.
Note: proper indentation is very important.
playbook - test.yml
---
- hosts: localhost
user: john
vars:
warningMsg: 'Welcome to this exciting time in your life.\nYou will never be the same\n'
tasks:
- name: Sample Task
copy:
dest: /tmp/warning
content: "{{ warningMsg }}"
|
This sample playbook will create a file on the defined host with the warning message defined.
To run this playbook simple issue the command: ansible-playbook <file.yml>
commandline
> ansible-playbook test .yml
[WARNING]: provided hosts list is empty, only localhost is available
PLAY ***************************************************************************
TASK [setup] *******************************************************************
ok: [localhost]
TASK [Sample Task] *************************************************************
changed: [localhost]
PLAY RECAP *********************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0
|
TODO
If you desire to run this script on a host besides localhost, you will need to ....
Modules
For a full list of modules that can be used with ansible, see http://docs.ansible.com/ansible/list_of_all_modules.html.
References
http://docs.ansible.com/ansible/playbooks_intro.html
http://docs.ansible.com/ansible/list_of_all_modules.html