How does Ansible actually execute a module on a remote host (AnsiballZ)?
AdvancedConceptFundamentals and Architecture
Answer
For a normal task, Ansible builds a self-contained zip payload (AnsiballZ) that bundles the module code, its module_utils dependencies and the task arguments. It then:
- Creates a temp directory under
~/.ansible/tmpon the target. - Transfers the payload (SFTP/SCP, or piped over stdin with pipelining).
- Runs it with the target's Python and parses the JSON it prints to stdout.
- Deletes the temp dir.
Setting ANSIBLE_KEEP_REMOTE_FILES=1 keeps the payload so you can python AnsiballZ_xxx.py explode it and debug a module locally. This is also why modules must print valid JSON and why stray output from shell profiles can break tasks.
More on Fundamentals and Architecture
What is Ansible and what problem does it solve?BeginnerWhat does "agentless" mean in Ansible?BeginnerWhat are the requirements for the control node?BeginnerWhat does a managed node need?BeginnerIs Ansible push-based or pull-based?BeginnerWalk through what happens when you run `ansible-playbook site.yml`.Intermediate