ansible.cfg: Enable the Ansible debugger when a task fails
RFC PATCH 1/2 ansible.cfg: Enable the Ansible debugger when a task fails
From: Chuck Lever <[email protected]>
This is useful to avoid generating a whole bunch of unwanted output that can change thread timing.
--- kconfigs/Kconfig.ansible_cfg | 13 +++++++++++++ .../roles/ansible_cfg/templates/ansible.cfg.j2 | 1 + 2 files changed, 14 insertions(+)
kconfigs/Kconfig.ansible_cfg +13 -0
@@ -10,6 +10,10 @@ config ANSIBLE_CFG_FORKS_SET_BY_CLI bool default $(shell, scripts/check-cli-set-var.sh ANSIBLE_CFG_FORKS) +config ANSIBLE_CFG_TASK_DEBUGGER_SET_BY_CLI + bool + default $(shell, scripts/check-cli-set-var.sh ANSIBLE_CFG_TASK_DEBUGGER) + menu "Ansible Callback Plugin Configuration" choice prompt "Ansible Callback Plugin"
@@ -207,6 +211,15 @@ config ANSIBLE_CFG_FORKS endif # !ANSIBLE_CFG_FORKS_CUSTOM +config ANSIBLE_CFG_TASK_DEBUGGER + bool "Enable the Ansible task debugger on failed tasks" + output yaml + default n + help + When this setting is enabled, a task failure invokes the + Ansible debugger. Generally this is useful only when + running kdevops from the command line. + if DISTRO_OPENSUSE config ANSIBLE_CFG_RECONNECTION_RETRIES
playbooks/roles/ansible_cfg/templates/ansible.cfg.j2 +1 -0
@@ -10,6 +10,7 @@ show_per_host_start = {{ ansible_cfg_callback_plugin_show_per_host_start }} show_task_path_on_failure = {{ ansible_cfg_callback_plugin_show_task_path_on_failure }} interpreter_python = {{ ansible_cfg_interpreter_python_string }} forks = {{ ansible_cfg_forks }} +enable_task_debugger = {{ ansible_cfg_task_debugger }} {% if ansible_facts['distribution'] == 'openSUSE' %} [connection] retries = {{ ansible_cfg_reconnection_retries }}
Signature · 1 line
2.50.0
RFC PATCH 2/2 ansible.cfg: Explicitly set the ssh user
From: Chuck Lever <[email protected]>
I've been seeing tasks that are marked "become: true" fail with this message:
Timeout (12s): waiting for privilege escalation promt:
This appears to be a common failure mode, but it is due to a broad variety of causes. I think I've nailed this one with this addition to ansible.cfg. It changes "ESTABLISHING SSH SESSION FOR: NONE" to "... FOR: <user>" where <user> is always a user that is allowed to use sudo.
The current Terraform Kconfig menu sets this user, but guestfs does not -- the Ansible ssh user for guestfs is always "kdevops". The ansible.cfg.j2 file reflects this.
--- playbooks/roles/ansible_cfg/templates/ansible.cfg.j2 | 5 +++++ 1 file changed, 5 insertions(+)
playbooks/roles/ansible_cfg/templates/ansible.cfg.j2 +5 -0
@@ -11,6 +11,11 @@ show_task_path_on_failure = {{ ansible_cfg_callback_plugin_show_task_path_on_fai interpreter_python = {{ ansible_cfg_interpreter_python_string }} forks = {{ ansible_cfg_forks }} enable_task_debugger = {{ ansible_cfg_task_debugger }} +{% if ssh_config_user is defined %} +remote_user = {{ ssh_config_user }} +{% else %} +remote_user = kdevops +{% endif %} {% if ansible_facts['distribution'] == 'openSUSE' %} [connection] retries = {{ ansible_cfg_reconnection_retries }}
Signature · 1 line
2.50.0
Quoted 4 lines · Chuck Lever
From: Chuck Lever <[email protected]>
This is useful to avoid generating a whole bunch of unwanted output that can change thread timing.
What do you mean? Debugging tasks (with debug module) may add delays that can affect the playbook time execution?
Quoted 2 lines
Signed-off-by Chuck Lever <[email protected]>
Looks useful. From the docs example looks like import pdb; pdb.set_trace().
https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_debugger.html#resolving-errors-in-the-debugger
Can you add the Ansible debugger docs link to the Kconfig?
Re: [RFC PATCH 2/2] ansible.cfg: Explicitly set the ssh user
In reply to Chuck LeverQuoted 5 lines · Chuck Lever
From: Chuck Lever <[email protected]>
I've been seeing tasks that are marked "become: true" fail with this message:
Quoted 7 lines
Timeout (12s): waiting for privilege escalation promt:
This appears to be a common failure mode, but it is due to a broad variety of causes. I think I've nailed this one with this addition to ansible.cfg. It changes "ESTABLISHING SSH SESSION FOR: NONE" to "... FOR: <user>" where <user> is always a user that is allowed to use sudo.
In which cases do we get NONE instead of the user? Looks like we may be missing something... Perhaps tasks that are marked as become: true but not withbecome_method: ansible.builtin.sudo?
Quoted 4 lines
The current Terraform
Kconfigmenu sets this user, but guestfs does not -- the Ansible ssh user for guestfs is always "kdevops". The ansible.cfg.j2 file reflects this.
Does this also affect the controller host user?
Quoted 10 lines
Signed-off-by Chuck Lever <[email protected]>--- playbooks/roles/ansible_cfg/templates/ansible.cfg.j2 | 5 +++++ 1 file changed, 5 insertions(+)playbooks/roles/ansible_cfg/templates/ansible.cfg.j2 +0
-0
playbooks/roles/ansible_cfg/templates/ansible.cfg.j2 show_task_path_on_failure = {{ ansible_cfg_callback_plugin_show_task_path_on_fai · line 18
Quoted 8 lines
playbooks/roles/ansible_cfg/templates/ansible.cfg.j2 +5
-0@@ -11,6 +11,11 @@ show_task_path_on_failure = {{ ansible_cfg_callback_plugin_show_task_path_on_fai interpreter_python = {{ ansible_cfg_interpreter_python_string }} forks = {{ ansible_cfg_forks }} enable_task_debugger = {{ ansible_cfg_task_debugger }} +{% if ssh_config_user is defined %} +remote_user = {{ ssh_config_user }} +{% else %} +remote_user = kdevops +{% endif %}
I think it makes sense. But I wonder if we want this to be set in the inventory file instead of globally here? I'm looking at these 2 links:
https://docs.ansible.com/ansible/latest/inventory_guide/connection_details.html#setting-a-remote-user
https://docs.ansible.com/ansible/2.9/plugins/connection/ssh.html#ssh-connection
Quoted 3 lines
playbooks/roles/ansible_cfg/templates/ansible.cfg.j2 +0
-0{% if ansible_facts['distribution'] == 'openSUSE' %} [connection] retries = {{ ansible_cfg_reconnection_retries }}
Quoted 8 lines · Daniel Gomez
Quoted 4 lines · Chuck Lever
From: Chuck Lever <[email protected]>
This is useful to avoid generating a whole bunch of unwanted output that can change thread timing.
What do you mean? Debugging tasks (with debug module) may add delays that can affect the playbook time execution?
Yes, or that using "make AV=3" can generate thousands of lines of output versus just a hundred.
Quoted 6 lines
Quoted 1 line
Signed-off-by Chuck Lever <[email protected]>Looks useful. From the docs example looks like import pdb;
pdb.set_trace().
https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_debugger.html#resolving-errors-in-the-debuggerCan you add the Ansible debugger docs link to the
Kconfig?
Yes.
Quoted 1 line
Reviewed-by Daniel Gomez <[email protected]>
Signature · 1 line
Chuck Lever
Re: [RFC PATCH 2/2] ansible.cfg: Explicitly set the ssh user
In reply to Daniel GomezQuoted 8 lines · Daniel Gomez
Quoted 7 lines · Chuck Lever
From: Chuck Lever <[email protected]>
I've been seeing tasks that are marked "become: true" fail with this message:
Timeout (12s): waiting for privilege escalation promt:
Quoted 7 lines
Quoted 5 lines
This appears to be a common failure mode, but it is due to a broad variety of causes. I think I've nailed this one with this addition to ansible.cfg. It changes "ESTABLISHING SSH SESSION FOR: NONE" to "... FOR: <user>" where <user> is always a user that is allowed to use sudo.
In which cases do we get NONE instead of the user?
I see that for all connections to remote (non-controller) hosts.
Now, I've also followed a recent recommendation to supercede paramiko with python3-ansible-pylibssh. Could that be the problem?
Quoted 3 lines
Looks like we may be
missing something... Perhaps tasks that are marked as become: true but not withbecome_method: ansible.builtin.sudo?
I saw the privilege escalation failure with tasks that had abecome_method: attribute.
Quoted 5 lines
Quoted 3 lines
The current Terraform
Kconfigmenu sets this user, but guestfs does not -- the Ansible ssh user for guestfs is always "kdevops". The ansible.cfg.j2 file reflects this.Does this also affect the controller host user?
It does not appear to. Local connections continue to utilize my user (cel).
Quoted 22 lines
Quoted 10 lines
Signed-off-by Chuck Lever <[email protected]>--- playbooks/roles/ansible_cfg/templates/ansible.cfg.j2 | 5 +++++ 1 file changed, 5 insertions(+)playbooks/roles/ansible_cfg/templates/ansible.cfg.j2 +0
-0playbooks/roles/ansible_cfg/templates/ansible.cfg.j2 show_task_path_on_failure = {{ ansible_cfg_callback_plugin_show_task_path_on_fai · line 18
Quoted 8 lines
playbooks/roles/ansible_cfg/templates/ansible.cfg.j2 +5
-0@@ -11,6 +11,11 @@ show_task_path_on_failure = {{ ansible_cfg_callback_plugin_show_task_path_on_fai interpreter_python = {{ ansible_cfg_interpreter_python_string }} forks = {{ ansible_cfg_forks }} enable_task_debugger = {{ ansible_cfg_task_debugger }} +{% if ssh_config_user is defined %} +remote_user = {{ ssh_config_user }} +{% else %} +remote_user = kdevops +{% endif %}I think it makes sense. But I wonder if we want this to be set in the inventory file instead of globally here? I'm looking at these 2 links:
Quoted 2 lines
https://docs.ansible.com/ansible/latest/inventory_guide/connection_details.html#setting-a-remote-user
https://docs.ansible.com/ansible/2.9/plugins/connection/ssh.html#ssh-connection
I didn't see anything there that suggested setting these in the inventory was any better. I don't have much of a preference, though.
Quoted 3 lines
Quoted 3 lines
playbooks/roles/ansible_cfg/templates/ansible.cfg.j2 +0
-0{% if ansible_facts['distribution'] == 'openSUSE' %} [connection] retries = {{ ansible_cfg_reconnection_retries }}
Signature · 1 line
Chuck Lever