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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…