hosts: dev user: root
tasks:
- name: install httpd
yum: pkg=httpd state=latest
notify: restart httpd
handlers:
- name: restart httpd
service: name=httpd state=restarted
[deyu1@kvm19 ansible]$ vim deploy.yml
[deyu1@kvm19 ansible]$ cat deploy.yml
---
- hosts: dev
tasks:
- name: install httpd
yum: pkg=httpd state=latest
notify: restart httpd
handlers:
- name: restart httpd
service: name=httpd enabled=yes state=restarted
[deyu1@kvm19 ansible]$ ansible-playbook deploy.yml PLAY [dev] ********************************************************************* TASK [Gathering Facts] ********************************************************* ok: [kvm11] TASK [install httpd] *********************************************************** changed: [kvm11] RUNNING HANDLER [restart httpd] ************************************************ changed: [kvm11] PLAY RECAP ********************************************************************* kvm11 : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
[deyu1@kvm19 ansible]$ ansible dev -m service -a "name=httpd state=started" --check
kvm11.deyu.wang | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"name": "httpd",
"state": "started",
"status": {
...........
[deyu1@kvm19 ansible]$ ansible dev -m service -a "name=httpd enabled=yes" --check
kvm11.deyu.wang | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"enabled": true,
"name": "httpd",
"status": {
...........