# Variable registration is getting skipped in zypper module

**URL:** <https://forum.ansible.com/t/variable-registration-is-getting-skipped-in-zypper-module/30567>\
**Category:** Ansible Project\
**Created:** [June 13, 2019, 4:23pm UTC](https://forum.ansible.com/t/variable-registration-is-getting-skipped-in-zypper-module/30567 "2019-06-13T16:23:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bobby\_Hood](https://avatars.discourse-cdn.com/v4/letter/b/d78d45/32.png) [@Bobby\_Hood](https://forum.ansible.com/u/Bobby_Hood)\
**Post date:** [June 13, 2019, 4:23pm UTC](https://forum.ansible.com/t/variable-registration-is-getting-skipped-in-zypper-module/30567/1 "2019-06-13T16:23:31Z")

</div>

I’m using the zypper and apt modules to update remote hosts. I don’t know if I’m missing something or it’s a bug, but registering a variable in the zypper module is getting skipped. It works fine in the apt module.

- name: (SuSE) Update all packages to latest versions  
when: ansible\_os\_family == “Suse”  
**zy** pper:  
name: ‘\*’  
state: latest  
type: package  
update\_cache: yes  
register: update\_result

- name: (Debian) Update all packages to latest versions

when: ansible\_os\_family == “Debian”  
apt:  
name: ‘\*’  
state: latest  
update\_cache: yes  
force\_apt\_get: yes  
autoremove: yes  
register: update\_result

This is the variable dump when using zypper. It’s always **“changed”: false** and **“skipped”: true** even if changes are made.

ok: [raamah] =\> {  
“update\_result”: {  
“changed”: false,  
“skip\_reason”: “Conditional result was False”,  
“skipped”: true  
}  
}

However, the apt module always returns values for “msg”, “stderr”, and “stdout” as seen below. Am I using the zypper module incorrectly or something?

ok: [webtest01] =\> {  
“update\_result”: {  
“changed”: false,  
“failed”: false,  
“msg”: “Reading package lists…\nBuilding dependency tree…\nReading state information…\nCalculating upgrade…\n0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\n”,  
“stderr”: “”,  
“stderr\_lines”: ,  
“stdout”: “Reading package lists…\nBuilding dependency tree…\nReading state information…\nCalculating upgrade…\n0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\n”,  
“stdout\_lines”: [  
“Reading package lists…”,  
“Building dependency tree…”,  
“Reading state information…”,  
“Calculating upgrade…”,  
“0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.”  
]  
}  
}

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [June 13, 2019, 4:37pm UTC](https://forum.ansible.com/t/variable-registration-is-getting-skipped-in-zypper-module/30567/2 "2019-06-13T16:37:26Z")

</div>

You are registering to the same variable in both tasks. Ansible will register regardless of the task being skipped or not.

If the suse/zypper task executes, I assume that the apt task should skip, as such, the zypper task registered with real data first, and then the apt task overwrites the result with a skipped info.

You should be using different register variable names for each task, to avoid this issue.

---

<div class="post-metadata">

**Author:** ![Bobby\_Hood](https://avatars.discourse-cdn.com/v4/letter/b/d78d45/32.png) [@Bobby\_Hood](https://forum.ansible.com/u/Bobby_Hood)\
**Post date:** [June 13, 2019, 4:45pm UTC](https://forum.ansible.com/t/variable-registration-is-getting-skipped-in-zypper-module/30567/3 "2019-06-13T16:45:08Z")

</div>

Ah I see, thank you.

---

<div class="post-metadata">

**Author:** ![Bobby\_Hood](https://avatars.discourse-cdn.com/v4/letter/b/d78d45/32.png) [@Bobby\_Hood](https://forum.ansible.com/u/Bobby_Hood)\
**Post date:** [June 13, 2019, 9:50pm UTC](https://forum.ansible.com/t/variable-registration-is-getting-skipped-in-zypper-module/30567/4 "2019-06-13T21:50:11Z")

</div>

Still having some trouble with this. I changed the registered variables to apt\_result and zypper\_result:

- name: (SuSE) Update all packages to latest versions  
when: ansible\_os\_family == “Suse”  
zypper:  
name: ‘\*’  
state: latest  
type: package  
update\_cache: yes  
register: zypper\_result
- name: (Debian) Update all packages to latest versions  
when: ansible\_os\_family == “Debian”  
apt:  
name: ‘\*’  
state: latest  
update\_cache: yes  
force\_apt\_get: yes  
autoremove: yes  
register: apt\_result

But the zypper module returns completely different parameters than the apt module. Shouldn’t it contain stdout and stderr too? I’ve tried removing all the apt stuff to eliminate any conflicts but the results didn’t change. This is the zypper\_result variable dump. It runs zypper update just fine on the host but I’m not getting the return values I want. At minimum I need the stdout and stderr output.

ok: [raamah] =\> {  
“zypper\_result”: {  
“changed”: false,  
“cmd”: [  
“/usr/bin/zypper”,  
“–quiet”,  
“–non-interactive”,  
“–xmlout”,  
“update”,  
“–type”,  
“package”,  
“–auto-agree-with-licenses”,  
“–no-recommends”  
],  
“failed”: false,  
“name”: [  
“\*”  
],  
“rc”: 0,  
“state”: “latest”,  
“update\_cache”: true  
}  
}

The apt dump again:

ok: [webtest01] =\> {  
“apt\_result”: {  
“changed”: false,  
“failed”: false,  
“msg”: “Reading package lists…\nBuilding dependency tree…\nReading state information…\nCalculating upgrade…\n0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\n”,  
“stderr”: “”,  
“stderr\_lines”: ,  
“stdout”: “Reading package lists…\nBuilding dependency tree…\nReading state information…\nCalculating upgrade…\n0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\n”,  
“stdout\_lines”: [  
“Reading package lists…”,  
“Building dependency tree…”,  
“Reading state information…”,  
“Calculating upgrade…”,  
“0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.”  
]  
}  
}

---

<div class="post-metadata">

**Author:** ![Sebastian\_Meyer](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@Sebastian\_Meyer](https://forum.ansible.com/u/Sebastian_Meyer)\
**Post date:** [June 13, 2019, 11:17pm UTC](https://forum.ansible.com/t/variable-registration-is-getting-skipped-in-zypper-module/30567/5 "2019-06-13T23:17:10Z")

</div>

Hi,

> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"cmd": [  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"/usr/bin/zypper",  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"--quiet",

the ansible zypper module calls zypper with --quiet, as you can check on  
the commandline that leads to zypper not writing to stdout, if there's  
nothing to do:

# zypper update  
Loading repository data...  
Reading installed packages...

Nothing to do.

---

<div class="post-metadata">

**Author:** ![Bobby\_Hood](https://avatars.discourse-cdn.com/v4/letter/b/d78d45/32.png) [@Bobby\_Hood](https://forum.ansible.com/u/Bobby_Hood)\
**Post date:** [June 13, 2019, 11:31pm UTC](https://forum.ansible.com/t/variable-registration-is-getting-skipped-in-zypper-module/30567/6 "2019-06-13T23:31:58Z")

</div>

Thanks, I thought that might be it. Seems pointless to suppress all the output. I used the “command” module instead with all the same parameters except --quiet and --xmlout and it’s working fine. And since I can’t use the “changed” parameter with command to see if any packages were updated (it always seems to return true), I’m instead checking its stdout for the string “Nothing to do”.
