playbook变量(七)template 基本使用 when

1、模拟6和7系统(6对应11、7对应12)

[root@linux-node1 ansible]# cat test_template2.yaml 
---
- hosts: date
  remote_user: root
  vars:
    - http_port: 99

  tasks:
    - name: install package
      yum: name=nginx
    - name: copy 7 template
      template: src=nginx.conf11.j2 dest=/etc/nginx/nginx.conf
      when: ansible_distribution_major_version == "7"
      notify: restart service
    - name: copy 6 template
      template: src=nginx.conf12.j2 dest=/etc/nginx/nginx.conf
      when: ansible_distribution_major_version == "6"
      notify: restart service
    - name: start service
      service: name=nginx state=started enabled=yes

  handlers:
    - name: restart service
      service: name=nginx state=restarted 

playbook变量(七)template 基本使用 when_第1张图片

 

 

 

 

你可能感兴趣的:(playbook变量(七)template 基本使用 when)