Interview Prep/Ansible/Fundamentals and Architecture

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:

  1. Creates a temp directory under ~/.ansible/tmp on the target.
  2. Transfers the payload (SFTP/SCP, or piped over stdin with pipelining).
  3. Runs it with the target's Python and parses the JSON it prints to stdout.
  4. 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.

All Ansible questions Roadmap: Ansible

More on Fundamentals and Architecture