5

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?

0
8

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.

3
  • One note to further this: docs.ansible.com/ansible/2.5/dev_guide/…. You can use the explode command to 'turn the string into some python files that you can work with': ~/.ansible/tmp$ ansible-tmp-1536719125.6725047-209276989541110/setup.py explode
    – jouell
    Sep 15 '18 at 19:42
  • 1
    Isn't this what I wrote above? "If the files were packed, there are instructions in comments how to expand the set."
    – techraf
    Sep 15 '18 at 19:43
  • Ansible needs python 2.6 on the remote end unless you use raw mode AFAIR Sep 16 '18 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.