Ansible installation folder - ansible

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

Related

Pip: install --find-links on multiple folder

I create a virtual environment with the command:
python -m venv ./my_venv
After activating this virtual env, I want to install some packages with .tar.gz archives.
My method to install my packages is explained in the following part:
PACKAGE1='/path/to/the/folder1'
PACKAGE2='/path/to/the/folder2'
PACKAGE3='/path/to/the/folder3'
PACKAGE4='/path/to/the/folder4'
pip install --find-links="${PACKAGE1}" package_1==1.0.0
pip install --find-links="${PACKAGE2}" package_2==1.0.0
pip install --find-links="${PACKAGE3}" package_3==1.0.0
pip install --find-links="${PACKAGE4}" package_4==1.0.0
Now I want to use a file requirements.txt like:
package_1==1.0.0
package_2==1.0.0
package_3==1.0.0
package_4==1.0.0
and run the command:
pip install --find-links="${PACKAGE}" -r requirements.txt
but
I don't find the way to tell pip to install using multiple folder.
Here is an example of what I want:
PACKAGE1='/path/to/the/folder1'
PACKAGE2='/path/to/the/folder2'
PACKAGE3='/path/to/the/folder3'
PACKAGE4='/path/to/the/folder4'
pip install --find-links="${PACKAGE1}" --find-links="${PACKAGE2}" --find-links="${PACKAGE3}" --find-links="${PACKAGE4}" -r requirements.txt
Obviously, I didn't work.
Can you help me ? :)
Have a look at the --find-links documentation again:
If a local path ... that’s a directory, then look for archives in the directory listing.
So /path/to/the/folder4 for example will need to contain an archive/wheel for package4. This will not work if /path/to/the/folder4 is just the source directory/root for package4.

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

How do I install pip modules on google compute engine?

I am trying to run some python script using ssh to log into the google compute engine but all the installed pip modules are not found as I do not have permission to the .cache/pip folder in my user is there a correct way to do this?
You should be running this with the root user.
Also, if you need pip inside your GCP Instance, you can use the following commands:
sudo curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
sudo python get-pip.py
[Source]
Use:
sudo apt-get install python3-pip
sudo runs this command as an administrator
apt-get is the standard package manager used on Debian Linux distributions
python3-pip is the package name for pip3
Once installed, you can install PIP modules with:
pip3 install MODULE_NAME
for example:
pip3 install tensorflow
I'm not entirely sure there is one correct way to do this, but an easy way would be to use the conda python package manager.
The lighter version of it is miniconda. You can get a minimal python installation with pip preinstalled, and virtual environments capability if you need. Assuming you are running on linux and want python 3, you'll have to run
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
and then install conda with
bash Miniconda3-latest-Linux-x86_64.sh
At the end of this process you should have a minimal python installation (that includes pip) and you'll be able to install packages with pip as you are used to.
You might want to install some basic libraries first -
sudo apt-get install bzip2 libxml2-dev
Then install miniconda as given by #teoguso and restart your shell
source ~/.bashrc
You can then use conda or pip to install your packages

How to install ansible on amazon aws?

Having trouble running Ansible on the latest version of amazon linux.
[root#ip-10-0-0-11 ec2-user]# yum install ansible --enablerepo=epel
[root#ip-10-0-0-11 ec2-user]# ansible-playbook
Traceback (most recent call last):
File "/usr/bin/ansible-playbook", line 44, in <module>
import ansible.playbook
ImportError: No module named ansible.playbook
Using AMI ID: ami-a10897d6.
Any ideas?
It appears that python library files do not have correct permissions by default. Running this fixed it for me.
[root#ip-10-0-0-11 ansible]# pip install ansible
Using pip (alone, not in conjunction with yum) is probably the best option right now on Amazon Linux. I'd suggest getting rid of the yum-installed copy if it's still there.
The RPM specs in epel and epel-testing (as of 1.9.2) currently handle only RHEL, Fedora, and SuSE, and the defaults are installing everything under Python 2.6, where the latest Amazon Linux has default Python 2.7. A bit of work will be required to get the RPM install working under Amazon Linux...
For Amazon Linux2 AMI:
sudo yum update
sudo yum install ansible
or
sudo amazon-linux-extras install ansible2
For Amazon Linux AMI:
sudo yum update
sudo yum install ansible --enablerepo=epel
For Ubuntu 18.04 AMI:
sudo apt-get update
sudo apt-get install ansible
Note: You can install ansible using "pip".
sudo yum install python-pip
sudo pip install ansible
Why not check out the source code from git and and checkout the latest stable version.
git clone git://github.com/ansible/ansible.git --recursive
$ cd ./ansible
$ source ./hacking/env-setup
git checkout <VERSION>
Just enable the below repo from the /etc/yum.repos.d/redhat-rhui.repo file by default is disabled.
rhui-REGION-rhel-server-extras/7Server/x86_64
This article says that you can use sudo amazon-linux-extras install ansible2 to install ansible on Amazon linux.
On Amazon Linux 2 to get the latest version of Ansible do not use yum (currently it won't give you 2.10.x), I recommend you use python3-pip.
sudo yum remove ansible
sudo yum install -y python3-pip
python3 -m pip install --user --upgrade pip # Do not run pip as sudo. Do this instead.
python3 -m pip install ansible
If you don't already have python3 you may need this step before the above:
sudo yum install -y python3.7
In my case, I needed ansible 2.10.x because it has the added benefit of requirements.yml files being able to install collections directly from git repositories.
This answer is based off of #M.Rajput's answer. I wanted to define the details so I wouldn't forget.
Warning: this was only tested on a RHEL 7.7 Community AMI (ami-029c0fbe456d58bd1).
# modify yum repo enabled
sudo vi /etc/yum.repos.d/redhat-rhui.repo
# find entry titled [rhui-rhel-7-server-rhui-extras-rpms]
# change "enabled=0" to "enabled=1"
# save and quit file (vim command is :wq)
sudo yum install ansible

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