Ansible installed from source - what should my library setting be? - ansible

I have installed Ansible from source as per the instructions at:
http://docs.ansible.com/ansible/intro_installation.html
However when I try to use any command other than script, I get the following error:
fatal: [...]: FAILED! => {"failed": true, "msg": "ERROR! The module get_url was not found in configured module paths"}
If the source Ansible directory is /home/cloud/ansible, and I have done a make install, what should I set the library path setting to in ansible.cfg?

As #udondan says, make sure you used:
git clone https://github.com/ansible/ansible --recursive
to clone the Ansible repo, and then run:
cd ./ansible
source ./hacking/env-setup
You don't need to run make install.
The machine that has Ansible running on it needs some other Python modules too, they are listed at the bottom of the http://docs.ansible.com/ansible/intro_installation.html#running-from-source section. Best to install the pip Python package manager with:
sudo easy_install pip
and then install the required packages:
sudo pip install paramiko PyYAML Jinja2 httplib2 six

Related

Ansible installation folder

I have installed Ansible on Ubuntu but it has installed it in the following directory:
/home/phill/.local/lib/python3.8/site-packages
rather than the expected /etc/ansible.
The command I used to install it was " python3 -m pip install --user ansible"
How do I get it to install in the /etc/ansible directory?
You don't want to "install" it to /etc/ansible. /etc is used for configuration files. You should read about the Filesystem Hierarchy Standard (FHS).
However, you can install ansible globally and create the /etc/ansible directory
sudo apt-get install ansible

Getting error when using Ansible playbook. error message: "msg": "boto required for this module"

I'm trying to execute a playbook for starting an ec2 instance. Have boto3 and python installed on both controlling machine and client node. But it still gives me the error saying:
"msg": "boto required for this module"
Have tried everything suggested here: Ansible ec2: "boto required for this module". But nada.
You are missing the python boto package on the host that is executing the Ansible playbooks.
You can install it via the python package manager
$ pip install boto --user
If you are using linux you can also install it via the package manager:
# RHEL/CentOS
$ sudo yum -y install python-pip
# Fedora
$ sudo dnf -y install python-pip
Package dependencies are listed on the Ansible website for each module. For example for the ec2 module the Ansible host dependencies are:
python >= 2.6
boto
It is worth noting that that boto, botocore, and boto3 are all separate packages.

Ansible: Unable to run docker compose in an ansible playbook

I appear to be unable to run docker compose tasks in an ansible playbook. I get stuck in a loop.
The first error I get when running sudo ansible-playbook playbook.yml is the following
fatal: [10.0.3.5]: FAILED! => {"changed": false, "msg": "Unable to load docker-compose. Try `pip install docker-compose`. Error: No module named compose"}
so I remote to that machine and did sudo pip install docker-compose and try running the playbook again. This time I get...
fatal: [10.0.3.5]: FAILED! => {"changed": false, "msg": "Cannot have both the docker-py and docker python modules installed together as they use the same namespace and cause a corrupt installation. Please uninstall both packages, and re-install only the docker-py or docker python module"}
so I try uninstalling docker python...
sudo uninstall docker python
Then I get the following when attempting to run the playbook again
fatal: [10.0.3.5]: FAILED! => {"changed": false, "msg": "Failed to import docker-py - No module named docker. Try `pip install docker-py`"}
However this is already install on the machine, as when I run sudo pip install docker-py I see the following...
Requirement already satisfied (use --upgrade to upgrade): docker-py in /usr/local/lib/python2.7/dist-packages
Cleaning up...
Does anyone know how to escape this loop and successfully get an ansible playbook that uses docker-compose to run?
The machine os is linux 14.04
Thanks,
What worked for me was to first uninstall everything docker related in the virtualenv for Ansible.
pip uninstall docker docker-py docker-compose
And then install the docker-compose module, which will install the docker module as well as a dependency.
pip install docker-compose
The Ansible docker module will try to import docker, which will also succeed with the docker module, and as such not provide an error with the misleading instruction to install docker-py.
I had the just had the same error message while trying to run sudo ansible playbook-with-docker.yaml
{"changed": false, "msg": "Unable to load docker-compose. Try `pip install docker-compose`. Error: No module named compose"}
I took me about 2 hours to figure out that in Linux pip install is not the same as sudo pip install (quite obvious, once you know what's happening ).
So in case someone has the same issue - make sure you're you are running everything consistently either as sudo or not sudo, but don't mix stuff :)
...and use sudo pip list | grep docker to verify.
As already stated in other answers, docker-compose python module is missing.
You can install it manually as previous answers indicate or you can use a "pure" Ansible solution that is to install via a task.
For that, use ansible.builtin.pip to install docker-compose module (you can add more modules to install if needed in the same task).
- hosts: all
gather_facts: no
tasks:
- name: Install docker-compose python package
ansible.builtin.pip:
name: docker-compose
Reference: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/pip_module.html
To add more context to Thermostat's answer
I was using pip3 and not pip with the following:
Ubuntu 20.04
Ansible 2.10.7
Python 3.8.10
pip 20.0.2 (pip3)
Here's how I fixed mine:
So first I ran the command to remove all existing copies of docker, docker-py and docker-compose python libraries:
pip3 uninstall docker docker-py docker-compose
And then ran the command below to install the python docker-compose library alongside the python docker library
pip3 install docker-compose
That's all.

