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

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.

Related

Ansible - Unhandled error in Python interpreter discovery for

I have a problem trying to ping to machines using ansible, 1 is fedora 35 the 2nd is ubuntu 21.
when I run
ansible all -i inventory -m ping -u salam -k
I get the following warnings
[WARNING]: Unhandled error in Python interpreter discovery for host
myubuntuIP: unexpected output from Python interpreter discovery
[WARNING]: sftp transfer mechanism failed on [myubuntuIP]. Use
ANSIBLE_DEBUG=1 to see detailed information
[WARNING]: scp transfer
mechanism failed on [myubuntuIP]. Use ANSIBLE_DEBUG=1 to see detailed
information myubuntuIP | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong" }
[WARNING]: Platform unknown on host myfedoraIP 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.14/reference_appendices/interpreter_discovery.html
for more information. myfedoraIP | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
when I do
which python3
on both machines, I get 2 different paths as follows
/usr/bin/python3 for fedora box /bin/python3 for ubuntu box
I understand from 1 thread here that we should indicate the path of python in ansible.cfg file, Can I indicate 2 different paths in the ansible.cfg? If yes how? and why ansible is not able to find the python path?
First, the error on your Ubuntu system appears unrelated to this question; it says:
[WARNING]: sftp transfer mechanism failed on [myubuntuIP]
[WARNING]: scp transfer mechanism failed on [myubuntuIP]
I suspect to diagnose that issue you'll need to follow the instructions in the error message, set ANSIBLE_DEBUG=1, and if the cause isn't immediately obvious open a new question here for that particular issue.
I understand from 1 thread here that we should indicate the path of python in ansible.cfg file, Can I indicate 2 different paths in the ansible.cfg? If yes how?
You don't set this in your ansible.cfg (unless you really do want a single setting for all your hosts); you set this in your Ansible inventory or in your host_vars or group_vars directory. For example, to set this on a specific host in your inventory, you might do something like this:
all:
hosts:
host1:
ansible_python_interpreter: /usr/bin/python3
host2:
host3:
You could accomplish the same thing by placing:
ansible_python_interpreter: /usr/bin/python3
In host_vars/host1.yaml.
If the same configuration applies to more than one host, you can group them and then apply the setting as a group variable. For example, to apply the setting only to a subset of your hosts:
all:
hosts:
host1:
children:
fedora_hosts:
vars:
ansible_python_interpreter: /usr/bin/python3
hosts:
host2:
host3:
Or to apply it globally:
all:
vars:
ansible_python_interpreter: /usr/bin/python3
hosts:
host1:
host2:
host3:
And why ansible is not able to find the python path?
That's not what the warning is telling you -- it was able to find the Python path (/usr/bin/python), but "future installation of another Python interpreter could change the meaning of that path" (because /usr/bin/python, depending on your distribution, could actually be python 2 instead of python 3, etc).

Python error running Ansible via SSM against EC2

I'm trying to run a fairly routing ansible playbook against ec2 instances in my AWS environment
---
- name: get python
hosts: myhost
become: true
vars:
ansible_connection: aws_ssm
ansible_aws_ssm_profile: myprofile
ansible_aws_ssm_region: eu-west-1
ansible_aws_ssm_bucket_name: "mybucketname"
tasks:
- name: run command
command: pwd
I can see that the connection to the instance works, but I get the following error
fatal: [i-000011112222aaaa]: FAILED! => {
"ansible_facts": {},
"changed": false,
"failed_modules": {
"ansible.legacy.setup": {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3.6"
},
"failed": true,
"module_stderr": "",
"module_stdout": " File \"/home/ssm-user/.ansible/tmp/ansible-tmp-1641395807.063974-83634-44643497283265/AnsiballZ_setup.py\", line 1\r\r\n <?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\r\n ^\r\r\nSyntaxError: invalid syntax\r\r",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1,
"warnings": [
"Platform linux on host i-000011112222aaaa is using the discovered Python interpreter at /usr/bin/python3.6, but future installation of another Python interpreter could change the meaning of that path. See https://docs.ansible.com/ansible-core/2.11/reference_appendices/interpreter_discovery.html for more information."
]
}
},
"msg": "The following modules failed to execute: ansible.legacy.setup\n"
}
My ansible.cfg looks like this
[defaults]
enable_plugins = aws_ec2
host_key_checking = False
pipelining = True
ansible_python_interpreter = /usr/bin/python3.9
My ansible --version
ansible [core 2.11.6]
config file = /Users/myuser/Repositories/myrepo/ansible/ansible.cfg
configured module search path = ['/Users/myuser/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/ansible
ansible collection location = /Users/myuser/.ansible/collections:/usr/share/ansible/collections
executable location = /Library/Frameworks/Python.framework/Versions/3.10/bin/ansible
python version = 3.10.0 (v3.10.0:b494f5935c, Oct 4 2021, 14:59:19) [Clang 12.0.5 (clang-1205.0.22.11)]
jinja version = 3.0.2
libyaml = True
I can see in the ansible --version that python3.10 is being referenced, but I'm specifying 3.9 in my ansible_python_interpreter. Is there a reason on the host side this wouldn't work? Running the command directly on the host works without issue.

Error in executing ansible playbook on target server without 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'?

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.

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