Variable: pass the variable to the handler

I use the eye as a supervisor, and with changes to the templates, it should do something like this:

eye load service.rb eye restart service.rb 

I want to define this as one handler for all applications and call it as

 eye reload appname 

And in the handler they work like this:

 - name: reload eye service command: eye load /path/{{ service }}.rb && eye restart {{ service }} 

But I cannot find a way to pass the variable to the handler. Is it possible?

+8
source share
1 answer

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 
0
source

Source: https://habr.com/ru/post/977003/


All Articles