- hosts: all
tasks:
- shell: ls -lrht /opt/appd | grep bak
register: appd_contents
- debug:
var: appd_contents
- shell: echo "motd contains the word hi"
when: appd_contents.stdout.find('bak') != -1
when 多個條件
tasks:
- name: "shutdown CentOS 6 and 7 systems"
command: /sbin/shutdown -t now
when: ansible_distribution == "CentOS" and
(ansible_distribution_major_version == "6" or ansible_distribution_major_version == "7")
debug 過個變量
- hosts: all
tasks:
- shell: ls -lrht /opt/appd | grep machine
register: appd_contents
- debug:
msg:
- "hahx{{ inventory_hostname }}xahahha"
- "hahh{{ appd_contents.stdout }}ahahha"
- shell: echo "motd contains the word hi"
when: ansible_distribution == "CentOS" and appd_contents.stdout.find('bak') == -1