Does anyone have any useful or clever Ansible tricks that you routinely use in the course of your normal daily activities?
One of the suggestion which i usually ensure to discuss is the name of each task.I suggest the task name should be name: Task 1 - TaskName by placing task numbers you have two benefits, 1. You know how many task you have in play 2. Troubleshooting, you can simply search for the failed task number and fix it.
I used to do this too, but I don't any longer. I found that if I needed to add a task or delete a task, I had to refactor a lot.
I also found that it made using roles more complicated.
I now use the "--list-tasks" and "--list-tags" extensively.
If playbooks are using roles instead of long tasks lists, the Task title will be prefixed with the name. So you get "<role>: Task title". This makes it easier to find tasks as well.
Yeah that's true, there would be way too much of editing in case you need to make a change.I prefer --list-tasks for listing the plays,tasks and tags.Have you noticed any extra info with --list-tags ?
Top tip from me - Create/Define a style guide. It makes life so much easier if everyone in your team/group/organization is working to the same standard.
Mine has things in it like:
Our style guide is much longer than that but you get the idea.
I think this is a good tip- one of the design goals of ansible is readability for people that are running playbooks. Having a style guide helps keep playbooks readable and consistent.
All modules are supposed to accept all forms of booleans. Where I've notice [someone needs to verify this...] that booleans behave a little differently is when variables are defined in an INI-style inventory file. I think I've had problems in an inventory file using booleans with these different styles.
I prefer for these booleans, to use the "yes" or "no" paradigm. Keeping that in mind, it helps me define better variable names knowning that the answer will be "yes" or "no".
Again - the aim for ansible is readability. Can you use True/False and 1/0 - yes. But from a stylistic point-of-view, I prefer yes/no for booleans to help improve readability.
Want to try Ansible in pull model?
Check it out: https://github.com/ansible/ansible-examples/blob/master/language_features/ansible_pull.yml
Good tip! ansible-pull is part of the standard ansible package. Thanks!
Please go through these sprints to clear the EX407
1. How to configure ansible environment ?
2. After configuring ansible environment how to associate the passwordless client to ansible server ?
3. Ansible all -m ping
4. ansible all -m setup --> to see the factor values from the clients
5. ansible all -m command -a "yum install httpd -y" --> for this you must have the privilaged escalation section in the ansible.cfg file
6. yum module
7. copy module --> from ansible server to all clients
8. copy module --> within client to the client in different directory
9. copy module --> while copying from ansible server to clients you must take the back of that source file
10. service module --> how to start the service
11. service module --> how to make persistant for the service across reboots
12. handlers --> whenever you use replace module or lineinfile module to replace any word in configuration file you can use this handlers section.For this in replace or lineinfile module play you need to use notify section.
13.Tagging ---> whenever you want to control the particular playbook execution then you need to add the tag value.so that while executing playbooks call the releavent tags.
14. local variable --> you can use the variable in every playbook inside file
15. Global variable --> you can mention it in inventory file and you can use it from any playbook
16. jinja2 template --> you can create jinja2 template file with ansible factor varaibles and then use jinja2 file (.j2 file) via template module
17. i want to download some file from the web url using get_url module
18. i want to monitor web urls using uri module
19. if i want to run any 2 linux commands sametime then you can use shell module.
20.If you get re-occur activities, say every week 100 server build and in every server build you need to keep install and configure set of similier tasks and packages.for this kinds of secnario then you need to use role type 1 method.
21.If you get bulk activities then apply role type2 with (item,vars and with_items) the necessary parameters.
22. If you really want to control your datacenter infrastructure then you create your own register and then whenever you create the register then print with jason format using debug: var option and then create the condition from the output.
23. if you really want to secure the file and use ansible-vault command to view,encrypt,decrypt,edit,create the file
24. insert_file --> will help you to understand the word manipulation via ansible.
25. while takeing any file backup you want to take back up with time date stamp,then use the below format in the playbook...
vars:
date: "{{ lookup('pipe', 'date +%Y%m%d-%H%M') }}"
26. I want to configure NFS Server and nfs client and nfs partition disk.
mount.yml --> refer this file
27. Want to implement ansible in windows infrastructure,then u install ansible in linux and configure the same --> LIP for ansible administration for windows machines v1.0
28. ansible-galaxy init jay --> just create role folder skeleton
29. we have to create AWS EC2 instance via ansible.for this you need ACCESS KEY and SECRET ACCESS KEY ID
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.