- 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=0TASK [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