access to register stdout_lines attributes

Hi,

I have a task that executes a shell command and spews out a few lines. Specifically, it probes a remote DB and and returns some information . Please see below:

`

  • name: Test role delegation to apps
    hosts: appboxes
    tasks:

  • name: get cluster status from dbboxes
    shell: mysqlsh --redirect-primary test123:test123@box1:3306 --cluster -e “cluster.status().defaultReplicaSet.primary” --interactive --json
    register: res
    delegate_to: “{{ groups.mysqldbs | first }}”
    run_once: True

  • name: check result
    debug:
    var=res.stdout_lines
    run_once: True

- name: check result

debug:

var: “{{ item.value }}”

with_items: “{{ res.stdout_lines }}”

run_one: True

`

`
root@controller:/etc/ansible/playbooks# ansible-playbook test_delegate.yml

PLAY [Test role delegation to apps] *********************************************************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************************************************************
ok: [appbox1]
ok: [appbox2]

TASK [get cluster status from dbboxes] ******************************************************************************************************************************************************************************************************
changed: [appbox1 → dbbox1]

TASK [check result] *************************************************************************************************************************************************************************************************************************
ok: [appbox1] => {
“res.stdout_lines”: [
“{”,
" "info": "Creating a session to ‘test123@box1:3306’"“,
“}”,
“{”,
" "info": "Your MySQL connection id is 246 Server version: 5.7.21-log MySQL Commercial Server (Advanced) No default schema selected; type \\use to set one."”,
“}”,
“{”,
" "info": "Reconnecting to PRIMARY instance of the InnoDB cluster (mysql://box1:3306)…"“,
“}”,
“{”,
" "info": "Creating a Classic session to ‘test123@box1:3306’"”,
“}”,
“{”,
" "info": "Closing old connection…"“,
“}”,
“{”,
" "info": "Your MySQL connection id is 239 Server version: 5.7.21-log MySQL Commercial Server (Advanced) No default schema selected; type \\use to set one."”,
“}”,
“{”,
" "value": "box1:3306"",
“}”
]
}

PLAY RECAP **********************************************************************************************************************************************************************************************************************************
appbox1 : ok=3 changed=1 unreachable=0 failed=0
appbox2 : ok=1 changed=0 unreachable=0 failed=0
`

I’ve been scratching my head trying to figure out how to return only the “value” attribute and its corresponding result.

I tried using a loop (commented out in the playbook) but it just spews out a load of errors saying the attribute doesn’t exist i.e.

`
TASK [check result] *************************************************************************************************************************************************************************************************************************
fatal: [appbox1]: FAILED! => {“msg”: “The task includes an option with an undefined variable. The error was: ‘ansible.utils.unsafe_proxy.AnsibleUnsafeText object’ has no attribute ‘value’\n\nThe error appears to have been in ‘/etc/ansible/playbooks/test_delegate.yml’: line 15, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: check result\n ^ here\n\nexception type: <class ‘ansible.errors.AnsibleUndefinedVariable’>\nexception: ‘ansible.utils.unsafe_proxy.AnsibleUnsafeText object’ has no attribute ‘value’”}
fatal: [appbox2]: FAILED! => {“msg”: “The task includes an option with an undefined variable. The error was: ‘ansible.utils.unsafe_proxy.AnsibleUnsafeText object’ has no attribute ‘value’\n\nThe error appears to have been in ‘/etc/ansible/playbooks/test_delegate.yml’: line 15, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: check result\n ^ here\n\nexception type: <class ‘ansible.errors.AnsibleUndefinedVariable’>\nexception: ‘ansible.utils.unsafe_proxy.AnsibleUnsafeText object’ has no attribute ‘value’”}
to retry, use: --limit @/etc/ansible/playbooks/test_delegate.retry

PLAY RECAP **********************************************************************************************************************************************************************************************************************************
appbox1 : ok=3 changed=1 unreachable=0 failed=1
appbox2 : ok=1 changed=0 unreachable=0 failed=1
`

Any ideas will be appreciated
Dayo

Got to the bottom of this eventually…

-debug: var= “{{ res.stdout_lines | last }}”

It’s the last item in the list