Changes

Jump to navigation Jump to search
209 bytes added ,  22:08, 3 August 2020
no edit summary
You can use the '''command module''' (secure but simple) or the '''[https://docs.ansible.com/ansible/shell_module.html shell module]'''. The latter may be useful if you need to run bash explicitly (defaults to /bin/sh); or anytime you need $HOME and redirection.
To sanitize any variables passed to the shell module, you should use <nowiki>"{{ var | quote }}" instead of just "{{ var }}"</nowiki> to make sure they don't include evil things like semicolons. 
== Example Commands ==
Note: control verbosity with <code>-vvvv</code>
# <code>ansible --help</code> display help
# <code>ansible --version</code> show version info
# <code>ansible -c local -i ~/ansible_hosts -m ping all</code> ping all the hosts in the inventory file
# <code>ansible '''-m setup''' wiki.example.com</code> Use the '''[https://docs.ansible.com/ansible/latest/setup_module.html setup]''' module to gather ansible 'facts' (aka [[ansible_variables]]) about that host.
The array notation is preferred over the dot notation for accessing variables.
<nowiki>{{ ansible_eth0["ipv4"]["address"] }} over {{ ansible_eth0.ipv4.address }} </nowiki> because some keywords in Python would conflict
Reserved words:
* environemnt
'''inventory_hostname''' is the name of the hostname as configured in Ansible's inventory host file. '''ansible_hostname''' is the discovered hostname
You can use a variables file to put sensitive data in a different file (one excluded from git).
* [http://jinja.pocoo.org/docs/dev/ Jinja] - the template engine for Ansible
* [https://cheat.readthedocs.io/en/latest/ansible/index.html Dan's Cheat Sheets]
{{References}}
[[Category:Virtualization]]
[[Category:Configuration Management]]
[[Category:DevOps]]

Navigation menu