Got to the bottom of this eventually...
-debug: var= "{{ res.stdout_lines | last }}"
It's the last item in the list
On Tuesday, May 15, 2018 at 2:15:57 PM UTC+1, deewon wrote:
>
> 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 <schema> 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 <schema> 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
>
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/fb9a48c6-d247-4fd2-ab5f-a104b4e0c377%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.