# help with variables

**URL:** <https://forum.ansible.com/t/help-with-variables/25619>\
**Category:** Ansible Project\
**Created:** [September 28, 2017, 2:36am UTC](https://forum.ansible.com/t/help-with-variables/25619 "2017-09-28T02:36:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frank\_Dias](https://avatars.discourse-cdn.com/v4/letter/f/eada6e/32.png) [@Frank\_Dias](https://forum.ansible.com/u/Frank_Dias)\
**Post date:** [September 28, 2017, 2:36am UTC](https://forum.ansible.com/t/help-with-variables/25619/1 "2017-09-28T02:36:42Z")

</div>

Can I get your help in diagnosing why this is not working, I am getting the error on task #3 Here are the three tasks; I am wantng to key off of “stdout”: “0”,

- name: Check if Redis Resources already exists

shell: “pcs resource | grep ‘{{ item.key }}’ | grep Master | wc -l”

register: resource\_exist

with\_dict: “{{redis}}”

tags: [config\_cluster, redis]

- name: Print results

debug: msg=“{{ resource\_exist.results }}”

tags: [config\_cluster, redis]

- name: Set facts about if resources already exists

set\_fact: resource\_{{ item.item.key }}={{item.stdout}}

with\_items: resource\_exist.results

tags: [config\_cluster, redis]

here is the output;

TASK [postgres-ha : Check if Redis Resources already exists] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

skipping: [[sds02.prodea-int.net](http://sds02.prodea-int.net)] =\> (item={‘key’: u’redis\_array\_1’, ‘value’: {u’bin’: u’/opt/redis/bin/redis-server’, u’clone\_max’: 3, u’master\_max’: 1, u’wait\_last\_known\_master’: 0, u’loglevel’: u’notice’, u’client\_bin’: u’/opt/redis/bin/redis-cli’, u’vip\_cidr\_netmask’: 24, u’master\_node\_max’: 1, u’save’: [u’900 1’, u’300 10’, u’60 10000’], u’vip\_nic’: u’eth0’, u’daemonize’: u’yes’, u’notify’: True, u’user’: u’root’, u’vip\_ip’: u’172.24.2.242’, u’rundir’: u’/var/run/redis’, u’logfile’: None, u’port’: 6379, u’clone\_node\_max’: 1}})

changed: [[sds01.prodea-int.net](http://sds01.prodea-int.net)] =\> (item={‘key’: u’redis\_array\_1’, ‘value’: {u’bin’: u’/opt/redis/bin/redis-server’, u’clone\_max’: 3, u’master\_max’: 1, u’wait\_last\_known\_master’: 0, u’loglevel’: u’notice’, u’client\_bin’: u’/opt/redis/bin/redis-cli’, u’vip\_cidr\_netmask’: 24, u’master\_node\_max’: 1, u’save’: [u’900 1’, u’300 10’, u’60 10000’], u’vip\_nic’: u’eth0’, u’daemonize’: u’yes’, u’notify’: True, u’user’: u’root’, u’vip\_ip’: u’172.24.2.242’, u’rundir’: u’/var/run/redis’, u’logfile’: None, u’port’: 6379, u’clone\_node\_max’: 1}})

TASK [postgres-ha : Print results] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

ok: [[sds01.prodea-int.net](http://sds01.prodea-int.net)] =\> {

“msg”: [

{

“\_ansible\_item\_result”: true,

“\_ansible\_no\_log”: false,

“\_ansible\_parsed”: true,

“changed”: true,

“cmd”: “pcs resource | grep ‘redis\_array\_1’ | grep Master | wc -l”,

“delta”: “0:00:00.328159”,

“end”: “2017-09-26 17:25:25.591212”,

“invocation”: {

“module\_args”: {

“\_raw\_params”: “pcs resource | grep ‘redis\_array\_1’ | grep Master | wc -l”,

“\_uses\_shell”: true,

“chdir”: null,

“creates”: null,

“executable”: null,

“removes”: null,

“warn”: true

}

},

“item”: {

“key”: “redis\_array\_1”,

“value”: {

“bin”: “/opt/redis/bin/redis-server”,

“client\_bin”: “/opt/redis/bin/redis-cli”,

“clone\_max”: 3,

“clone\_node\_max”: 1,

“daemonize”: “yes”,

“logfile”: null,

“loglevel”: “notice”,

“master\_max”: 1,

“master\_node\_max”: 1,

“notify”: true,

“port”: 6379,

“rundir”: “/var/run/redis”,

“save”: [

“900 1”,

“300 10”,

“60 10000”

],

“user”: “root”,

“vip\_cidr\_netmask”: 24,

“vip\_ip”: “172.24.2.242”,

“vip\_nic”: “eth0”,

“wait\_last\_known\_master”: 0

}

},

“rc”: 0,

“start”: “2017-09-26 17:25:25.263053”,

“stderr”: “”,

“stderr\_lines”: ,

“stdout”: “0”,

“stdout\_lines”: [

“0”

]

}

]

}

skipping: [[sds02.prodea-int.net](http://sds02.prodea-int.net)]

TASK [postgres-ha : Set facts about if resources already exists] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

fatal: [[sds01.prodea-int.net](http://sds01.prodea-int.net)]: FAILED! =\> {“failed”: true, “msg”: “the field ‘args’ has an invalid value, which appears to include a variable that is undefined. The error was: ‘ansible.vars.unsafe\_proxy.AnsibleUnsafeText object’ has no attribute ‘stdout’\n\nThe error appears to have been in ‘/etc/ansible/roles/postgres-ha/tasks/redis\_resources.yml’: line 18, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Set fatcs about if resources already exists\n ^ here\n”}

fatal: [[sds02.prodea-int.net](http://sds02.prodea-int.net)]: FAILED! =\> {“failed”: true, “msg”: “the field ‘args’ has an invalid value, which appears to include a variable that is undefined. The error was: ‘ansible.vars.unsafe\_proxy.AnsibleUnsafeText object’ has no attribute ‘stdout’\n\nThe error appears to have been in ‘/etc/ansible/roles/postgres-ha/tasks/redis\_resources.yml’: line 18, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Set fatcs about if resources already exists\n ^ here\n”}

NO MORE HOSTS LEFT \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

to retry, use: --limit @/root/sds-postgres-ha.retry

---

<div class="post-metadata">

**Author:** ![Frank\_Dias](https://avatars.discourse-cdn.com/v4/letter/f/eada6e/32.png) [@Frank\_Dias](https://forum.ansible.com/u/Frank_Dias)\
**Post date:** [September 28, 2017, 2:40am UTC](https://forum.ansible.com/t/help-with-variables/25619/2 "2017-09-28T02:40:57Z")

</div>

I an trying to get set\_fact: resource\_{{ item.item.key }}={{item.stdout}} to be the output of “stdout”: “0” meaning resource\_{{ item.item.key }}= 0, later in other task I am checking if value is 0 or 1

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [September 28, 2017, 2:39pm UTC](https://forum.ansible.com/t/help-with-variables/25619/3 "2017-09-28T14:39:10Z")

</div>

The error message is not really helpful, but the problem is that your with\_items: is missing jinja templating. As it stands now item is literally the text "resource\_exist.results"

So you need this:

&nbsp;&nbsp;&nbsp;with\_items: '{{ resource\_exist.results }}'
