Ansible /etc/ansible missing PIP - ansible

I have recently reimaged my laptop with Ubuntu 18.04 and after installing Ansible(2.7.5) via PIP (python2) I have realised that /etc/ansible is missing.
Removing the package and reinstalling it has not changed anything. Apart from missing the /etc/ansible Ansible is working. Any idea how to force the creation of directory on the install?
Or shall I just create it manually?

Yes. You can create is manually. Or, you might want to take the one from the Ubuntu package (when there is a reason not to install it completely).
# dpkg -l | grep ansible
ii ansible 2.7.5-1ppa~bionic all
# apt-file list ansible | grep ansible.cfg
ansible: /etc/ansible/ansible.cfg

Related

ansible config file not found; using defaults

I have created venv called ansible and installed ansible using
pip3 install ansible. Now while checking ansible version config file = None
ansible --version
ansible 2.9.12
config file = None
configured module search path = ['/home/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/ansible/ansible/lib/python3.7/site-packages/ansible
executable location = /home/ansible/ansible/bin/ansible
python version = 3.7.4 (default, Aug 18 2019, 12:04:45) [GCC 5.4.0 20160609]
When I run ansible command it says No config file found; using defaults but which is that defaults file and where it can be found ?
Q: "Which is that default file and where can it be found?"
A: Short answer: There doesn't have to be any configuration file. In this case, the hardcoded defaults will apply.
Details:
Quoting from Getting the latest configuration
"If installing Ansible from a package manager, the latest ansible.cfg file should be present in /etc/ansible ..."
See The configuration file. Ansible searches configuration files in this order:
ansible.cfg (in the current directory)
~/.ansible.cfg (in the home directory)
/etc/ansible/ansible.cfg
If there isn't any configuration file the defaults will apply. See the hardcoded defaults in Ansible Configuration Settings. The output of the below command will show you where each configuration option comes from
shell> ansible-config dump
ansible configuration file is only created automatically during the installation if you perform the installation with package managers like yum or apt-get. If you installed ansible using pip you should create the configuration file manually.
sudo apt remove ansible
sudo apt update
sudo apt install software-properties-common
sudo apt-add-repository --yes --update ppa:ansible/ansible
sudo apt install ansible
now you can get the ansible configuration location
It's not wise to name your virtual environment ansible I suggest to rename it.
Please share the command which you used to create the virtual environment (because you should activate it, I do not see it from what you have shared)
If you want a quick fix for your issue , you could declare a environment variable named ANSIBLE_CONFIG with the location of your desired configuration.
Ansible looks for the config file in this order:
ANSIBLE_CONFIG (env var)
ansible.cfg (in the current directory)
~/.ansible.cfg (in the home directory)
/etc/ansible/ansible.cfg

Gather Installed Homebrew Packages as Ansible "facts" for MacOS

I can gather a list of Ansible facts on my MacOS system locally, using the following command:
ansible -m setup localhost
However, this list of facts doesn't provide a list of Homebrew packages that are installed, apparently.
If I run this command, I don't get any extra information about installed Homebrew packages either:
ansible -m homebrew localhost
All I get is the following output:
localhost | SUCCESS => {
"changed": false,
"msg": ""
}
Question: How can I extend Ansible to gather a list of installed Homebrew packages as Ansible "facts"?
To solve this, I just learned how to create Ansible custom facts via this article.
The solution is painfully simple. I created the following custom Ansible fact file under the path /etc/ansible/facts.d/homebrew.fact, which worked flawlessly.
#!/usr/bin/env pwsh
brew list -1 | ConvertTo-Json
Make sure that you make the *.fact* files executable as well, otherwise they won't be called by Ansible.
sudo chmod +x /etc/ansible/facts.d/homebrew.fact
NOTE: Requires PowerShell to be installed. brew cask install powershell

Ansible: path to ansible.cfg

I have this known issue. So I try to fix it but I don't see where I have to create my ansible.cfg (or does it already exist)? I tried it in my homedirectory but it still did not work.
sudo vi ~/.ansible.cfg
I read a lot about /etc/ansible but on my system it isn't there.
I'm on Mac El Capitan. I've installed ansible by using pip.
ansible --version
ansible 1.9.4
configured module search path = None
From the docs:
Changes can be made and used in a configuration file which will be processed in the following order:
ANSIBLE_CONFIG (an environment variable)
ansible.cfg (in the current directory)
.ansible.cfg (in the home directory)
/etc/ansible/ansible.cfg
I'm not sure this does 100% apply to 1.9.4. Ansible is terrible in versioning their documentation. (=there only is one version and not always the version a feature was introduced or changed is mentioned)
But I am sure everything except ~/.ansible.cfg works in 1.x as I have tried that before.
So if you have created ~/.ansible.cfg and it is not being used, check if the environment var ANSIBLE_CONFIG is set or there is one file in the directory from where you call ansible. The first one found will be used. processed in the following order does not mean they will be merged in that order. First one found wins.
I read a lot about /etc/ansible but on my system it isn't there.
Yeah, that depends on how Ansible was installed. If it's not there you could just create it but if you do not need it, no need to create it. I actually deleted mine as I see no use for it.
For latest version (2.7.6) if you install via pip you wont get ansible folder in /etc.
so this is what you get when you do ansible --version
ansible --version
ansible 2.7.6
config file = None
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
But once you manually create directory under /etc as ansible and add ansible.cfg file there ansible automatically detects it. but you will have to configure the rest manually like hosts file..etc . so after this we get
ansible --version
ansible 2.7.6
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
I got the same thing when I used pip. But I think better way is either using apt or yum according to your OS.
I have centOS so following worked for me.
To get Ansible for CentOS 7, first ensure that the CentOS 7 EPEL repository is installed:
sudo yum install epel-release
Once the repository is installed, install Ansible with yum:
sudo yum install ansible
We now have all of the software required to administer our servers through Ansible.
Reference: https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-ansible-on-centos-7

Offline Ansible Control Machine installation

I need to install Ansible Control Machine behind a corporate firewall with no internet access. I can't find documentation for an offline install. I have access on my workstation to download anything I want and can copy it to the target machine. I have tried searching online but have not been able to find examples on how to do this. My server is Ubuntu 14.04 but if anyone has documentation for Red Hat or another distro that would also help.
I did a testing on my RH6, so if you have a RH6 with Internet access to download all required installation file, and a RH6 installation ISO. You should be able to achieve this.
Assuming you have a RH6 which has Internet access, let's call it A. And another one doesn't have access: B.
download Ansible and Jinja2 from A, and copy the files to B.
For Ansible: http://docs.ansible.com/ansible/intro_installation.html
Jinja2 is required for Ansible, download it here:
https://pypi.python.org/pypi/Jinja2
Mount the RH6 installation ISO to your RH6 B, then install the required RPM.
In my case, i installed PIP as well:
rpm -ivh python-paramiko-1.7.5-2.1.el6.noarch.rpm libyaml-0.1.3-4.el6_6.x86_64.rpm PyYAML-3.10-3.1.el6.x86_64.rpm perl-TermReadKey-2.30-13.el6.x86_64.rpm perl-Error-0.17015-4.el6.noarch.rpm python-six-1.9.0-2.el6.noarch.rpm
//following required for Git
rpm -ivh --force --nodeps perl-Git-1.7.1-3.el6_4.1.noarch.rpm
rpm -ivh git-1.7.1-3.el6_4.1.x86_64.rpm
Note: i didn't install httplib2 here, you can do it later.
install MarkupSafe (required for Jinja2)
//install MarkupSafe
tar -xvf MarkupSafe-0.23.tar.gz
cd MarkupSafe-0.23/
sudo python setup.py install
install Jinja2
//install Jinjia2
tar -xvf Jinja2-2.8.tar.gz
cd Jinja2-2.8/
sudo python setup.py install
On RH6 B, you should be able to run Ansible now:
tar -zxvf ansible.tar.gz
source ./hacking/env-setup
echo "127.0.0.1" > ~/ansible_hosts
export ANSIBLE_INVENTORY=~/ansible_hosts
ansible --version
I know this is a very old question, but I've found the answer in this blog post and I believe that could help someone out there.
Although this post aproach is on a CentOS/RHEL machine, I believe the procedure is very similar to other distros:
Download the packages (RPM) dependencies
Download the Ansible packages
Upload the downloaded packages to the target machine
Install it using yum localinstall
Or you could also install it from the source.

How can I install simplejson on hosts without root or yum, using ansible?

I want to install simplejson on the hosts on which I want to run my playbook.
I don't have root access to those servers, I can't yum install anything.
Running this ignores the first module defined in the command:
ansible all -i hosts.ini -u dtoma -m copy -a "src=simplejson-3.8.0.tar.gz dest=~/simplejson.tgz" -m raw
Is it possible at all to use two modules in one ansible command?
My version of ansible is:
$ ansible --version
ansible 1.8.2
configured module search path = None
I could write a script to do this but I wanted to try using Ansible.
Is it possible at all to use two modules in one ansible command?
The ansible command is used to invoke a single module. Most people use it mainly for testing purposes.
If you need to bootstrap installing python-json, and can't do it via yum, etc. then you probably need to manually copy the tarball over via scp first, then do something like:
$ ansible all -i hosts.ini -u dtoma -m raw -a "tar xzf simplejson.tgz ; cd simplejson ; python setup.py install"

Resources