ansible - ansible-playbook:无法使用 fileglob 在预期路径中找到子目录
问题描述
我尝试从roles/common/files
with复制文件fileglob
,但ansible-playbook
在roles/common/tasks/files
使用角色文档说:
任何副本、脚本、模板或包含任务(在角色中)都可以引用角色/x/{files,templates,tasks}/(目录取决于任务)中的文件,而无需相对或绝对路径。
剧本:
# ./ansible/roles/common/tasks/main.yml
- hosts: localhost
connection: local
gather_facts: no
tasks:
- name: setup bashrc
import_tasks: bashrc.yml
任务:
# ./ansible/roles/common/tasks/bashrc.yml
- name: try to find bashrc libs in roles/common/files/bashrc
copy:
src: "{{ item }}"
dest: /tmp
with_fileglob:
- bashrc/*.lib.sh
# Causes the same error:
# loop: "{{ lookup('fileglob', 'bashrc/*', wantlist=True) }}"
文件树:
.
├── ansible
│ └── roles
│ └── common
│ ├── files
│ │ └── bashrc
│ │ ├── shell-aliases.lib.sh
│ │ ├── shell-functions.lib.sh
│ │ └── shell-settings.lib.sh
│ └── tasks
│ ├── bashrc.yml
│ ├── main.retry
│ └── main.yml
运行剧本:
$ ansible-playbook -vvvvv ./ansible/roles/common/tasks/main.yml
...
TASK [try to find bashrc libs in roles/common/files/bashrc] *******...
task path: /home/<user>/git/homedirsync/ansible/roles/common/tasks/bashrc.yml:1
looking for "bashrc" at "/home/<user>/git/homedirsync/ansible/roles/common/tasks/files/bashrc"
looking for "bashrc" at "/home/<user>/git/homedirsync/ansible/roles/common/tasks/bashrc"
looking for "bashrc" at "/home/<user>/git/homedirsync/ansible/roles/common/tasks/files/bashrc"
looking for "bashrc" at "/home/<user>/git/homedirsync/ansible/roles/common/tasks/bashrc"
[WARNING]: Unable to find 'bashrc' in expected paths
...
Ansible 版本:
ansible 2.6.1
config file = /home/<user>/.ansible.cfg
configured module search path = [u'/var/ansible/library']
ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
executable location = /usr/local/bin/ansible
python version = 2.7.6 (default, Nov 13 2018, 12:45:42) [GCC 4.8.4]
我看到了很多它有效的例子和它不起作用的问题,但在我的案例中我无法定位问题的根源。社区,请帮助。
解决方案
问:“无法使用 fileglob 在预期路径中找到子目录”
A: 引用fileglob 的 NOTES
“匹配是针对 Ansible 控制器上的本地系统文件。”
角色的特性“任何副本、脚本、模板或包含任务都可以引用 roles/x/{files,templates,tasks} ... 中的文件”不适用于fileglob。
相反,可以使用特殊变量。例如
with_fileglob:
- '{{ role_path }}/files/bashrc/*.lib.sh'
推荐阅读
- jinja2 - Jinja2 - 输出键:嵌套字典的值格式
- sql - 如何处理数据仓库中重复id包含略有不同值的维度表?
- node.js - 尝试使用 .insert 从多个集合 mongo 获取数据,但继续收到“不是函数”错误
- javascript - WordPress 使用 json_encode 将帖子从 php 发送到 js,并将 ID 发布到 div
- android - 即使应用程序未运行,我如何检查数据?
- c - 在C中连接具有特殊结束字符的字符串
- javascript - 嵌套异步函数的问题(异步系列中的异步瀑布)
- java - 发送电子邮件时如何向 Amazon SES 服务提供 AWS 密钥?
- python - 列表正确访问部分元素的列表
- coldfusion - 以更大的内容呈现 XML