Handlers / main.yml:
- name: restart my service shell: eye load /path/{{ service }}.rb && eye restart {{ service }}
So, you can set the default default variable /main.yml:
service : "service"
or you can define {{service}} though the command line:
ansible-playbook -i xxx path/to/playbook -e "service=service"
http://docs.ansible.com/ansible/playbooks_variables.html
PS: http://docs.ansible.com/ansible/playbooks_intro.html#playbook-language-
example --- - hosts: webservers vars: http_port: 80 max_clients: 200 remote_user: root tasks: - name: ensure apache is at the latest version yum: name=httpd state=latest - name: write the apache config file template: src=/srv/httpd.j2 dest=/etc/httpd.conf notify: - restart apache - name: ensure apache is running (and enable it at boot) service: name=httpd state=started enabled=yes handlers: - name: restart apache service: name=httpd state=restarted
http://docs.ansible.com/ansible/playbooks_intro.html#handlers-running-operations-on-change
If you ever want to immediately reset all handler commands, then in 1.2 and later versions you can:
tasks: - shell: some tasks go here - meta: flush_handlers - shell: some other tasks
source share