Error in executing ansible playbook on target server without python - python

I have installed ansible on my windows machine using Cygwin. Executing the playbook for various target servers of Linux, AIX, Oracle is working completely fine.But when I am executing the playbook for VIOS server, it is giving below error. The problem is only with the execution for VIOS server because python is not present there and it is not possible for me to make any change on the target VIOS server.
Tried passing in vars ansible_python_interpreter: /usr/bin/python or ansible_python_interpreter: /usr/bin/python3, but still error persists.
Please can anybody help me with the solution.
PLAY [playbook for vios servers] ************************************************************************************************************
TASK [Gathering Facts] ***************************************************************************************************************************
fatal: [vios01_cont]: FAILED! => {"ansible_facts": {}, "changed": false, "failed_modules": {"setup": {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "failed": true, "module_stderr": "Connection to 10.10.64.25 closed.\r\n", "module_stdout": "/bin/sh: /usr/bin/python: not found.\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 127, "warnings": ["No python interpreters found for host vios01_cont (tried ['/usr/bin/python', 'python3.7', 'python3.6', 'python3.5', 'python2.7', 'python2.6', '/usr/libexec/platform-python', '/usr/bin/python3', 'python'])"]}}, "msg": "The following modules failed to execute: setup\n"}
PLAY RECAP ***************************************************************************************************************************************
vios01_cont : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

As already mentioned in the comments, the only module you can use in your case is raw. Furthermore you will not be able to gather facts.
- hosts: "{{ target_hosts }}"
gather_facts: no
tasks:
- name: "Do something"
raw: 'echo "test"'
register: result
failed_when: result.rc != 0
Additionally you will need to address the error handling by yourself, as well if something has changed via changed_when.
Source
Whats the difference between ansible 'raw', 'shell' and 'command'?

Related

The following modules failed to execute: ansible.legacy.setup?

I am trying to use the Dell OpenManage Ansible Modules to communicate with a PowerEdge's iDRAC. I cannot find a solution to my problem online, hopefully someone here will be able to assist. The only real answer I have found is that the host machine might not be using Python but as you can see from the error below, the host is in fact using a python interpreter. It is not the exact same interpreter as what is in the virtual environment I am running the playbook out of, I am not sure if that makes a difference or not.
Device:
PowerEdge R620 and iDRAC7
Playbook:
---
- hosts: PowerEdge
connection: local
gather_facts: False
tasks:
- name: Get hardware inventory
dellemc_get_system_inventory:
idrac_ip: "IP"
idrac_user: "USER"
idrac_password: "PASSWORD"
validate_certs: false
become: yes
Command:
ansible-playbook playbook.yml -i iDRAC_IP, -u USER --ask-pass -vvv -K
Error:
fatal: [iDRAC_IP]: FAILED! => {
"ansible_facts": {},
"changed": false,
"failed_modules": {
"ansible.legacy.setup": {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"failed": true,
"module_stderr": "Shared connection to iDRAC_IP closed.\r\n",
"module_stdout": "\rcmdstat\r\n\r\tstatus : 2\r\n\r\tstatus_tag : COMMAND PROCESSING FAILED\r\n\r\terror : 252\r\n\r\terror_tag : COMMAND SYNTAX ERROR\r\n",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 0,
"warnings": [
"Platform unknown on host iDRAC_IP is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change the meaning of that path. See https://docs.ansible.com/ansible-core/2.13/reference_appendices/interpreter_discovery.html for more information."
]
}
},
"msg": "The following modules failed to execute: ansible.legacy.setup\n"
}
the host machine might not be using Python but as you can see from the error below
This module uses a REST API which uses port 443.
Ansible doesn't like to use passwords, it is highly reccomended to use SSH Keys. Here is a tutorial to make the keys and place them on ESXI (stop at the ESXI part).
Create SSH Keys
To place the SSH key on an iDRAC (I used this method on a Dell PowerEdge FC430), follow the directions on Page 77 of this reference guide.
Placing SSH Keys on iDRAC
The playbook that worked for me
---
- hosts: host_file
gather_facts: False
collections: dellemc.openmanage
tasks:
- name: Get System Inventory
dellemc.openmanage.idrac_system_info:
idrac_ip: ip
idrac_password: pass
idrac_user: user
validate_certs: False
delegate_to: localhost
Host file contains:
host IP address
ansible_connection=ssh
remote username
Calling ansible playbook
ansible-playbook -vvvv <your_file>.yml
If that doesn't work, you should verify that python is upgraded to 3.8.6, and check if the iDRAC firmware upgraded to 2.82.82.82.

Ansible Tower - aws_s3 module - set python interpreter and install dependencies

I am trying to deploy the below task via Ansible AWX (Tower) and having some issues with the aws_s3 module.
---
- hosts: all
become: yes
tasks:
- name: Setting host facts for Python interpreter
set_fact:
ansible_python_interpreter: "/usr/bin/python3"
- name: 01 - Download file locally
aws_s3:
bucket: temp-buck-0001
object: /test/quiz.sh
dest: /tmp/quiz.sh
mode: get
- name: 02 - Change the file permissions of the shell scrip to allow for execute
file:
path: /tmp/quiz.sh
mode: "u=x"
- name: 03 - Change the working directory to tmp before executing the command.
shell: quiz.sh >> quizlog.txt
args:
chdir: /tmp
I'm getting the below error when trying to deploy the above ansible play. It seems to have a problem with Python dependencies in particular boto3 and botocore so I attempted to install these manually for testing purposes.
However, I'm receiving the below errors. It concerns dependencies for the aws_s3 module. I'm not sure if I have set up my Python interpreter correctly. Any help would be much appreciated.
Also, if anybody could suggest how to write a task to install Python3x and dependencies which is required for the aws_s3 module that would also be much appreciated.
TASK [01 - Download Metricbeats file locally]
********************************** fatal: [Dev-02]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 20.10.12.114
closed.\r\n", "module_stdout": "/bin/sh: /usr/bin/python3: No such
file or directory\r\n", "msg": "The module failed to execute
correctly, you probably need to set the interpreter.\nSee
stdout/stderr for the exact error", "rc": 127}
and the below output
{ "module_stdout": "/bin/sh: /usr/bin/python3: No such file or
directory\r\n", "module_stderr": "Shared connection to 20.10.12.114
closed.\r\n", "msg": "The module failed to execute correctly, you
probably need to set the interpreter.\nSee stdout/stderr for the exact
error", "rc": 127, "_ansible_no_log": false, "changed": false }
For context, this is the version of Python I have installed:
[ec2-user#ip-20-10-12-114 ~]$ pip --version
pip 21.0.1 from /usr/lib/python3.6/site-packages/pip (python 3.6)
[ec2-user#ip-20-10-12-114 ~]$ which pip
/usr/bin/pip
[ec2-user#ip-20-10-12-114 ~]$ python --version
Python 2.7.18
[ec2-user#ip-20-10-12-114 ~]$ which python
/usr/bin/python
[ec2-user#ip-20-10-12-114 ~]$ python3 --version
Python 3.6.2
[ec2-user#ip-20-10-12-114 ~]$ which python3
/usr/bin/python3

run python script locally using ansible passing remote host has input

want to fetch remote hosts with out ssh to the remote host i want to run python script local. by passing remote host has input to my python script
by {{ inventory_hostname }}".
- hosts: "{{ variable_host | default('web')}}"
become: true
any_errors_fatal: yes
serial: 1
tasks:
- name: execute install script
command: python myscript.py -i "{{ inventory_hostname }}" -f script.cql -u username-p password
delegate_to: 127.0.0.1
i got the error
FAILED! => {"changed": false, "failed": true, "module_stderr": "sudo: a password is required\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 1}
this looks like a case of ansible not knowing your sudo password.
see Specify sudo password for Ansible et al.

ansible python error : No module named os

I am getting the below error when deploying for the first time to a host using ansible.
I've tried using the default setup (I believe this is using default python 3.6 version on the system). I ve also attempted to add in the inventory a variable to use python 2.6(ansible_python_interpreter = /usr/bin/python2.6)
Same error :
FAILED! => {"changed": false, "failed": true, "module_stderr": "Shared
connection to myserverxx closed.\r\n", "module_stdout": "'import site'
failed; use -v for traceback\r\nTraceback (most recent call last):\r\n File
\"/home/myuser/.ansible/tmp/ansible-tmp-1531332066.08-
249430258979920/setup.py\", line 4, in <module>\r\n import
os\r\nImportError: No module named os\r\n", "msg": "MODULE FAILURE", "rc": 0}
On the host I can login and use python 3.6 interpreter and run import os (no error here).
EDIT :
example of command that fails. I have the issue with a ping, seems configuration issue (with python?).
ansible -m ping dev_myserver -i ansible-hosts
Content of ansible-hosts
[dev_myserver]
servername ansible_user=username
This is caused by python installation on the environment, nothing wrong with ansible (was able to reproduce the error while logged in locally).

Fatal error at provisioning while installing python

I have this playbook:
---
- hosts: all
become: yes
become_user: root
gather_facts: no
pre_tasks:
- name: 'install python2'
raw: sudo apt-get -y install python-simplejson
roles:
- git
...
Sometimes, it works perfectly fine and sometimes it gives me this error:
==> default: Running provisioner: ansible...
default: Running ansible-playbook...
PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=false ANSIBLE_SSH_ARGS='-o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -i '/var/www/test/.vagrant/machines/default/virtualbox/private_key' -o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook --connection=ssh --timeout=30 --extra-vars="ansible_ssh_user='ubuntu'" --limit="all" --inventory-file=ansible/hosts/hosts_linux.txt -v ansible/site.yml
Using /etc/ansible/ansible.cfg as config file
PLAY ***************************************************************************
TASK [install python2] *********************************************************
fatal: [10.0.11.44]: FAILED! => {"changed": false, "failed": true, "rc": 255, "stderr": "", "stdout": "", "stdout_lines": []}
PLAY RECAP *********************************************************************
10.0.11.44 : ok=0 changed=0 unreachable=0 failed=1
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
I am wondering why do I get this error and what does it mean? There is no output on the error and the exactly same code works if I try this many times. It makes no sense. Why is ansible failing to install python?
According to your comments, the problem is with ssh. You can create your own ansible.cfg file in your current working directory and supply openssh options directly as described here: open-ssh options
I suggest you try:
[defaults]
host_key_checking = False
And also during your playbook run, you can manually specify which ssh key to use like:
ansible-playbook --private-key /path/to/ssh_key ...
Finally, make sure there is no IP conflict, because your server's ssh fingerprint should not change. Try manually ssh'ing a few times as well.

Categories

Resources