Please could someone give some help to this problem. I have I cant see anything wrong.
I have what looks like a bug in ansible_distribution. where it looks like its not getting picked up properly. Not sure how it obtains this information under the covers but it is returning correct info. Even although /etc/redhat-release has different content. to this
I’m running ansible 2.9.23
Ansible facts of the server I want to upgrade seem to be correct:
“ansible_distribution”: “CentOS”,
“ansible_distribution_file_parsed”: true,
“ansible_distribution_file_path”: “/etc/redhat-release”,
“ansible_distribution_file_variety”: “RedHat”,
“ansible_distribution_major_version”: “6”,
“ansible_distribution_release”: “Final”,
“ansible_distribution_version”: “6.10”,
THE ERROR IS :
FAILED! => {“msg”: “The conditional check ‘resultupdateallcentos.rc > 0 and ansible_distribution == "CentOS" or "ALOS" and ansible_distribution_major_version == "6"’ failed. The error was: error while evaluating conditional (resultupdateallcentos.rc > 0 and ansible_distribution == "CentOS" or "ALOS" and ansible_distribution_major_version == "6"): ‘dict object’ has no attribute ‘rc’\n\nThe error appears to be in ‘/tmp/d20221006-1291-1dvfink/project/playbook.yml’: line 63, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: centos6logupdateissue\n ^ here\n”}
CODE excerpt is:
These two tasks are registering their result to the same variable. Even if a task condition isn’t true the register variable is set.
-
name: Centos6 update
yum:
name: “"
disablerepo: "”
enablerepo: “CentOS6_Base*”
state: latest
register: resultupdateallcentos
ignore_errors: true
when:
ansible_distribution == “CentOS” and ansible_distribution_major_version == “6”
notify: check for need to reboot
-
name: Centos7 update
yum:
#name: “xxsxxcreen”
#name: “screen”
name: “"
disablerepo: "”
enablerepo: “CentOS7_Base*”
state: latest
register: resultupdateallcentos
ignore_errors: true
when:
ansible_distribution == “CentOS” and ansible_distribution_major_version == “7”
notify: check for need to reboot
At least that has been my experience. The CentOS 7 task likely is overwriting the registered result of the CentOS 6 task.
Walter
Hi I made the changes as suggested but Is still failing. any ideas ?
PLAY [Check the correct repos] *************************************************
3:
4:
TASK [Gathering Facts] *********************************************************
5:
[WARNING]: Platform linux on host hostname is using the
6:
discovered Python interpreter at /usr/bin/python, but future installation of
7:
another Python interpreter could change this. See https://docs.ansible.com/ansi
8:
ble/2.9/reference_appendices/interpreter_discovery.html for more information.
9:
ok: [hostname]
10:
11:
TASK [check it is a recognised distro] *****************************************
12:
skipping: [hostname]
13:
14:
TASK [Centos6 Install yum-utils] ***********************************************
15:
skipping: [hostname]
16:
17:
TASK [Centos7 Install yum-utils] ***********************************************
18:
skipping: [hostname]
19:
20:
TASK [Centos6 update] **********************************************************
21:
skipping: [hostname]
22:
23:
TASK [Centos7 update] **********************************************************
24:
skipping: [hostname]
25:
26:
TASK [centos6logupdateissue] ***************************************************
27:
fatal: [hostname]: FAILED! => {“msg”: “The conditional check ‘resultupdateallcentos6.rc > 0 and ansible_distribution == "CentOS" and ansible_distribution_major_version == "6"’ failed. The error was: error while evaluating conditional (resultupdateallcentos6.rc > 0 and ansible_distribution == "CentOS" and ansible_distribution_major_version == "6"): ‘dict object’ has no attribute ‘rc’\n\nThe error appears to be in ‘/tmp/d20221019-10194-1tbi3t/project/playbook.yml’: line 63, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: centos6logupdateissue\n ^ here\n”}
28:
PLAY RECAP *********************************************************************
29:
hostname : ok=1 changed=0 unreachable=0 failed=1 skipped=5 rescued=0 ignored=0
30:
Exit status: 2
Your error message tells you what is wrong - ‘dict object’ has no attribute ‘rc’
Place a debug statement before the failing task and display resultupdateallcentos6.
- debug: var=resultupdateallcentos6
Look at the output to see what is returned. Also note that ALL of you prior tasks are “skipping”. Maybe there is no ‘rc’ attribute because they are not executing. Figure out why they are all skipping. That might tell you why you have no ‘rc’ attribute.
Walter