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:
---
- name: Check the correct repos
hosts: all
vars:
distribution_list:
- ALOS
- CentOS
- OracleLinux
tasks:
- name: check it is a recognised distro
fail:
when: ansible_distribution not in distribution_list
- name: Centos6 Install yum-utils
yum:
name: "yum-utils"
disablerepo: "*"
enablerepo: "CentOS6_Base*"
state: present
register: resultyumutilscentos6
when:
ansible_distribution == "CentOS" and ansible_distribution_major_version == "6"
- name: Centos7 Install yum-utils
yum:
name: "yum-utils"
disablerepo: "*"
enablerepo: "CentOS7_Base*"
state: present
register: resultyumutilscentos7
when:
ansible_distribution == "CentOS" and ansible_distribution_major_version == "7"
- 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
- name: centos6logupdateissue
command: logger -t GIS_ALERT_P3 -p local1.info "Subject=Error with yum update via autopatch; Body=See foreman server for more details"
when: resultupdateallcentos.rc > 0 and ansible_distribution == "CentOS" and ansible_distribution_major_version == "6"
- name: centos7logupdateissue
command: logger -t GIS_ALERT_P3 -p local1.info "Subject=Error with yum update via autopatch; Body=See foreman server for more details"
when: resultupdateallcentos.rc > 0 and ansible_distribution == "CentOS" and ansible_distribution_major_version == "7"
- name: centos6showtask # As the update has ignore_errors so that above logger can run, need to ensure entire job is marked as failed if rc >0
debug: msg="{{ resultupdateallcentos }}"
failed_when: resultupdateallcentos.rc > 0
when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "6"
- name: centos7showtask # As the update has ignore_errors so that above logger can run, need to ensure entire job is marked as failed if rc >0
debug: msg="{{ resultupdateallcentos }}"
failed_when: resultupdateallcentos.rc > 0
when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "7"
handlers:
- name: check for need to reboot
command: needs-restarting -r
register: result
ignore_errors: yes
notify: Alert on reboot from syslog
failed_when: result.rc > 1 # rc 1 means rebooted needed, not that the command failed
- name: Alert on reboot from syslog
command: logger -p local1.info "System rebooted by autopatch"
when: result.rc == 1
notify: Reboot client if required
- name: Reboot client if required
reboot:
when: result.rc == 1 # rc 1 = needs reboot
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c9cd6a5d-4038-407e-bc6c-a45e76e9992cn%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/e07bc5d7-6587-4f65-9e31-6c956b2a9b0bn%40googlegroups.com.