Sentinel - Redis : fatal: [pyxrrsap02.pyx.erp]: FAILED! => {"failed": true, "msg": "ERROR! 'list object' has no attribute 'cmd'"}

Hi,
I try to connect to a list of Sentinel host to get the master redis host and port.

  • name: “CONNECT SENTINEL” command: “redis-cli -h {{ item.allowed_host }} -p {{ item.port }} SENTINEL get-master-addr-by-name redis-pex-01” with_items: “{{ production.redis_params.sentinels }}” register: status_sentinel ignore_errors: yes

TASK [CONNECT SENTINEL] ********************************************************
changed: [pyxrrsap02.pyx.erp] => (item={u’allowed_host’: u’pyxrrsap01’, u’port’: 17700}) => {“changed”: true, “cmd”: [“redis-cli”, “-h”, “pyxrrsap01”, “-p”, “17700”, “SENTINEL”, “get-master-addr-by-name”, “redis-pex-01”], “delta”: “0:00:00.016587”, “end”: “2015-11-11 00:49:19.387801”, “item”: {“allowed_host”: “pyxrrsap01”, “port”: 17700}, “rc”: 0, “start”: “2015-11-11 00:49:19.371214”, “stderr”: “”, “stdout”: “10.50.133.20\n6379”, “stdout_lines”: [“10.50.133.20”, “6379”], “warnings”: }
changed: [pyxrrsap02.pyx.erp] => (item={u’allowed_host’: u’pyxrrsap01’, u’port’: 27700}) => {“changed”: true, “cmd”: [“redis-cli”, “-h”, “pyxrrsap01”, “-p”, “27700”, “SENTINEL”, “get-master-addr-by-name”, “redis-pex-01”], “delta”: “0:00:00.017153”, “end”: “2015-11-11 00:49:19.998121”, “item”: {“allowed_host”: “pyxrrsap01”, “port”: 27700}, “rc”: 0, “start”: “2015-11-11 00:49:19.980968”, “stderr”: “”, “stdout”: “10.50.133.20\n6379”, “stdout_lines”: [“10.50.133.20”, “6379”], “warnings”: }

I try to display result f register value:

  • name: “DISPLAY SENTINEL VAR 1”
    debug: msg={{ status_sentinel }}
    ignore_errors: yes

TASK [DISPLAY SENTINEL VAR 1] **************************************************
ok: [pyxrrsap02.pyx.erp] => {
“changed”: false,
“msg”: {
“changed”: true,
“msg”: “All items completed”,
“results”: [
{
“_ansible_no_log”: false,
“changed”: true,
“cmd”: [
“redis-cli”,
“-h”,
“pyxrrsap01”,
“-p”,
“17700”,
“SENTINEL”,
“get-master-addr-by-name”,
“redis-pex-01”
],
“delta”: “0:00:00.016587”,
“end”: “2015-11-11 00:49:19.387801”,
“invocation”: {
“module_args”: {
“_raw_params”: “redis-cli -h pyxrrsap01 -p 17700 SENTINEL get-master-addr-by-name redis-pex-01”
},
“module_name”: “command”
},
“item”: {
“allowed_host”: “pyxrrsap01”,
“port”: 17700
},
“rc”: 0,
“start”: “2015-11-11 00:49:19.371214”,
“stderr”: “”,
“stdout”: “10.50.133.20\n6379”,
“stdout_lines”: [
“10.50.133.20”,
“6379”
],
“warnings”:
},
{
“_ansible_no_log”: false,
“changed”: true,
“cmd”: [
“redis-cli”,
“-h”,
“pyxrrsap01”,
“-p”,
“27700”,
“SENTINEL”,
“get-master-addr-by-name”,
“redis-pex-01”
],
“delta”: “0:00:00.017153”,
“end”: “2015-11-11 00:49:19.998121”,
“invocation”: {
“module_args”: {
“_raw_params”: “redis-cli -h pyxrrsap01 -p 27700 SENTINEL get-master-addr-by-name redis-pex-01”
},
“module_name”: “command”
},
“item”: {
“allowed_host”: “pyxrrsap01”,
“port”: 27700
},
“rc”: 0,
“start”: “2015-11-11 00:49:19.980968”,
“stderr”: “”,
“stdout”: “10.50.133.20\n6379”,
“stdout_lines”: [
“10.50.133.20”,
“6379”
],
“warnings”:
}
]
}
}

But when it tries to parse to have detail it doesn’t work:

  • name: “DISPLAY SENTINEL VAR 1 1”
    debug: msg={{ status_sentinel.results.cmd }}
    ignore_errors: yes
- name: "DISPLAY SENTINEL VAR 1 2"
  debug: msg={{ item.cmd }}
  with_items: ${status_sentinel.results}
  ignore_errors: yes

TASK [DISPLAY SENTINEL VAR 1 1] ************************************************
fatal: [pyxrrsap02.pyx.erp]: FAILED! => {“failed”: true, “msg”: “ERROR! ‘list object’ has no attribute ‘cmd’”}
…ignoring

TASK [DISPLAY SENTINEL VAR 1 2] ************************************************
fatal: [pyxrrsap02.pyx.erp]: FAILED! => {“failed”: true, “msg”: “ERROR! ‘unicode object’ has no attribute ‘cmd’”}
…ignoring

or like this :

  • name: “DISPLAY SENTINEL VAR 2 1”
    debug: var={{ item }}
    with_items: ${status_sentinel.results}
    ignore_errors: yes

doesn’t work:
TASK [DISPLAY SENTINEL VAR 2 1] ************************************************
ok: [pyxrrsap02.pyx.erp] => (item=${status_sentinel.results}) => {
“${status_sentinel.results}”: “VARIABLE IS NOT DEFINED!”,
“item”: “${status_sentinel.results}”

Any idea ?

Regards,

SOLVED:

Simple by using : [0][0] and [0][1] to get the correct value/parameters.