Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
772 views
in Technique[技术] by (71.8m points)

yaml - how can I resolve this ansible playbook error?

When I run the playbook, it gives the following error:

fatal: [172.16.49.191]: FAILED! => { "msg": "The conditional check 'out.found' failed. The error was: error while evaluating conditional (out.found): 'dict object' has no attribute 'found' The error appears to be in '/root/test.yaml': line 51, column 6, but may be elsewhere in the file depending on the exact syntax problem. The offending line appears to be: # when: out.found - name: UbuntuAddDns1 ^ here " }

and this is my code:

---
- hosts: test
  tasks:
   - name: DebianRemoveOldDNS
     replace:
       path: /home/ansible/debian.file
       regexp: "dns"
       replace: "# dns"
     when:
       ansible_distribution == "CentOS1"
   - name: AddDNS1
     lineinfile:
       path: /home/ansible/debian.file
       line: dns-nameservers 85.85.85.85
     when:
       ansible_distribution == "CentOS1"
   - name: AddDNS2
     lineinfile:
       path: /home/ansible/debian.file
       line: dns-nameservers 95.95.95.95
       insertafter: dns-nameservers 85.85.85.85
     when:
       ansible_distribution == "CentOS1"

   - name: Get a list of *.config.file in /home/ansible
     find:
       paths: /home/ansible
       patterns: "*.config.file"
     register: my_find
     when:
       ansible_distribution == "CentOS"
   - name: EnsureContainNameservers
     lineinfile:
       path: /home/ansible/*.config.file
       regexp: "nameservers"
       state: absent
     check_mode: yes
     with_items: "{{ my_find.files }}"
     register: out
     when:
       ansible_distribution == "CentOS"
   - name: if be
     lineinfile:
       path: "{{ item.path }}"
       state: absent
       regexp: "          - "
     with_items: "{{ my_find.files }}"
  when:
       ansible_distribution == "CentOS"
     when: out.found
   - name: UbuntuAddDns1
     lineinfile:
       path: "{{ item.path }}"
       insertafter: "        adresses:"
       line: "          - 85.85.85.85"
     with_items: "{{ my_find.files }}"
     when:
       ansible_distribution == "CentOS"
     when: out.found
   - name: UbuntuAddDns2
     lineinfile:
       path: "{{ item.path }}"
       insertafter: "          - 85.85.85.85"
       line: "          - 95.95.95.95"
     with_items: "{{ my_find.files }}"
     when:
       ansible_distribution == "CentOS"
     when: out.found
   - name: if not be
     lineinfile:
       path: "{{ item.path }}"
       insertafter: "gateway"
       line: "      nameservers:"
     with_items: "{{ my_find.files }}"
     when:
       ansible_distribution == "CentOS"
     when: not out.found
   - name: UbuntuAddDnsAddress
     lineinfile:
       path: "{{ item.path }}"
       insertafter: "      nameservers:"
       line: "        adresses:"
     with_items: "{{ my_find.files }}"
     when:
       ansible_distribution == "CentOS"
     when: not out.found
   - name: UbuntuAddDns1
     lineinfile:
       path: "{{ item.path }}"
       insertafter: "        adresses:"
       line: "          - 85.85.85.85"
     with_items: "{{ my_find.files }}"
     when:
       ansible_distribution == "CentOS"
     when: not out.found
   - name: AddDNS2
     lineinfile:
       path: "{{ item.path }}"
       line: "          - 95.95.95.95"
       insertafter: "          - 85.85.85.85"
     with_items: "{{ my_find.files }}"
     when:
       ansible_distribution == "CentOS"
     when: not out.found
question from:https://stackoverflow.com/questions/65914579/how-can-i-resolve-this-ansible-playbook-error

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...