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.