Changes

Jump to navigation Jump to search
update best practices
== Best Practices ==
Use tags to organize your Building Ansible workAutomation Platform execution environments (EE) * https://www.redhat.com/architect/ansible-execution-environment-tips
Use caching (default is off) to be able to refer to host 'facts' without having to hit each host in a playbookUsing Python 3* https://docs.ansible.com/ansible/latest/reference_appendices/python_3_support.html* https://docs.ansible.com/ansible/latest/dev_guide/developing_python_3.html
* Use register of [https://docs.ansible.com/ansible/playbooks_variables.html variables] tags to create more 'facts'. Results vary from module to module. Use -v to see possible values. organize your Ansible work
There * Use caching (default is an order of precedence with [https://docs.ansible.com/ansible/playbooks_variables.html off) to be able to refer to host 'facts' without having to hit each host in a playbook variables], with role defaults the lowest priority and extra vars the winner.
* Use register of [https://docs.ansible.com/ansible/playbooks_variables.html variables] to create more 'facts'. Results vary from module to module. Use -v to see possible values.  * There is an order of precedence with [https://docs.ansible.com/ansible/playbooks_variables.html playbook variables], with role defaults the lowest priority and extra vars the winner. * The array notation is preferred over the dot notation for accessing variables.<br />
<nowiki>{{ ansible_eth0["ipv4"]["address"] }} over {{ ansible_eth0.ipv4.address }}</nowiki> because some keywords in Python would conflict
* Reserved words:** hostvars** group_names** groups** environemnt
* '''<code>inventory_hostname</code>''' is the name of the hostname as configured in Ansible's inventory host file. '''<code>ansible_hostname</code>''' is the discovered hostname
* You can use a variables file to put sensitive data in a different file (one excluded from git).
<source lang="yaml">
- hosts: all
</source>
* You can use variables on the command line (and besides key=value pairs, you can use json or yml)
<source lang="yaml">
---
<code>ansible-playbook release.yml --extra-vars "hosts=vipers user=starbuck"</code>
* Check [https://www.ansible.com/blog/ansible-performance-tuning Performance Tuning] like enabling <code>pipelining</code> which is off by default.
* Truthy values should always be expressed as '''one of <code>[false, true]</code>'''. Although the Ansible docs show that [https://docs.ansible.com/ansible/latest/YAMLSyntax.html#yaml-basics you can use several forms of expression for boolean values], and [http://yaml.org/type/bool.html the YAML spec specifies a fuller range of possibilities] described below, the Ansible documentation now also [https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html clarifies that only lowercase 'true' or 'false'] is compatible with [[yamllint]] options.
;YAML boolean values, not Ansible:
:<syntaxhighlight lang=ebnf>

Navigation menu