ansible config file not found; using defaults - ansible

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

Related

Does poetry (or pip) 'install' create/have the option to deploy an executable?

I am running
poetry install
from within a python local virtualenv ".venv" . The project is supposed to create an executable hercl that becomes available on the user's path. Two questions:
What options / configuration of I'm not sure if that's supposed to gets installed into the local .venv/bin or in the pyenv shims.
Since poetry reuses / redirects many functions to pip it may be the case that the feature I'm asking about is actually from pip itself. I have not been able to discover from either poetry or pip documentation about this shell script installation. How is this achieved?
Update
After running running pip install outside of the virtualenv it pulls from pypi and creates a bash script ~/.pyenv/shims/my_app .
In my case the my_app is "hercl" and we see this:
$which hercl
~/.pyenv/shims/hercl
Its contents are :
$cat $(which hercl)
#!/usr/bin/env bash
set -e
[ -n "$PYENV_DEBUG" ] && set -x
program="${0##*/}"
export PYENV_ROOT="~/.pyenv"
exec "~/.pyenv/libexec/pyenv" exec "$program" "$#"
Somehow this script is installed when running pip install: I am wondering how pip knows to do this. Is it from the pyproject.ml from poetry ? Is it from a setup.py or setup.cfg associated with pip ?
Anoterh Update #sinoroc has another tack on this: poetry has a scripts section that I did not notice (noobie on that tool).
[tool.poetry.scripts]
hercl = "hercl.hercl:main"
hercl is a command that I was looking for .
But there was also an actual _bash script that would launch hercl that got installed under the shims as part of the virtualenv. i think that script were in the
In a Poetry-based project such executable scripts are defined in the scripts section of pyproject.toml.
If a virtual environment is active when installing the application then the executable is installed in the virtual environment's bin directory. So it is available only while the virtual environment is "active".

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 /etc/ansible missing PIP

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

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

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