Score:1

How can I see which commands ansible runs and their output?

us flag

I'm new to Ansible, and yes I know this has already been asked many times, but I already tried to apply advice I saw elsewhere.

I did export ANSIBLE_STDOUT_CALLBACK=debug and then ansible-playbook -vvvvvv arch-upgrade.yaml -l my-host with arch-upgrade.yaml below:

- name: ArchLinux up-to-date
  hosts: all
  tasks:
    - name: full system upgrade
      pacman:
        update_cache: yes
        upgrade: yes
      register: out
    - debug: msg="{{ out }}"

I get a lot of details about how ansible opens it's ssh connections, transfers its python file, runs it remotely, etc. but as far as I can tell, not a single thing about what command the python script actually ran and what it returned (stdout, stderr, return code). That's why I'm not including this very long log here, but I can upon request.

Is someone aware of how I can ask ansible to be more verbose about what it does (and not how it does it) ?

br flag
Ansible can provide you with the output of a module. See [Debugging modules](https://docs.ansible.com/ansible/latest/dev_guide/debugging.html#debugging-modules) if you want to learn more. It's pretty straightforward. You ask Ansible to leave the code at the remote node. See ANSIBLE_KEEP_REMOTE_FILES. Then, at the remote node, you unpack the code and run *pdb*.
us flag
Ok thanks, I guess this is a way to do it. Seems a bit convoluted though. Is there no "native" way to see what's happening from the ansible command line ? I mean things like `run_command` do not interact with some kind of native logging mechanism within ansible ?
br flag
No. It is not. Imagine how Ansible works. First, at the controller, all data and code are compressed into a packet ``AnsiballZ``. Then, this packet is sent to a remote node. At the remote node, the data and code are extracted and executed. When a task completes the output is sent back from the remote node to the controller. Read the link above.
us flag
Yes what you propose is simple from a systems design point of view. It's not so simple from a user's point of view. I'm a bit surprised there is no generic framework within ansible to log the side effects a what modules does (shell commands, system calls, API calls, etc.) without having to run it by hand. Nevertheless thanks for the insights into the internals of ansible !
br flag
You're welcome! It's necessary to understand that the success of Ansible is in providing a comprehensive framework to write custom modules. There is [unified structure of the output](https://docs.ansible.com/ansible/latest/dev_guide/developing_modules_general.html#creating-an-info-or-a-facts-module) but, because of the variety of the modules, you get only such output the author of the module provides. There are about 10k modules at the moment, I assume. See [Ansible collections](https://github.com/orgs/ansible-collections/repositories).
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.