hry*_*zik 10 ansible ansible-playbook
我使用"眼睛"作为主管,模板的更改必须运行如下:
eye load service.rb
eye restart service.rb
Run Code Online (Sandbox Code Playgroud)
我想将其定义为所有应用程序的单个处理程序,并将其称为
eye reload appname
Run Code Online (Sandbox Code Playgroud)
并在处理程序中运行如下:
- name: reload eye service
command: eye load /path/{{ service }}.rb && eye restart {{ service }}
Run Code Online (Sandbox Code Playgroud)
但我找不到将变量传递给处理程序的方法.可能吗?
处理程序/main.yml:
- name: restart my service
shell: eye load /path/{{ service }}.rb && eye restart {{ service }}
Run Code Online (Sandbox Code Playgroud)
所以你可以通过默认的defaults/main.yml设置变量:
service : "service"
Run Code Online (Sandbox Code Playgroud)
或者您可以通过命令行定义 {{ service }} :
ansible-playbook -i xxx path/to/playbook -e "service=service"
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
http://docs.ansible.com/ansible/playbooks_intro.html#handlers-running-operations-on-change
如果您想立即刷新所有处理程序命令,在 1.2 及更高版本中,您可以:
tasks:
- shell: some tasks go here
- meta: flush_handlers
- shell: some other tasks
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9313 次 |
| 最近记录: |