bobbai 发表于 2018-7-30 10:25:26

ansible的playbook介绍和实战

# cat http.yml  
- hosts: testservers
  
remote_user: root
  
tasks:
  
- name: instal httpd service
  
    yum: name=httpd state=present
  
- name: copy httpd conf
  
    copy: src=/etc/httpd/conf/httpd.conf dest=/etc/httpd/conf/httpd.conf
  
    notify:
  
      - restart httpd service
  
- name: start httpd service
  
    service: name=httpd state=started enabled=true
  
handlers:
  
    - name: restart httpd service
  
      service: name=httpd state=restarted
  

  
# ansible-playbook http.yml
  

  
PLAY ************************************************************
  

  
GATHERING FACTS ***************************************************************
  
ok:
  
ok:
  

  
TASK: **************************************************
  
ok:
  
ok:
  

  
TASK: *******************************************************
  
changed:
  
changed:
  

  
TASK: ***************************************************
  
changed:
  
changed:
  

  
NOTIFIED: *********************************************
  
changed:
  
changed:
  

  
PLAY RECAP ********************************************************************
  
192.168.100.131            : ok=5    changed=3    unreachable=0    failed=0
  
192.168.100.132            : ok=5    changed=3    unreachable=0    failed=0
  

  
# ansible testservers -m shell -a 'netstat -nltp |grep 8090'
  
192.168.100.131 | success | rc=0 >>
  
tcp      0      0 :::8090                     :::*                        LISTEN      4216/httpd
  

  
192.168.100.132 | success | rc=0 >>
  
tcp      0      0 :::8090                     :::*                        LISTEN      36215/httpd
  

  
#
页: [1]
查看完整版本: ansible的playbook介绍和实战