Yum module not found ansible - vagrant

I'm very new to Vagrant and Ansible, somehow I managed to setup Vagrant and have a box running but when i try to provision it with Ansible then I get error.ImportError: No module named yum
My playbook looks like below :-
---
- hosts: default
connection: local
sudo: true
tasks:
- name: install apache
yum: name=httpd state=latest
I'm using Ubuntu as my host machine and have Vagrant 1.8.5 and latest version of Ansible on it.Can somebody please suggest where I'm mistaking. Thanks in advance.

With
connection: local
you are running the playbook on your host which is Ubuntu.
And that's why it doesn't find yum.

Related

Installing the deb package via ansible

I am trying to install a deb package on a remote server using ansible, using the following construction
- name: Install deb
delegate_to: app1
apt:
deb: https://example.com/deb/package.deb
or
- name: Install deb
delegate_to: app1
apt:
deb: /path/to/deb
playbook works, says that everything is ok, but in fact the package is not installed, if you connect to a remote server and manually run apt install /path/to/deb, then the package is installed. I tried to copy deb to the server using ansible and install it by downloading the package from an Internet resource, the result is always the same
You have to use the privilege escalation methods become and become_method: sudo for Ansible. Installing a package need sudo privilege.
- name: Install deb
delegate_to: app1
apt:
deb: /path/to/deb
become: yes
The following modification of the task helped
- name: Install deb
command: apt install /path/to/package.deb -y --allow-downgrades
The allow_downgrade directive for the apt module appeared, starting with the ansible 2.12 version in my 2.9 it did not work, as the force directive did not work, I had to implement the task using a not very nice method.

Install AWS SSM Agent on multiple EC2 instances using Ansible

I have a requirement where I have to install AWS SSM Agent on multiple EC2 instances(of different flavors) using Ansible. Can someone please help me? or Suggest me how to achieve this?
I wrote the following script and tried. It is working but, is there a way to achieve this using "Package" module? Because I am afraid my approach might do a reinstall (even if it is already installed). Thanks in advance.
(OR)
Do you think it is better to use Shell commands (https://aws.amazon.com/premiumsupport/knowledge-center/install-ssm-agent-ec2-linux/) in the Ansible script to install the agent and refer to them based on the condition of os flavour?
---
- hosts: all
remote_user: ansible
become: true
tasks:
- name: install SSM if REDHAT
command: "{{ item }}"
loop:
- sudo yum install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm
- sudo systemctl enable amazon-ssm-agent
- sudo systemctl start amazon-ssm-agent
when: ansible_os_family == "RedHat"
- name: install SSM if UBUNTU
command: "{{ item }}"
loop:
- sudo snap install amazon-ssm-agent --classic
- sudo systemctl start snap.amazon-ssm-agent.amazon-ssm-agent.service
when: ansible_os_family == "Debian"

How ansible find python modules on target and is it possible to use virtualenv to install modules dependencies?

I need to create some snake-oil certificates on some playbook and I'm using openssl_privatekey, openssl_csr and openssl_certificate modules for this. The problem is that this module depens on PyOpenSSL and that CentOS versions of PyOpenSSL are outdated.
To workaround this I install PyOpenSSL from pip, which works, but may overwrite an already existing PyOpenSSL module if that was installed with yum.
On my playbook I'm doing this:
- name: 'Install PyOpenSSL'
pip:
name: PyOpenSSL
state: present
version: '>= 0.15'
Now, is there a way to install this in a virtual environment, so that ansible is aware of it? If so I can simply remove the virtual environment in the play's end.
You can create a virtualenv with the pip module. You can probably make Ansible aware of that virtualenv by setting the ansible_python_interpreter fact to point at the python binary in the virtualenv, so something like:
---
- hosts: localhost
gather_facts: false
tasks:
- name: install modules
pip:
state: present
name: "{{ modules }}"
virtualenv: /tmp/venv
vars:
modules:
- pyopenssl
- set_fact:
ansible_python_interpreter: /tmp/venv/bin/python
Caveat: I haven't tested this thoroughly. It didn't break anything.

Unable to run Ansible 'expect' module

I am trying to run an Ansible script that invokes the 'expect' module (see end of the message).
When I run it, I get error:
The pexpect python module is required
Yet, the pip task for installing pexpect runs without error.
What am I doing wrong?
Thx.
Alain Désilets
=== Playbook content ===
---
- name: Run Anaconda shell
hosts: all
vars:
conda_home: "~/anaconda2-NEW"
conda_inst_sh_path: /path/to/Anaconda2-2018.12-MacOSX-x86_64.sh
tasks:
- name: install pexpect
pip:
name: pexpect
become: yes
become_user: root
- name: Run anaconda installation script
expect:
command: "sh {{conda_inst_sh_path}}"
responses:
(?i)password: "MySekretPa$$word"
become: yes
become_user: root
As the Ansible documentation of the expect module states:
The below requirements are needed on the host that executes this module.
python >= 2.6
pexpect >= 3.3
You need to install pexpect in a minimum version of 3.3 besides python >= 2.6 on the target system, that means that you have to install pexpect and python on every system, that is defined under hosts: all.

Can't create gitlab project with ansible [duplicate]

I'm just getting started with ansible, and I'm trying to get it to work with the linode module from OSX Yosemite. I'm using brew-installed Python, and pip-installed ansible. So I have done the following:
$ brew install python
$ PYCURL_SSL_LIBRARY=nss pip install pycurl
$ CFLAGS=-Qunused-arguments CPPFLAGS=-Qunused-arguments pip install ansible
To test:
$ which python
/usr/local/bin/python
$ python --version
Python 2.7.9
$ which ansible
/usr/local/bin/ansible
$ ansible --version
ansible 1.8.2
configured module search path = None
When I run my playbook I get:
failed=True msg='pycurl required for this module'
So somehow ansible is not seeing the pycurl library.
Here is the playbook:
---
- hosts: 127.0.0.1
connection: local
gather_facts: no
tasks:
- name: "provision a server"
local_action:
module: linode
api_key: FOO
name: linode-test1
plan: 1
datacenter: 1
distribution: 99
password: 'superSecureRootPassword'
ssh_pub_key: ssh-rsa FOO
swap: 768
wait: yes
wait_timeout: 600
state: present
It's happening on ubuntu as well, finally figured out the solution. You need to explicity pass path to python executable
Change Ansible hosts file from
[local]
localhost
to
[local]
localhost ansible_python_interpreter=/usr/local/bin/python
or to your virtual environment python path.
I was able to fix this on OS X El Capitan 10.11.6 by editing hosts:
[local]
localhost ansible_python_interpreter=/usr/local/bin/python
You may then need additional Python dependencies:
pip install pycurl
pip install linode-python

Resources