Using tests as filters is deprecated. Instead of using result|succeeded use result is succeeded. This feature will be removed in version 2.9.

Answer from Damian Fajfer on Stack Overflow
🌐
GitHub
github.com › geerlingguy › ansible-role-repo-epel › issues › 30
The conditional check 'result.rc == 0' failed · Issue #30 · geerlingguy/ansible-role-repo-epel
March 11, 2019 - The error was: error while evaluating conditional (result.rc == 0): 'dict object' has no attribute 'rc'"}
Author   geerlingguy
Top answer
1 of 2
5

Using tests as filters is deprecated. Instead of using result|succeeded use result is succeeded. This feature will be removed in version 2.9.

2 of 2
3

Correct answer and findings:

  1. 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 yum module if that failed due to connection reset or other reason. In that case, the only dict variable available for a failed action was result.rc != 0. Thus, in the until loop, until: result.rc == 0 condition worked for both successful/failed case for CentOS.

  2. In Ubuntu, if the apt module 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 use until loop 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.

Discussions

command/shell should have a "negative" failed_when exception
Summary I started with ansible, and frequently am running in situations where I am missing a feature, when command outputs suggest an error (and ansible stops processing), but this kind of error is one I want to ignore. Example (for addi... More on github.com
🌐 github.com
3
October 12, 2023
in messages/syslog we find "DONE: rc=0" after a rear run - make it more meaningful
Exit code in messages file improvement rear version (/usr/sbin/rear -V): v2.0 OS version (cat /etc/rear/os.conf or lsb_release -a): n/a example: # grep DONE /var/log/messages Nov 25 17:20:45 client rear[14341]: DONE: rc=0 Would be better... More on github.com
🌐 github.com
6
November 28, 2016
Issue with the success/succeeded filter
The error was: error while evaluating conditional (result.rc == 0): 'dict object' has no attribute 'rc'\n\nThe error appears to have been in '/var/lib/awx/projects/andyc/rc_test.yml': line 11, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending ... More on github.com
🌐 github.com
6
May 25, 2017
c - What does `rc` for function return values mean? - Stack Overflow
Me, I'm boring and name the variable "result" instead of guess-the-acronym. ... You don't need to understand the naming of variables to understand code. You need to understand what the function foo() is, does, and returns to understand this code. Never trust what the return variable is named to explain what the code does... ... I think it's "return code". Mostly used to refer to integer return codes of 0... More on stackoverflow.com
🌐 stackoverflow.com
People also ask

Can I register multiple outputs in a single Ansible task?
No, each register captures the output of only one task. However, you can use structured outputs like dictionaries or lists to handle complex data.
🌐
cyberpanel.net
cyberpanel.net › blog › ansible-register
Ansible Register: Capture & Reuse Task Output Efficiently
Can I use registered variables across different plays?
By default, registered variables are available only within the play they were created. To pass them across plays, you’ll need to use facts or write them to a file.
🌐
cyberpanel.net
cyberpanel.net › blog › ansible-register
Ansible Register: Capture & Reuse Task Output Efficiently
What is the register keyword in Ansible?
The register keyword in Ansible is used to capture the output or result of a task and save it to a variable for use later in the playbook.
🌐
cyberpanel.net
cyberpanel.net › blog › ansible-register
Ansible Register: Capture & Reuse Task Output Efficiently
🌐
Reddit
reddit.com › r/ansible › issue with conditional loop in ansible playbook.
r/ansible on Reddit: Issue with conditional loop in ansible playbook.
December 8, 2023 -
Basically what I want to do is to first determine if the table "names" has been created since there may be delays in creating the table hence I am using with_sequence to keep trying for a certain number of times. If the table is detected then I run another script to add default users to the table. 

I am getting "the conditional check 'result.rc !=0' failed. The error was: error while evaluating conditional (result.rc !=0); 'result is undefined.

- name: detect if table exists 
  script: /detect.sh #this shell script returns 0 if the "names" table is found
   register:  result 
   with_sequence: count=100
   when: result.rc != 0 
- name: Add new user to detected table 
    script adduser.sh #adds a default user to the table "names"
    when: result.rc == 0 

I do notice that if i have:

  • debug: msg: "Return code {{result.rc}}" before with_sequence then i dont get the error and it runs... but I am a bit lost on why. Thanks!

🌐
GitHub
github.com › ansible › ansible › issues › 81963
command/shell should have a "negative" failed_when exception · Issue #81963 · ansible/ansible
October 12, 2023 - failed_when: (result.rc != 0) and ("It is already configured for your Uberspace account." not in result.stderr) changed_when: (result.rc == 0) or ("It is already configured for your Uberspace account." not in result.stderr)
Author   ansible
🌐
Ansible
docs.ansible.com › projects › ansible › latest › playbook_guide › playbooks_error_handling.html
Error handling in playbooks — Ansible Community Documentation
- name: Check if a file exists in temp and fail task if it does ansible.builtin.command: ls /tmp/this_should_not_be_here register: result failed_when: - result.rc == 0 - '"No such" not in result.stderr'
🌐
CyberPanel
cyberpanel.net › blog › ansible-register
Ansible Register: Capture & Reuse Task Output Efficiently
April 28, 2025 - Use ignore_errors: true when a failure is expected and pair it with conditionals like when: result.rc != 0.
🌐
GitHub
github.com › rear › rear › issues › 1089
in messages/syslog we find "DONE: rc=0" after a rear run - make it more meaningful · Issue #1089 · rear/rear
November 28, 2016 - Exit code in messages file improvement rear version (/usr/sbin/rear -V): v2.0 OS version (cat /etc/rear/os.conf or lsb_release -a): n/a example: # grep DONE /var/log/messages Nov 25 17:20:45 client rear[14341]: DONE: rc=0 Would be better...
Author   rear
Find elsewhere
🌐
GitHub
github.com › ansible › ansible › issues › 25027
Issue with the success/succeeded filter · Issue #25027 · ansible/ansible
May 25, 2017 - The error was: error while evaluating conditional (result.rc == 0): 'dict object' has no attribute 'rc'\n\nThe error appears to have been in '/var/lib/awx/projects/andyc/rc_test.yml': line 11, 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: if rc zero then run this task\n ^ here\n" } } TASK [if success then run this task] *******************************************12:30:06 changed: [localhost] TASK [debug] *******************************************************************12:30:06 ok: [localhost] => { "change
Author   ansible
🌐
Google Groups
groups.google.com › g › robotframework-users › c › Nq-0JKK3-5c
result object with rc0
${result} = <result object with rc 0> 0= 25= = ${effect} <result object with rc 0> ${object} <result object with rc 0> ------------ i have doubt in following · 1)<result object with rc 0> what it means · 2)how result.rc is printing 0 · 3)how get process result,get process object also printing result with object rc0 ·
Top answer
1 of 4
22

