Posts

Showing posts from April, 2019

Best practices for writing better ansible playbooks

Some of the best practices for writing the clean and scalable ansible playbooks: Maintain all ansible code in git. Maintain the standard directory structure. Here is the reference:  https://github.com/Indu-sharma/learningansible Use requirements.txt for python dependencies management and requirements.yml for ansible-galaxy modules/roles. Configure ansible_stdout_callback, log file path, forks in ansible.cfg. Always use -check mode for ansible playbooks for the dry run.  Verify all your variables in advance with -m setup. Use ansible-galaxy init for your creating your roles directory/files structures. Within a role playbook, follow the sequence in the start Use assert to check that requirements are met Install packages Use Validate for Template config files  Trigger handlers when config files have been changed   Avoid using shell/command modules if possible; they are skipped in -check mode. Avoid using set_facts; they are not visible when using -m setup mode. Also,