What does Ansible push to the remote host

ansible

Wondering how Ansible works at a brick level. Most sites say a module is pushed and Ansible does not need an agent on the remote host – just SSH and Python.

It seems like Ansible would need to create a python script locally and copy it to the remote host. What is sent? Is it literally a .py file or a .pyc file – or other?

How is it possible the remote host will not need any additional Python packages?

Best Answer

Most sites say a module is pushed and Ansible does not need an agent on the remote host - just SSH and Python.

That's correct.

scp or WinRM might also be used, as well a handful of other connection types.


It seems like Ansible would need to create a python script locally and copy it to the remote host. What is sent? Is it literally a .py file or a .pyc file - or other?

It does create a script locally and copy it to the remote host. .py or a packed set of those.

You can see for yourself -- execute Ansible with ANSIBLE_KEEP_REMOTE_FILES set to 1:

ANSIBLE_KEEP_REMOTE_FILES=1 ansible-playbook playbook.yml

and check the temporary directory on the target machine (by default under the $HOME/.ansible/tmp/ for the connecting user).

If the files were packed, there are instructions in the comments inside the file on how to expand the set.


How is it possible the remote host will not need any additional Python packages?

This claim is incorrect.

There are many modules requiring additional Python packages, for example expect module:

The below requirements are needed on the host that executes this module.

  • python >= 2.6
  • pexpect >= 3.3

or even executables, for example unarchive module:

Requires gtar/unzip command on target host.