Can AWS CLI be installed using Python2.7?

I installed AWS CLI from Python 2.7 using python -m pip install awscli. It seemed to install, but then when trying to run aws, I get 'aws' is not recognized as an internal or external command.
The documentation states that I should add to PATH this:
%USERPROFILE%\AppData\Local\Programs\Python\Python36\Scripts
But this is for Python3. Where is it installed for Python2? There is nothing in %USERPROFILE%\AppData\Local\Programs\ (I checked). And does installation work for Python2 or only for Python3?
After lots of searching, the file was located at c:\Python27\Scripts\aws.cmd. But it was aws.cmd, not aws.exe. So to make aws work, you need to add it to the PATH:
set PATH=%PATH%;c:\Python27\Scripts
After that it works:
c:\Python27>aws --version
File association not found for extension .py
aws-cli/1.11.148 Python/2.7.14rc1 Windows/10 botocore/1.7.6
Although there is still this weird File association not found for extension .py error.
Edit: From #zwer's comment about "File association not found for extension .py", you need to execute this from an administrator cmd prompt:
assoc .py=Python.File
ftype Python.File=c:\Python27\python.exe "%1" %*
The best approach to get this done is
Install pip
pip Install awscli
aws configure
keys and identification keys access parameters
To Install PIP:
need to update YUM Release version and then install python-pip
#yum install epel-release
#yum install python-pip
Install AWSCLI:
#pip install awscli
Configure AWSCLI:
#aws configure
aws_access_key_id=<########>
aws_secret_access_key=<####################>
Default Region[None]: region=us-west-2
format[none]: json
you can find these configuration parameters later in file::
~/.ssh/aws/credentials

ansible-galaxy role fails with "do not have permission to modify /etc/ansible/roles/"

tl;dr = How do OS X users recommend working around this permissions error?
I'm on OS X 10.10.1 and I recently installed Ansible running the following:
sudo pip install ansible --quiet
sudo pip install ansible --upgrade
I want to start off with a galaxy role to install homebrew and went to run this one with the following error:
$ ansible-galaxy install geerlingguy.homebrew
- downloading role 'homebrew', owned by geerlingguy
- downloading role from https://github.com/geerlingguy/ansible-role-homebrew/archive/1.0.1.tar.gz
- extracting geerlingguy.homebrew to /etc/ansible/roles/geerlingguy.homebrew
- error: you do not have permission to modify files in /etc/ansible/roles/geerlingguy.homebrew
- geerlingguy.homebrew was NOT installed successfully.
- you can use --ignore-errors to skip failed roles.
While I see /etc is owned by root, I don't see any notes in documentation saying I should chmod anything.
For reference:
$ ansible --version
ansible 1.8.2
configured module search path = None
Is this expected or is my installation somehow wrong?
The default location for roles is /etc/ansible/roles (for version <= 2.3. Since v2.4, the default location has changed to ~/.ansible/roles/, an issue has been raised). You need to specify --roles-path when using ansible-galaxy. Here's what ansible-galaxy install --help says:
-p ROLES_PATH, --roles-path=ROLES_PATH
The path to the directory containing your roles. The
default is the roles_path configured in your
ansible.cfg file (/etc/ansible/roles if not
configured)
You can also set roles_path in ansible.cfg; see the documentation for details.
Or you can use brew to install ansible. To do it you would need to run:
brew install ansible
If you had any previous installations, it is possible that you will see a message like this:
Error: The brew link step did not complete successfully The formula
built, but is not symlinked into /usr/local Could not symlink
bin/ansible Target /usr/local/bin/ansible already exists. You may want
to remove it: rm '/usr/local/bin/ansible'
To force the link and overwrite all conflicting files: brew link
--overwrite ansible
To list all files that would be deleted: brew link --overwrite
--dry-run ansible
Possible conflicting files are: /usr/local/bin/ansible
/usr/local/bin/ansible-console /usr/local/bin/ansible-doc
/usr/local/bin/ansible-galaxy /usr/local/bin/ansible-playbook
/usr/local/bin/ansible-pull /usr/local/bin/ansible-vault
So, run brew link --overwrite ansible to fix that. And now you will be able to install any roles without sudo.
Example:
ยป ansible-galaxy install bennojoy.redis
- downloading role 'redis', owned by bennojoy
- downloading role from https://github.com/bennojoy/redis/archive/master.tar.gz
- extracting bennojoy.redis to /usr/local/etc/ansible/roles/bennojoy.redis
- bennojoy.redis was installed successfully
As I saw you used "sudo" to install Ansible, I suppose it shall be OK to continue using "sudo" for ansible-galaxy installation. And that's what I just did.

Resources