# Variable change if condition is not met !!! Register "skipped" ?

**URL:** <https://forum.ansible.com/t/variable-change-if-condition-is-not-met-register-skipped/17869>\
**Category:** Ansible Project\
**Created:** [March 30, 2015, 6:36am UTC](https://forum.ansible.com/t/variable-change-if-condition-is-not-met-register-skipped/17869 "2015-03-30T06:36:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adrian\_Paraschiv](https://avatars.discourse-cdn.com/v4/letter/a/f14d63/32.png) [@Adrian\_Paraschiv](https://forum.ansible.com/u/Adrian_Paraschiv)\
**Post date:** [March 30, 2015, 6:36am UTC](https://forum.ansible.com/t/variable-change-if-condition-is-not-met-register-skipped/17869/1 "2015-03-30T06:36:32Z")

</div>

I have a role that I need to use for more values. For each task within the role I register a variable: checkdeps (it’s the same for all tasks within this role - during a run it always has at least one value/output - I need it like this because the path differs “/opt/play/apps/default-ace”, “default-device” etc.) and in the end I do an echo to view the output of checkdeps.stdout.

Below I’ve put one task that will output ok and one that will intentionally will be skipped. If I use the parameter dep: APK\_PARSER in the playbook what it does is: first checkdeps registers the output and in the second task the value of checkdeps is replaced with nothing! Even though the task is skipped due to no matching dep parameter.

Why does the value of checkdeps is replaced if the condition is not met ?

```auto
- name: "output ok"
  shell: "cd /opt/play/apps/default-ace && play deps {{ dep }}"
  register: checkdeps
  when: "dep == \"APK_PARSER\""

- name: "example to skip"
  shell: "cd /opt/play/apps/default-device && play deps {{ dep }}"
  register: checkdeps
  when: "dep == \"I\" or dep == \"II\""

- name: "echo ok if Done!"
  shell: "echo \"OK - {{ dep }} Dependencies {{ checkdeps.stdout }}\""

```

And it gives me error:

```auto
One or more undefined variables: 'dict' object has no attribute 'stdout'

```

I’ve modified the last line without the stdout:

```auto
shell: "echo \"OK - {{ dep }} Dependencies {{ checkdeps }}\""

```

and it gives the output:

```auto
stdout:
OK - APK_PARSER Dependencies {u'skipped': True, u'changed': False}

```

did the variable checkdeps register the “skipping: […]” ? Why it is changing it’s value if the condition is not met ?

---

<div class="post-metadata">

**Author:** ![Tomasz\_Kontusz](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@Tomasz\_Kontusz](https://forum.ansible.com/u/Tomasz_Kontusz)\
**Post date:** [March 30, 2015, 6:58am UTC](https://forum.ansible.com/t/variable-change-if-condition-is-not-met-register-skipped/17869/2 "2015-03-30T06:58:56Z")

</div>

registering a variable isn’t meant to be skipped, it works as designed. If you want to build something like this you’ll have to register different variables, and then use set\_vars to create the output one

Adrian Paraschiv [adrian.paraschiv.mobile@gmail.com](mailto:adrian.paraschiv.mobile@gmail.com) napisał:

---

<div class="post-metadata">

**Author:** ![Adrian\_Paraschiv](https://avatars.discourse-cdn.com/v4/letter/a/f14d63/32.png) [@Adrian\_Paraschiv](https://forum.ansible.com/u/Adrian_Paraschiv)\
**Post date:** [March 30, 2015, 7:10am UTC](https://forum.ansible.com/t/variable-change-if-condition-is-not-met-register-skipped/17869/3 "2015-03-30T07:10:15Z")

</div>

Thanks for the fast response but I don’t get it and google is not helping me in finding an example or even how this module: “set\_vars” works.  
So you say that if I put something like this:

- name: “play deps if ACE\_\*”  
shell: “cd /opt/play/apps/default-ace && play deps {{ dep }}”  
register: **checkdeps1**  
when: “dep == "1"”
- name: “play deps example to skip”  
shell: “cd /opt/play/apps/default-ace && play deps {{ dep }}”  
register: **checkdeps2**  
when: “dep == "2"”  
…
- name: “play deps example to skip”  
shell: “cd /opt/play/apps/default-ace && play deps {{ dep }}”  
register: **checkdeps100**  
when: “dep == "100"”

Where do I put set\_vars ???

---

<div class="post-metadata">

**Author:** ![Tomasz\_Kontusz](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@Tomasz\_Kontusz](https://forum.ansible.com/u/Tomasz_Kontusz)\
**Post date:** [March 30, 2015, 7:41am UTC](https://forum.ansible.com/t/variable-change-if-condition-is-not-met-register-skipped/17869/4 "2015-03-30T07:41:00Z")

</div>

Sorry, it’s set\_fact, not set\_vars. You’d add a task like this at the end:

- set\_fact:  
checkdeps: ‘{{ checkdeps1 if not (checkdeps1 | skipped) else checkdeps2 }}’

Or put something like this after each of the tasks registering checkdeps\*:

- set\_fact:  
checkdeps: ‘{{ checkdeps1 }}’  
when: ‘{{ not (checkdeps1 | skipped) }}’

Adrian Paraschiv [adrian.paraschiv.mobile@gmail.com](mailto:adrian.paraschiv.mobile@gmail.com) napisał:
