Ansible: Difference between revisions

clean up link to Releases and Maintenance
 
(7 intermediate revisions by the same user not shown)
Line 8: Line 8:




Also, RedHat seems to have purposely made things very convoluted in terms of versioning, release cycles and product naming. So check https://docs.ansible.com/ansible/latest/reference_appendices/release_and_maintenance.html and see if you can figure it out. <ref>In 2024 people are still '''[https://www.reddit.com/r/ansible/comments/1chyjdc/confused_about_ansible_documentation_and_versions/ Confused about Ansible documentation and versions]''' It's rather ridiculous that their ansible-core project does NOT use SemVer</ref>
Also, RedHat seems to have purposely made things very convoluted in terms of versioning, release cycles and product naming. So check [https://docs.ansible.com/ansible/latest/reference_appendices/release_and_maintenance.html '''Releases and Maintenance'''] and see if you can figure it out. <ref>In 2024 people are still '''[https://www.reddit.com/r/ansible/comments/1chyjdc/confused_about_ansible_documentation_and_versions/ Confused about Ansible documentation and versions]''' It's rather ridiculous that their ansible-core project does NOT use SemVer</ref> In [[Meza]], we use 'ansible-core' which does not follow [[Semantic Versioning|SemVer]], while the Community Project does follow SemVer


==Installation==
==Installation==
Line 35: Line 35:
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>
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
'''But''', it worked fine for me in the Meza 1_39 upgrade using Ansible 2.9.27 I think the reason it worked was that I was using old-galaxy.ansible.com in my ansible.cfg which was backwards compatible.
</ref>  
</ref>  


Line 61: Line 61:
#<code>ansible localhost -m setup --tree /tmp/facts</code> store all facts in a file 'tree', based on hostname
#<code>ansible localhost -m setup --tree /tmp/facts</code> store all facts in a file 'tree', based on hostname
#<code>ansible -m debug -a "var=hostvars['wiki.example.com']" localhost</code> gives you the '[[ansible hostvars]]'
#<code>ansible -m debug -a "var=hostvars['wiki.example.com']" localhost</code> gives you the '[[ansible hostvars]]'
#<code>ansible -m ansible.builtin.debug -a "var=hostvars['localhost']" -c local localhost</code> is another way of writing this using the fully qualified module name and working on localhost (no inventory needed; and actually you don't need to specify the connection as local because that is implied)
#<code>ansible-playbook play1.yml play2.yml</code> Run multiple playbooks
#<code>ansible-playbook play1.yml play2.yml</code> Run multiple playbooks
#<code>ansible-playbook -i production webservers.yml --tags ntp '''--list-tasks'''</code> confirm what task names would be run if I ran this command and said "just ntp tasks"
#<code>ansible-playbook -i production webservers.yml --tags ntp '''--list-tasks'''</code> confirm what task names would be run if I ran this command and said "just ntp tasks"
Line 71: Line 72:
==Variables==
==Variables==


;You have 3 plays in one playbook.  Will play 3 be able to reference facts registered in play 1?:
;I have 3 plays in one playbook.  Will play 3 be able to reference facts registered in play 1?:
:facts, yes, play vars, no
: facts: yes  
:vars associated to the host, persist, vars defined in the play, do not, set_facts, registered vars and gathered facts associate to the host so those do persist for the run
: play vars: no
: vars associated to the host, persist.
: set_facts, registered vars and gathered facts associate to the host, so those do persist for the run
: vars defined in the play, do not.


==Playbooks==
==Playbooks==
Ansible "[http://docs.ansible.com/playbooks.html Playbooks]" use an easy and descriptive language based on YAML.
Ansible "[http://docs.ansible.com/playbooks.html Playbooks]" use an easy and descriptive language based on YAML.
== With Meza ==
sudo meza deploy monolith -vvv -e group_wheel=wheel -e ansible_user=meza-ansible


==Roles==
==Roles==
Line 83: Line 90:
==Targets==
==Targets==
Ansible can deploy to virtualization environments and public and private cloud environments including VMWare, OpenStack, AWS, Eucalyptus Cloud, KVM, and CloudStack
Ansible can deploy to virtualization environments and public and private cloud environments including VMWare, OpenStack, AWS, Eucalyptus Cloud, KVM, and CloudStack
==Testing==
==Testing==
{{#evu:https://www.youtube.com/watch?v=FaXVZ60o8L8&t=1244s
{{#evu:https://www.youtube.com/watch?v=FaXVZ60o8L8&t=1244s
Line 96: Line 101:
#<code>yamllint</code>
#<code>yamllint</code>
#<code>ansible-playbook --syntax-check</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
#<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)
#molecule test (integration)
#<code>ansible-playbook --check</code> (against prod)
#<code>ansible-playbook --check</code> (against prod)
Line 138: Line 143:


*You can use a variables file to put sensitive data in a different file (one excluded from git).
*You can use a variables file to put sensitive data in a different file (one excluded from git).
<source lang="yaml">
<syntaxhighlight lang="yaml">
- hosts: all
- hosts: all
   remote_user: root
   remote_user: root
Line 145: Line 150:
   vars_files:
   vars_files:
     - /vars/top_secret.yml
     - /vars/top_secret.yml
</source>
</syntaxhighlight>


*You can use variables on the command line (and besides key=value pairs, you can use json or yml)
*You can use variables on the command line (and besides key=value pairs, you can use json or yml)
<source lang="yaml">
<syntaxhighlight lang="yaml">
---
---


Line 156: Line 161:
   tasks:
   tasks:
     - ...
     - ...
</source>
</syntaxhighlight>
<code>ansible-playbook release.yml --extra-vars "hosts=vipers user=starbuck"</code>
<code>ansible-playbook release.yml --extra-vars "hosts=vipers user=starbuck"</code>


Line 288: Line 293:
[[Category:Configuration Management]]
[[Category:Configuration Management]]
[[Category:DevOps]]
[[Category:DevOps]]
[[Category:Python]]