I think it's "return code". Mostly used to refer to integer return codes of 0/NULL or 1 form.

2 of 4
11

rc stands for "rutabaga casserole". What? You don't think so?!

Well the fact is no one can say what this really stands for because there are no mandated names in C code. It could stand for "return code" or "remote control" or whatever the author had in his head at the time.

I would like to know it's meaning to help with my understanding of the code

Your argument is inherently flawed. If you want to understand code better, make sure you read the documentation and source of the functions being used, never trust that the names of functions, or data types yield any precedence into what the code is actually doing.


Edit to address the comment:

Actually, I think your argument is flawed, Mike. It is absurd to say that knowing commonly used variable names won't help you understand code, despite the fact that they are not mandated. For example, it is well known that i is commonly used (but not mandated) as a loop increment variable across all languages.

It's a fair argument to say that there are indeed variable names that people tend to follow. We'll see ret or rc for a return value or a return code, frequently we'll see single variables a,b,c,...,i,j,k, used for looping operators. However making an assumption about what a variable does based on a name is a terrible idea.
Not only might your assumption about what the variable stands for be wrong (for example a simple i in an Ohm's law function might very well be the name chosen to represent current, nothing to do with looping) but also what makes sense to you might not be what made sense to the author.

example, the author has a variable int return_code. You might assume that's going to house the return code of the function, but maybe it's being used to check the returned value of a function called within the function you're evaluating and the variable int r is used for the return code instead.
Let's say you see the variable count is that going to be a loop iterator, or a count of a number of files, or is it a counting semaphore?

So, Chris Redford, I must respectfully disagree. It's not absurd to say that knowing commonly used variable names won't help understand code, because it won't do any better than reading the code itself, and it might lead you down a stray path thinking you know what is going on when you really don't.
If you understand source code you'll see return xxx; or for(int yyy=0; and you won't have to make assumptions about what those variables are doing, you'll know for sure, and that's the only way to be guaranteed you know what's happening.

🌐
Medium
medium.com › @dvineeth10 › ansible-error-handling-9391f83081d2
Ansible Error Handling. 1.Error Handling in Ansible: | by Vineeth D | Medium
July 22, 2024 - -name: Handle errors based on command result debug: msg: “Task succeeded” when: cmd_result.rc == 0 # Execute this task only if the previous command succeeded
🌐
SAS Support Communities
communities.sas.com › t5 › SAS-Programming › Need-to-get-the-return-code-rc-0 › td-p › 240453
Need to get the return code(rc=0) - SAS Support Communities
December 23, 2015 - data x; set sashelp.class; run; %put WARNING: &syscc rc=&sysrc &syserr &syserrortext &syswarningtext; data x; set sashelp.class; x=input(sex,8); run; %put WARNING: &syscc rc=&sysrc &syserr &syserrortext &syswarningtext;
🌐
Rust
doc.rust-lang.org › std › rc › struct.Rc.html
Rc in std::rc - Rust
#![feature(allocator_api)] use std::rc::Rc; let zero = Rc::<u32>::try_new_zeroed()?; let zero = unsafe { zero.assume_init() }; assert_eq!(*zero, 0); ... Constructs a new Pin<Rc<T>>. If T does not implement Unpin, then value will be pinned in memory and unable to be moved. ... Maps the value in an Rc, reusing the allocation if possible. f is called on a reference to the value in the Rc, and the result is returned, also in an Rc.
🌐
GitHub
github.com › ansible › ansible › issues › 40328
Handling errors not working? · Issue #40328 · ansible ...
May 17, 2018 - failed: [localhost] (item=table1) => { "changed": true, "cmd": "aws dynamodb update-table --table-name \"default.table1\" --stream-specification StreamEnabled=true,StreamViewType=\"NEW_AND_OLD_IMAGES\" --profile \"default\" --region \"us-west-1\"", "delta": "0:00:01.411326", "end": "2018-05-17 16:52:20.840013", "failed_when_result": true, "invocation": { "module_args": { "_raw_params": "aws dynamodb update-table --table-name \"default.table1\" --stream-specification StreamEnabled=true,StreamViewType=\"NEW_AND_OLD_IMAGES\" --profile \"default\" --region \"us-west-1\"", "_uses_shell": true, "chdir": null, "creates": null, "executable": null, "removes": null, "stdin": null, "warn": true } }, "item": "table1", "rc": 0, "start": "2018-05-17 16:52:19.428687", "stderr": "", "stderr_lines": [], "stdout": " JSON OUTPUT RETURNED.
Author   ansible
🌐
Reddit
reddit.com › r/ansible › ansible ad hoc non-zero return error
r/ansible on Reddit: Ansible ad hoc non-zero return error
March 13, 2023 -

Hello All,

I am getting a non-zero error when I run the following ad-hoc
ansible fib -m raw -a "show version" -u admin -k
*fib is the host name

I have gone through the posts here, but I cannot get it resolved, I am able to run playbooks successfully and able to ssh into the device but I cannot run ad hoc command using the raw module

🌐
Ansible
forum.ansible.com › get help
Receiving non zero return code error while running raw module - Get Help - Ansible
November 9, 2023 - Hello, I’m new to ansible and I need some help. I have been trying to test running raw module to cisco devices but I keep receiving a failed error and get the following message: FAILED! => {“changed”: true, “msg”: “non-zero return code”, “rc”: 127, “stderr”: “/bin/sh: ...