Customizing Hosts, Runs, Handlers Flashcards
What are possible host patterns?
all, union, intersection, exclusion, wildcard, range, regular expression
Explain intersection in host definition and give an example
Apply a task on the intersection of two groups.
hosts: database:&staging
Explain union in host definition and give an example
Apply a task on the union of two groups.
hosts: database:staging
Explain exclusion in host definition and give an example
Apply a task on the exclusion of a group from another groups.
hosts: database:!staging
Explain wildcard in host definition and give an example
Apply a task on set of hosts matching an expression defined with wildcard.
hosts: *.example.com
Explain range in host definition and give an example
Apply a task on set of hosts defined by range
hosts: web[1:20].example.com
Explain regex in host definition and give an example
Apply a task on set of hosts defined by regular expression
hosts: ~web\d+.example.(org|com)
Sketch a command that would run a playbook.yml against a group of hosts web as opposed to the whole invetory.
ansible-playbook -l web playbook.yml
Sketch a command that would run a playbook.yml against a group of hosts using filters.
ansible-playbook -l web:staging playbook.yml
What clause allows you to run a command on the control machine?
local_action
Give an example scenario where running a command on the control host makes sense and provide the correspdoning ansible task.
We restarted the managed host and we have to wait for it to be back before we do other configuraions. In this case, the wait will be on the control node.
-name: wait for managed host to be back
local_action: wait_for port=22 host=”{{ inventory_hostname}}” search_regex=OpenSSH
What are some use cases where you might want to run a command on a node other than the control and the managed node?
1) You have to add the managed node to a load balancer
2) You have to configure an alerting system to watch the managed node
What is the key clause that enables running a command on a node other than the control and the managed nodes?
delegate_to
Provide an example task of running a command on a node other than the control and the managed nodes?
- name: enable alerts
nagios: action=enable_alerts service=web host={{ inventory_hostname}}
delegate_to: nagios.example.com
What is the default execution mode: one node after anorher or all nodes in parallel?
all nodes in parallel.
Cite an example where running ansible on managed node in sequence would make sense as opposed to running in parallel.
Upgrading a production application where many nodes are behing a LB. Becase don’t need the service interruption, we would upgrade one node at a time.
What clause do you use to run the playbook on one node at a time?
serial:1
What clause do you use to run the playbook on 20% of node at a time?
serial: 20%
I have 5000 nodes in my inventory. I want to try the playbook on one node first and then run it on 10% of nodes at a time. what is the right construct for this?
serial:
- 1 - 20%
Explain max_fail_percentage
Allows you to specify the number of nodes that are allowed to fail when running the playbook. The value is in percentage. Beyond the specified percentage, Ansible will stop running the playbook.
What is the clause for running a playbook only once?
run_once: true
What scenario can it be useful to run the playbook only once?
database initialization or sometimes local actions
What are example of ansible running strategies?
linear, free
What is the default Ansible running strategy?
linear