Ansible Automation Platform中目录存在却提示不存在的排查求助
Ansible find模块报错指定路径非目录的排查方案
问题描述
通过Ansible Automation Platform调度playbook获取指定目录下的所有文件,playbook片段如下:
- name: Find Backup Files to Move find: paths: /path/to/directory recurse: no excludes: 'test-file.tar.gz' delegate_to: localhost register: testfiles
playbook持续失败,报错信息:
[WARNING]: Skipped '/path/to/directory' path due to this access issue: '/path/to/directory' is not a directory
手动确认目录存在且非空,执行ll /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
已执行的排查操作
- 执行
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
- 执行
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
- 执行
ls -ld /path/输出:
drwxr-x---. 4 awx awx 62 Dec 5 23:12 /path/
- 测试
/tmp/ansible_backups/目录,playbook输出:
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 " ] } } PLAY RECAP ********************************************************************* localhost : ok=4 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
目前问题升级,Ansible无法识别本地存在的目录,需进一步排查。
排查建议
- 确认执行环境的文件系统隔离性:从环境变量可知,任务运行在AWX的OCI执行容器中,容器文件系统与宿主机完全隔离。你指定的
/path/to/directory是宿主机路径,容器内大概率不存在该路径,测试的/tmp/ansible_backups/同理。 - 配置宿主机目录挂载:在AWX作业模板配置中,将宿主机的
/path/to/directory挂载为容器内可访问的路径(如/mnt/backup),然后修改playbook中paths参数为容器内路径。 - 验证容器内路径存在性:在playbook中添加调试任务,直接在容器内执行目录检查:
- name: Check directory in container command: ls -ld /path/to/directory delegate_to: localhost register: dir_check - name: Print check result debug: var: dir_check
若输出提示目录不存在,说明路径未挂载到容器,需调整AWX执行环境的挂载配置。
- 检查SELinux策略限制:容器内的SELinux策略可能限制路径访问,可临时关闭容器内SELinux测试(不建议生产环境),或调整宿主机挂载目录的SELinux标签。
内容的提问来源于stack exchange,提问作者user1913559
相关产品推荐
相关产品推荐

