Open main menu

Changes

no edit summary
===Initialize a Project===
Use '''[https://galaxy.ansible.com/ui/ Ansible Galaxy]''' If you want to do a new project, you can use the <code>ansible-galaxy foo init</code> command which will create the directory and file structure for 'foo' in the current working directory.
Also, if you want to install other Ansible Galaxy projects, you can either do it "manually" <code> ansible-galaxy install -r </code> Or, setup a 'requirements.yml' file in your playbook that then gets run by your stack. <ref>https://stackoverflow.com/questions/25230376/how-to-automatically-install-ansible-galaxy-roles</ref> <ref>Supposedly this only works for newer versions of Ansible, per the warning on their homepage:<blockquote> Warning alert:To be able to download content from galaxy it is required to have ansible-core>=2.13.9 Please, check it running the command: ansible --version</blockquote> '''But''', it worked fine for me in the Meza 1_39 upgrade using Ansible 2.9.27</ref>  <code>ansible-galaxy [delete|import|info|init|install|list|login|remove|search|setup] [--help] [options]</code>
==Modules==
==Playbooks==
Ansible "[http://docs.ansible.com/playbooks.html Playbooks]" use an easy and descriptive language based on YAML.
 
==Roles==
[https://www.redhat.com/sysadmin/developing-ansible-role 8 steps to developing an Ansible role] (aka when a playbook becomes a re-usable role)
==Targets==
#<code>yamllint</code>
#<code>ansible-playbook --syntax-check</code>
#<code>ansible-lint</code> https://ansible.readthedocs.io/projects/lint/ TLDR; you might want to setup a venv and then pip3 install ansible-lint
#molecule test (integration)
#<code>ansible-playbook --check</code> (against prod)
'''Play''': each play and contained structures, vars entries, include_vars, role defaults and vars.
'''Host''': variables directly associated to a host, like inventory, facts or registered task outputs
 
Another aspect of scope is <tt>includes</tt> vs. <tt>imports</tt> and loosely speaking, control structures like <tt>loop</tt> and the deprecated <tt>with_items</tt>
 
*https://stackoverflow.com/questions/68863854/iterate-list-within-role-task-provide-each-element-as-vars-to-include-tasks
*https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_reuse.html#comparing-includes-and-imports-dynamic-and-static-re-use
 
==Ansible with VSCode==
https://marketplace.visualstudio.com/items?itemName=redhat.ansible
==Ansible with Vagrant==
*https://docs.ansible.com/ansible/playbooks_conditionals.html#sts=The When Statement%C2%B6
 
==Controlling Whitespace in Jinja2 Templates==
See [[Controlling whitespace in Jinja2 templates]]
==Ansible References==
*http://jpmens.net/2012/06/06/configuration-management-with-ansible/
*[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]
*== To Do == # Follow and learn from Jeff Geerling's Drupal site https://github.com/geerlingguy/jeffgeerling-com because his techniques embody best practices for PHP, Drupal, Docker, Ansible, etc. In episode 12 of Ansible 101 - Real-world Ansible Playbooks [https://cheatwww.readthedocsyoutube.iocom/enlive/latest_QZr4xKhir4?si=LOyBibByqdmLb7M6&t=1107 here] he discusses his Drupal playbook and the 'deploy' tag. But sadly the playbooks are private (Midwestern Mac infrastructure), so you'll have to read the screen to emulate it exactly. The closest I found was https://github.com/geerlingguy/ansible-awx-varnish-php-app/indexblob/master/main.html Danyml# Add info (separate page) about the Ansible clone of the Ruby deployment system 'Capistrano' called 'Anistrano's Cheat Sheets]## https://www.oliverdavies.uk/talks/deploying-php-ansible-ansistrano## https://github.com/ansistrano/deploy
{{References}}