.ansible/tmp/ansible-tmp-* Permission denied - ansible

Remote host throws error while running Ansible playbook despite a user being sudo user.
"/usr/bin/python: can't open file '/home/ludd/.ansible/tmp/ansible-tmp-1466162346.37-16304304631529/zypper'

A fix that worked for me, was to change the path of the ansible's remote_tmp directory, in ansible's configuration file, e.g.
# /etc/ansible/ansible.cfg
remote_tmp = /tmp/${USER}/ansible
Detailed information can be found here.
Note: With ansible v4 (or later) this this variable might look like this ansible_remote_tmp check the docs
Caution:Ansible Configuration Settings can be declared and used in a configuration file which will be searched for in the following order:
ANSIBLE_CONFIG (environment variable if set)
ansible.cfg (in the current directory)
~/.ansible.cfg (in the home directory)
/etc/ansible/ansible.cfg

I had to set variable ansible_remote_tmp rather than remote_tmp in order to make it working.

Changing remote_tmp didn't solve the issue for me. What did solve it, however, was removing --connection=local from the playbook invocation.

How does the file in question get to the host? Do you copy or sync it? If you do, may want do to do
chmod 775 fileName
on the file before you send it to the host.

Related

Running Ansible playbook from a file in Rundeck

I am trying to run Ansible playbook stored in my local drive. I am using wsl 2 which is where I have installed Ansible and Rundeck.
Playbook path: /home/hannan/wslNodeRedProjects/ansible/myplaybook1.yml
On providing the correct location of the playbook I get the following errors:
ERROR! the playbook: /home/hannan/wslNodeRedProjects/ansible/myplaybook1.yml could not be found
*Failed: AnsibleNonZero: ERROR: Ansible execution returned with non zero code.
*
I am not sure why I am getting an error even after specifying the correct location.
I wanted to know if I am missing anything or should I need to provide other options like Ansible binaries directory path as well.
This error might indicate that the user establishing the local SSH connection to execute the playbook (default: rundeck) doesn't have executable permissions to the full playbook path.
This could be resolved by either using a user with the right executable permissions, or by granting executable permissions to the specific user with ACL, like so:
$ setfacl -R -m user:rundeck:x /path/to/playbook/
setfacl - set file access control lists.
-R, --recursive -
apply operations to all files and directories recursively.
-m, --modify -
modify the ACL of a file or directory. ACL entries for this operation must include permissions.
See man setfacl for further reading.

Ansible: ansible.cfg from current directory?

Is it possible to make ansible first search for .ansible.cfg in current directory, instead of always defaulting to home directory? Similarly like many configs work, where it looks in your current dir, then parent (and so on) to find relevant config.
Yet with ansible it always uses config from one place.
When I started deploying with different inventory in mind, I forgot about that, thinking that it will use my local config (where I set path to another inventory, different roles etc), but it of course it used default options and deployed in wrong environments, wrong things..
Is there a way to properly manage multiple configs with ansible?
Say I have dir my-ansible and in that dir, I have .ansible.cfg, so doing cd my-ansible and ansible-playbook my-playbook.yml it would use config in that directory, not in my home dir?
You should use ansible.cfg, not .ansible.cfg in current directory, see
https://docs.ansible.com/ansible/latest/reference_appendices/config.html#the-configuration-file
Changes can be made and used in a configuration file which will be searched for in the following order:
ANSIBLE_CONFIG (environment variable if set)
ansible.cfg (in the current directory)
~/.ansible.cfg (in the home directory)
/etc/ansible/ansible.cfg

Getting a python warning when running playbook EC2 inventory

I am really new to Ansible and I hate getting warnings when I run a playbook. This environment is being used for my education.
Environment:
AWS EC2
4 Ubuntu 20
3 Amazon Linux2 hosts
Inventory
using the dynamic inventory script
playbook
just runs a simple ping against all hosts. I wanted to test the inventory
warning
[WARNING]: Platform linux on host XXXXXX.amazonaws.com is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change the
meaning of that path. See https://docs.ansible.com/ansible-core/2.11/reference_appendices/interpreter_discovery.html for more information.
Things I have tried
updated all sym links on hosts to point to the python3 version
adding the line "ansible_python_interpreter = /usr/bin/python" to "/etc/ansible/ansible.cfg"
I am relying on that cfg file
I would like to know how to solve this. since I am not running a static inventory, I didn't think that I could specific an interpreter on a per host or group of hosts. While the playbook runs, it seems that something is not configured correctly and I would like to get that sorted. This is only present on the Amazon Linux instances. the Ubuntu instances are fine.
Michael
Thank you. I did find another route that work though I am sure that you suggest would also work.
I was using the wrong configuration entry. I was using
ansible_python_interpreter = /usr/bin/python
when I should have been using
interpreter_python = /usr/bin/python
on each host I made sure that /usr/bin/python sym link was pointing and the correct version.
according to the documentation
for individual hosts and groups, use the ansible_python_interpreter inventory variable
globally, use the interpreter_python key in the [defaults] section of ansible.cfg
Regards, Michael.
You can edit your ansible.cfg and set auto_silent mode:
interpreter_python=auto_silent
Check reference here:
https://docs.ansible.com/ansible/latest/reference_appendices/interpreter_discovery.html

Ansible is not creating .retry files

I'm using Ansible 2.8 version and i do not see .retry files getting created if the playbook fails to execute tasks on servers.
I do not see any error message as such
Entries in ansible.cfg are as below.
Since the retry_files_enabled defaults to true i have not made any changes to cfg file. Does anyone know the reason why it isnt creating .retry files?
#retry_files_enabled = False
#retry_files_save_path = ~/.ansible-retry
You can check the actual values of configuration by running
ansible-config dump
The reason the Ansible behavior is different from the value in a configuration file is that Ansible have few possible places to look for configuration files, and some of them may have higher preference than your. (f.e. ansible.cfg in the directory with the playbook).
The default behaviour was changed via this proposal:
https://github.com/ansible/proposals/issues/155
RETRY_FILES_ENABLED now defaults to False

How can I tell if my ansible.cfg is working?

I have an ansible.cfg file. Ansible isn't behaving as expected for me, but I don't know if that's because my configuration isn't working or because my ansible.cfg file isn't even getting picked up at all.
How can I verify whether my ansible.cfg is working?
Q: "I don't know if my configuration isn't working or my ansible.cfg file isn't even getting picked up at all."
A: Run the command
shell> ansible-config dump --only-changed
This will "Only show configurations that have changed from the default" and will also reveal the source of the change either it's a configuration file or an environment variable.
For details see Configuration settings.

Resources