Reputation: 366
I have a playbook scheduled via Ansible Automation Platform that gets all of the files within a directory. Below is an excerpt:
- name: Find Backup Files to Move
find:
paths: /path/to/directory
recurse: no
excludes: 'test-file.tar.gz'
delegate_to: localhost
register: testfiles
This playbook keeps failing with the following message:
[WARNING]: Skipped '/path/to/directory' path due to this access issue:
6
'/path/to/directory' is not a directory
The directory certainly does exist, and it is not empty. Below is the output from an ll
command on /path/to/directory
:
-rwxr-x---. 1 awx awx 98358 Dec 6 00:00 test-file-2022-backup-12-06-00:00:06.tar.gz
lrwxrwxrwx. 1 awx awx 80 Dec 6 00:00 test-file-latest.tar.gz -> /path/to/directory/test-file-backup-2022-12-06-00:00:06.tar.gz
What can I do to troubleshoot this further? It's not clear to me that this is a permission issue.
Below is the output from ls -alZ /path
:
total 4
drwxr-x---. 4 awx awx unconfined_u:object_r:default_t:s0 62 Dec 5 23:12 .
dr-xr-xr-x. 18 root root system_u:object_r:root_t:s0 244 Dec 5 23:11 ..
drwxr-x---. 7 awx awx unconfined_u:object_r:admin_home_t:s0 154 Dec 6 10:00 dir1
drwxr-x---. 2 awx awx unconfined_u:object_r:default_t:s0 4096 Dec 6 10:00 to
Below is the output from ls -alZ /path/to/directory
:
drwxr-x---. 2 awx awx unconfined_u:object_r:default_t:s0 4096 Dec 6 10:00 .
drwxr-x---. 4 awx awx unconfined_u:object_r:default_t:s0 62 Dec 5 23:12 ..
-rwxr-x---. 1 awx awx unconfined_u:object_r:default_t:s0 98358 Dec 6 00:00 test-file-backup-2022-12-06-00:00:06.tar.gz
-rwxr-x---. 1 awx awx unconfined_u:object_r:default_t:s0 105073 Dec 6 02:00 test-file-backup-2022-12-06-02:00:05.tar.gz
-rwxr-x---. 1 awx awx unconfined_u:object_r:default_t:s0 105066 Dec 6 04:00 test-file-backup-2022-12-06-04:00:05.tar.gz
-rwxr-x---. 1 awx awx unconfined_u:object_r:default_t:s0 105070 Dec 6 06:00 test-file-backup-2022-12-06-06:00:05.tar.gz
-rwxr-x---. 1 awx awx unconfined_u:object_r:default_t:s0 105068 Dec 6 08:00 test-file-backup-2022-12-06-08:00:05.tar.gz
-rwxr-x---. 1 awx awx unconfined_u:object_r:default_t:s0 107031 Dec 6 10:00 test-file-backup-2022-12-06-10:00:05.tar.gz
lrwxrwxrwx. 1 awx awx unconfined_u:object_r:default_t:s0 80 Dec 6 10:00 test-file-backup-latest.tar.gz -> /path/to/directory/test-file-backup-2022-12-06-10:00:05.tar.gz
Below is the output from ls -ld /path/
drwxr-x---. 4 awx awx 62 Dec 5 23:12 /path/
I've tried to follow the example from @U88OD and below is the output I received:
PLAY [localhost] ***************************************************************
TASK [Gathering Facts] *********************************************************
ok: [localhost]
TASK [Show environment] ********************************************************
ok: [localhost] => {
"msg": [
"root",
{
"ANSIBLE_HOST_KEY_CHECKING": "False",
"RUNNER_ONLY_FAILED_EVENTS": "False",
"ANSIBLE_PARAMIKO_RECORD_HOST_KEYS": "False",
"PKGMGR_OPTS": "--nodocs --setopt=install_weak_deps=0 --setopt=rhel-8-for-x86_64-appstream-rpms.excludepkgs=ansible-core",
"_": "/usr/bin/python3.9",
"AWX_ISOLATED_DATA_DIR": "/runner/artifacts/15",
"HOSTNAME": "87098dfce111",
"MAX_EVENT_RES": "700000",
"AWX_HOST": "https://FQDN",
"ANSIBLE_UNSAFE_WRITES": "1",
"DESCRIPTION": "Red Hat Ansible Automation Platform Supported Execution Environment",
"container": "oci",
"INVENTORY_ID": "2",
"PROJECT_REVISION": "",
"ANSIBLE_SSH_CONTROL_PATH_DIR": "/runner/cp",
"AWX_PRIVATE_DATA_DIR": "/tmp/awx_15_7u3ff0s7",
"PWD": "/runner/project",
"HOME": "/home/runner",
"LC_CTYPE": "C.UTF-8",
"ANSIBLE_RETRY_FILES_ENABLED": "False",
"ANSIBLE_ROLES_PATH": "/runner/requirements_roles:~/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles",
"ANSIBLE_STDOUT_CALLBACK": "awx_display",
"ANSIBLE_INVENTORY_UNPARSED_FAILED": "True",
"ANSIBLE_COLLECTIONS_PATHS": "/runner/requirements_collections:~/.ansible/collections:/usr/share/ansible/collections",
"TERM": "xterm",
"RUNNER_OMIT_EVENTS": "False",
"JOB_ID": "15",
"ANSIBLE_FORCE_COLOR": "True",
"SHLVL": "2",
"ANSIBLE_CALLBACK_PLUGINS": "/runner/artifacts/15/callback",
"PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
},
[
"/runner/inventory/hosts"
],
"Ansible Backup",
15,
"manual"
],
"_ansible_verbose_always": true,
"_ansible_no_log": null,
"changed": false
}
[WARNING]: Skipped '/tmp/ansible_backups/' path due to this access issue:
'/tmp/ansible_backups/' is not a directory
ok: [localhost]
TASK [Show result] *************************************************************
ok: [localhost] => {
"result": {
"changed": false,
"examined": 0,
"failed": false,
"files": [],
"matched": 0,
"msg": "Not all paths examined, check warnings for details",
"skipped_paths": {
"/tmp/ansible_backups/": "'/tmp/ansible_backups/' is not a directory"
},
"warnings": [
"Skipped '/tmp/ansible_backups/' path due to this access issue: '/tmp/ansible_backups/' is not a directory\n"
]
}
}
PLAY RECAP *********************************************************************
localhost : ok=4 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
There appears to be something seriously wrong because Ansible cannot find any local directories!
Upvotes: 0
Views: 2971
Reputation: 366
It appears as though the @U880D is correct. This playbook is running within a container, and that doesn’t have access to the underlying host file system. This is a new change in Ansible Automation Platform 2. More details can be found here:
In my use case an external process is running a backup job in Ansible and I want to copy the files to a NFS.
For anyone else that is trying to run this, I ended up creating a bash script and dropping it in /etc/cron.hourly
. That bash script includes backing up Tower and copying the files from the backup folder to remote storage. I'm also deleting past backups older 14 days. Below is the bash script:
#!/bin/bash
# Switch to the Ansible backup folder.
cd /tower_backup/ansible-tower-backup-scripts/;
# Run the Ansible Backup
./setup.sh -e 'backup_dest=/tmp/ansible_backups/' -b > /dev/null
# Copy all of the files in this folder over to remote storage.
cp -n /tmp/ansible_backups/*.tar.gz /mnt/ansible_backups/
# Delete remote backups older than 14 days.
find /mnt/ansible_backups -mtime +14 -delete;
# Delete local backups older than 2 days.
find /tmp/ansible_backups -type f -mtime +2 -delete;
Remember to mount the NFS before you create the cron job otherwise, your files will not be copied over to remote storage.
Upvotes: 2
Reputation: 12124
What can I do to troubleshoot this further? It's not clear to me that this is a permission issue.
According your description I understand that you like to do an investigation or debugging on your Control Node(s) (only). To do so, you may have a look into the following minimal test playbook.
- hosts: localhost
gather_facts: true
tasks:
- name: Show environment
debug:
msg:
- "{{ ansible_user }}"
- "{{ ansible_env }}"
- "{{ ansible_inventory_sources }}"
- "{{ tower_job_template_name }}"
- "{{ tower_job_id }}"
- "{{ tower_job_launch_type }}"
- name: Find available files
find:
paths: ['/tmp/ansible/', '/home/awx/']
recurse: yes
file_type: directory
register: result
- name: Show result
debug:
var: result
The following directories are available and accessible
$ ls -alZ /home/ | grep awx
drwx------. awx awx unconfined_u:object_r:home_root_t:s0 awx
$ ls -alZ /tmp/ansible/ | tail -2
drwxrwxr-x. user users unconfined_u:object_r:user_tmp_t:s0 facts_cache
Executing the playbook (on a RHEL 7.9.x system, no container environment, Ansible Engine 2.9.27, Python 2.7.5, Ansible Tower 3.7.x, Python 3.6) will result into an output of
TASK [Show environment] ********************************************************
ok: [localhost] => {
"msg": [
"root",
{
"ANSIBLE_CALLBACK_PLUGINS": "/var/lib/awx/venv/awx/lib64/python3.6/site-packages/awx/plugins/callback:/var/lib/awx/venv/awx/lib64/python3.6/site-packages/ansible_runner/callbacks",
"ANSIBLE_COLLECTIONS_PATHS": "/tmp/awx_1234_abcd/requirements_collections:~/.ansible/collections:/usr/share/ansible/collections",
"ANSIBLE_FACT_CACHE_TIMEOUT": "0",
...
"ANSIBLE_ROLES_PATH": "/tmp/awx_1234_abcd/requirements_roles:./:~/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles",
"ANSIBLE_SSH_CONTROL_PATH_DIR": "/tmp/awx_1234_abcd/cp",
"ANSIBLE_STDOUT_CALLBACK": "awx_display",
"ANSIBLE_VENV_PATH": "/var/lib/awx/venv/ansible",
"AWX_HOST": "https://awx.example.com",
"AWX_ISOLATED_DATA_DIR": "/tmp/awx_1234_abcd/artifacts/1234",
"AWX_PRIVATE_DATA_DIR": "/tmp/awx_1234_abcd",
...
"HOME": "/var/lib/awx",
"INVENTORY_ID": "1",
...
"JOB_ID": "1234",
...
"PATH": "/var/lib/awx/venv/ansible/bin:/var/lib/awx/venv/awx/bin:/opt/rh/rh-postgresql10/root/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin",
...
"PROJECT_REVISION": "abcdefg...0123456...tuvwxyz",
"PROOT_TMP_DIR": "/tmp",
"PWD": "/tmp/awx_1234_abcd/project/localhost",
"PYTHONPATH": "/var/lib/awx/venv/ansible/lib/python2.7/site-packages:/var/lib/awx/venv/awx/lib64/python3.6/site-packages/awx/lib:/var/lib/awx/venv/awx/lib64/python3.6/site-packages/ansible_runner/callbacks",
"RUNNER_OMIT_EVENTS": "False",
"RUNNER_ONLY_FAILED_EVENTS": "False",
...
"SHLVL": "2",
"SUPERVISOR_ENABLED": "1",
"SUPERVISOR_GROUP_NAME": "tower-processes",
"SUPERVISOR_PROCESS_NAME": "awx-dispatcher",
"SUPERVISOR_SERVER_URL": "unix:///var/run/supervisor/supervisor.sock",
"TZ": "UTC",
"USER": "awx",
"VIRTUAL_ENV": "/var/lib/awx/venv/ansible",
"_": "/usr/bin/python2"
},
[
"/tmp/awx_1234_abcd/tmp1234abcd"
],
"localhost - Debug execution environment",
1234,
"manual"
]
}
TASK [Find available files] ****************************************************
ok: [localhost]
TASK [Show result] *************************************************************
ok: [localhost] => {
"result": {
"changed": false,
"examined": 2,
"failed": false,
"files": [
{
...
"path": "/tmp/ansible/facts_cache",
"pw_name": "awx",
...
}
],
"matched": 1,
"msg": "/home/awx/ was skipped as it does not seem to be a valid directory or it cannot be accessed\n"
}
}
From the output you can see that the directory under /tmp/
can be accessed but under /home/
not.
Please take note of in especially of
"ANSIBLE_VENV_PATH": "/var/lib/awx/venv/ansible"
"HOME": "/var/lib/awx"
"PROOT_TMP_DIR": "/tmp"
"USER": "awx"
"VIRTUAL_ENV": "/var/lib/awx/venv/ansible"
and others.
Summary
For me this seems to be the expected behavior.
How to proceed further?
Change your path to under /tmp/awx/
or /var/lib/awx
and do further testing.
Upvotes: 0