任务控制方式

   1.条件判断 when

- hosts: web
  tasks:

    -name: Install httpd server
     yum: name=httpd state=present
     when: ( ansible_distribution == "centos7" )

    -name: Install apache server
     yum: name=httpd2 state=present
     when: ( ansible_distribution == "ubuntu" )

- hosts: all
  tasks:
    -name: create yum repo
     yum_repository:
       name: ansible_nginx
       description: ansible_nginx
       baseurl: http://mirros.list.com
     when: ( ansible_fqdn is match("app*")) or ( ansible_fqdn is match("db*"))

    -name: check httpd server
     command: systemctl is-actived httpd
     ignore_errors: yes
     register: checkhttpd

    -name: httpd restart
     service: name=httpd state=present
     when: check_httpd.rc == 0
when控制

相关文章: