Your second command contains a when clause. If it is skipped, ansible still registers the variable but there is no rc attribute in the data.
You need to take this into consideration when using the var in the next task. The following condition on last task should fix your issue.
when: blaze_undeployment_status.rc | default('') == 0 or blaze_deployment_status.rc == 1
Answer from Zeitounator on Stack Overflow'dict object' has no attribute 'rc'
shell module - error 'dict object' has no attribute 'rc' when running launchctl cmd
Error while evaluating conditional (not ansible_check_mode and rvm1_gpg_keys != '' and (gpg_import is not defined or gpg_import.rc != 0)): 'dict object' has no attribute 'rc'
Ansible register result result.stdout result.rc etc dict variable not found, how to use until loop - Stack Overflow
Videos
Using tests as filters is deprecated. Instead of using result|succeeded use result is succeeded. This feature will be removed in version 2.9.
Correct answer and findings:
In CentOS, if the action is successful and if the registered variable result is set, then a user can see these dict variables for ex: result.rc being 0, result.stdout = "something\nsomethingEsle\netc etc etc" and/or result.stdout_lines = "...same as above..." and result.results in some cases. If the action was failed, then I couldn't see result.stdout getting set in my case for using
yummodule if that failed due toconnection resetor other reason. In that case, the only dict variable available for a failed action was result.rc != 0. Thus, in theuntilloop,until: result.rc == 0condition worked for both successful/failed case for CentOS.In Ubuntu, if the
aptmodule action was successful, I got result.stdout and result.stdout_lines variables set but no result.rc dict variable set. For a failed operation, there's was no result.stdout or result.stdout_lines or result.rc dict variables set. SO, in case of Ubuntu, I couldn't useuntilloop using one of these dictionary variables.
The only workaround I can think of is, to wrap the apt-get install <pacakge> in a script and use until loop in BASH etc to do what Ansible is doing. At least, that'll be little easier to code and if the exit code is not 0, then I can use until.
But, I finally found a solution, which works in Ubuntu for both successful and failed cases:
Jinja2 filters may help i.e. when: result|failed therefore, if I have to use a registered variable result for a FAILED condition, then using with until, I'll use it (opposite of failed status) i.e. as:
until: result|succeeded
The good thing is that, the above until statement will work for both CentOS and Ubuntu and for both successful/failed states.
Hi
The following play works well with ubuntu 20.04 but fails with kali.
- name: Installing or updating RCLONE if required register: output shell: "curl https://rclone.org/install.sh | bash" args: warn: no failed_when: "output.rc == 1 or output.rc == 2 or output.rc == 4" changed_when: "output.rc == 0 "
Error on kali
fatal: [localhost]: FAILED! => {"changed": false, "changed_when_result": "The conditional check 'output.rc == 0' failed. The error was: error while evaluating conditional (output.rc == 0): 'dict object' has no attribute 'rc'. 'dict object' has no attribute 'rc'", "msg": "Unsupported parameters for (ansible.legacy.command) module: warn. Supported parameters include: _raw_params, _uses_shell, argv, chdir, creates, executable, removes, stdin, stdin_add_newline, strip_empty_ends."}I have been trying to fix this on kali running
ansible --version ansible [core 2.14.6] config file = None configured module search path = ['/home/whitehat/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3/dist-packages/ansible ansible collection location = /home/whitehat/.ansible/collections:/usr/share/ansible/collections executable location = /usr/bin/ansible python version = 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True
Any Idea how to fix it?
Regards, SD
The syntax you included:
when: me.cool is not defined
is correct.
You can also use not in:
when: "'cool' not in me"
The problem is that your error message:
The conditional check 'me.cool' failed.
claims your condition is defined as:
when: me.cool
So, either there is some bug in the version you use (but you did not share which one it is) and there were known issues, or you did not post the exact task that caused the error.
You can avoid 'dict object' has no attribute by using jinja2 selectattr() syntax as in :
when: me|selectattr("cool", "defined")|list|length >0
idea obtained from Michael Hoglan at https://groups.google.com/forum/#!topic/ansible-project/8XJkHQgttLA