help with variables

32 views
Skip to first unread message

Frank Dias

unread,
Sep 27, 2017, 10:36:42 PM9/27/17
to Ansible Project

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] => (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] => (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] => {

    "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]

 

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

fatal: [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]: 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

Frank Dias

unread,
Sep 27, 2017, 10:40:57 PM9/27/17
to Ansible Project
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

Kai Stian Olstad

unread,
Sep 28, 2017, 10:39:38 AM9/28/17
to ansible...@googlegroups.com
On 28. sep. 2017 04:36, Frank Dias wrote:
> - name: Set facts about if resources already exists
> set_fact: resource_{{ item.item.key }}={{item.stdout}}
> with_items: resource_exist.results

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:

with_items: '{{ resource_exist.results }}'


--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages