ansible playbook register debug

- 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


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章