hyzqb 发表于 2015-9-16 09:04:03

ansible使用6

tasks:  - name: "shutdown Debian flavored systems"
  command: /sbin/shutdown -t now
  when: ansible_os_family == "Debian"
  
  tasks:
  - command: /bin/false
  register: result
  ignore_errors: True
  - command: /bin/something
  when: result|failed
  - command: /bin/something_else
  when: result|success
  - command: /bin/still/something_else
  when: result|skipped
  
  # fact
  ansible hostname.example.com -m setup
  
  tasks:
  - shell: echo "only on Red Hat 6, derivatives, and later"
  when: ansible_os_family == "RedHat" and ansible_lsb.major_release|int >= 6
  
  # 变量
  vars:
  epic: true
  
  tasks:
  - shell: echo "This certainly is epic!"
  when: epic
  
  tasks:
  - shell: echo "This certainly isn't epic!"
  when: not epic
  
  # jinja2模板
  tasks:
  - shell: echo "I've got '{{ foo }}' and am not afraid to use it!"
  when: foo is defined
  
  - fail: msg="Bailing out. this play requires 'bar'"
  when: bar is not defined
  
  # loop
  tasks:
  - command: echo {{ item }}
  with_items: [ 0, 2, 4, 6, 8, 10 ]
  when: item > 5
页: [1]
查看完整版本: ansible使用6