告诉我,我无法理解。为了测试,我赶紧勾勒,体验0..j2文件:
{% for group in groups['all'] %}
Host {{ group }}
User {{ ansible_user }}
{% endfor %}
主机文件:
[test1]
localhost1 ansible_host=localhost ansible_host_ip=127.0.0.1 ansible_user=arch1 ansible_connection=local
localhost2 ansible_host=localhost ansible_host_ip=127.0.0.2 ansible_user=test ansible_connection=local
localhost3 ansible_host=localhost ansible_host_ip=127.0.0.3 ansible_user=test ansible_connection=local
[test2]
localhost4 ansible_host=localhost ansible_host_ip=127.0.0.4 ansible_user=root1 ansible_connection=local
.yml 文件:
---
- name: Test SSH create
hosts: all
tasks:
- name: Update Test SSH Jinja2
template:
src: /etc/ansible/temlates/ssh_test.j2
dest: /etc/ansible/test
并输出:
Host localhost1
User test
Host localhost2
User test
Host localhost3
User test
Host localhost4
User test
为什么 ansible_user 总是一样的?他为什么不把它们一一放下?据我了解,这是因为 ansible_user 变量取自创建配置的主机。如何在不使用模块的情况下解决此问题?
这就是我所需要的,如何指定变量并不明显。