Ansible throwing errors while installing packages via apt and yum

ansible

I am trying to install packages in ansible using playbook. For that i need to install some packages in yum and some in apt.
The version of ansible i am using is:

root@server:~# ansible --version
ansible 2.6.0

when i try to run this playbook for yum, i get this error:

fatal: [centos]: FAILED! => {"changed": false, "module_stderr": "Shared connection to centos closed.\r\n", 
"module_stdout": "sudo: a password is required\r\n", 
"msg": "MODULE FAILURE", "rc": 1}
to retry, use: --limit @/root/test.retry

when i try to run this playbook for apt, i get this error:

fatal: [server]: FAILED! =>
{"changed": false, "module_stderr": "Shared connection to server closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n File \"/tmp/ansible_t9NeHG/ansible_module_apt.py\", line 269, in \r\n from ansible.module_utils.urls import fetch_url\r\n File \"/tmp/ansible_t9NeHG/ansible_modlib.zip/ansible/module_utils/urls.py\", line 95, in \r\n File \"/usr/lib/python2.7/dist-packages/urllib3/contrib/pyopenssl.py\", line 54, in \r\n import OpenSSL.SSL\r\n File \"/usr/lib/python2.7/dist-packages/OpenSSL/init.py\", line 8, in \r\n from OpenSSL import rand, crypto, SSL\r\n File \"/usr/lib/python2.7/dist-packages/OpenSSL/SSL.py\", line 118, in \r\n SSL_ST_INIT = _lib.SSL_ST_INIT\r\nAttributeError: 'module' object has no attribute 'SSL_ST_INIT'\r\n", "msg": "MODULE FAILURE", "rc": 1}

enter image description here

I have gone through various help posts, but this is the way they have suggested to run the playbook. Where am i making the mistakes? Could you please specify. Thank you in advance

Best Answer

I really did lot of work out to solve this issue. The reason was simple. We need to install Python in the remote machine.

For that, use

# apt-get install python-pip

check the version of python installed on remote machine:

# python --version

Next on the remote machine make sure that we can access them without password. For that, edit sudoers file:

# visudo or #nano /etc/sudoers

then at the end of the file, add

user ALL=(ALL) NOPASSWD: ALL

and save it.

This will do the trick and should work on every installation steps for yum as well as apt.