当我执行这个playbook时,遇到了一些问题:
- hosts: all
connection: local
tasks:
- template: src=/etc/ansible/{{group_names}}/common.j2 dest=/etc/ansible/configs/{{inventory_hostname}}.txt
name: create common config snippets
我得到的错误是:
fatal: [R1]: FAILED! => {"changed": false, "failed": true, "msg": "Unable to find '/etc/ansible/[u'ios']/common.j2' in expected paths."}
fatal: [R2]: FAILED! => {"changed": false, "failed": true, "msg": "Unable to find '/etc/ansible/[u'ios1']/common.j2' in expected paths."}
这是我的群组:
/etc/ansible# cat hosts | grep ios
[ios]
[ios1]
这里是我的common.j2
文件:
/etc/ansible# ls ios1/
common.j2
/etc/ansible# ls ios/
common.j2
请问有人能详细解释一下为什么 group_names
返回的是 [u'group_names']
吗?
group_names
是一个列表,详见魔术变量和如何访问其他主机的信息。在文件名中这样替换是没有意义的。 - larsks