Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing Python via Ansible when no Python version exists on target machine

Tags:

ansible

I am attempting to install Python onto a virtual machine (let refer to this as the 'target machine') with ansible-playbook. The target machine has no version of Python installed at all (lightweight Unix version)

From my understanding, most ansible modules will require the target machine to have Python installed on it. However, the raw module does not.

I can't seem to even get the most basic command to work with the raw module, it seems that ansirble is still looking for Python on the target machine. If I manually ssh into the target machine and install Python, then the ansible-playbook begins to work.

Error message:

fatal: [dev]: FAILED! => 
{"changed": false, "failed": true,
 "module_stderr": "Shared connection to 192.168.99.100 closed.\r\n",  
 "module_stdout": "/bin/sh: /usr/bin/python: not found\r\n",
 "msg": "MODULE FAILURE", "rc": 0}

file /host_vars/dev.yml:

#NOTE: I can manually ssh in with the details without a problem
ansible_ssh_port: 22
ansible_user: docker
ansible_ssh_host: 192.168.99.100
ansible_ssh_private_key_file: ~/.docker/machine/machines/default/id_rsa

file playbook.yml:

- hosts: all
  tasks:
  - name: test the raw module
    raw: echo "Hello World"

file hosts:

dev

Command I ran:

ansible-playbook -i ./hosts ./playbook.yml

Why is the raw command looking for Python?

How can I run command with Ansible without the target machine having Python?

like image 251
Sam Anthony Avatar asked Mar 29 '17 23:03

Sam Anthony


People also ask

Does Ansible require Python on target?

By default Ansible modules require python to be present in the target machines, since they are all written in python.

Which Python version is required for Ansible?

Currently Ansible can be run from any machine with Python 2 (version 2.7) or Python 3 (versions 3.5 and higher) installed. Windows isn't supported for the control machine. This includes Red Hat, Debian, CentOS, macOS, any of the BSDs, and so on.

How do I fix usr bin Python not found in Ansible?

There are 3 ways to solve this problem if you encounter it on your remote host: Set ansible_python_interpreter: /usr/bin/python3 variable for all hosts that have python3 installed by default. Install Python 2 using Ansible's raw module. Symlink /usr/bin/python3 to /usr/bin/python using Ansible's raw module.

Can Ansible work without Python?

While you can write Ansible modules in any language, most Ansible modules are written in Python, including the ones central to letting Ansible work. By default, Ansible assumes it can find a /usr/bin/python on your remote system that is either Python2, version 2.6 or higher or Python3, 3.5 or higher.


1 Answers

It's not the raw module, but fact-gathering that tries to run Python.

Add:

gather_facts: no
like image 190
techraf Avatar answered Oct 09 '22 01:10

techraf