有人可以确认这是否是错误吗?
- name: "Test"
hosts: localhost
vars_files:
- env_file.yml
roles:
- role: Juniper.junos
environment:
"{{ env_vars }}"
connection: local
gather_facts: no
tasks:
- name: "Juniper VPN primary managed"
juniper_junos_config:
load: "merge"
config_mode: "private"
check: true
commit: false
template: "provisioning templates/Juniper_primary_managed.j2"
format: "text"
vars:
- 'unrelated to this issue vars'
provider:
host: "{{ ansible_host }}"
timeout: 180
register: response
环境文件包含:
---
env_vars:
ANSIBLE_NET_USERNAME: 'username'
ANSIBLE_NET_PASSWORD: 'password'
运行剧本会产生以下结果:
TASK [test] ******************************************************************************************************************************************************
task path: /data/rundeck/juniper_provision/file1.yaml:44
Using module file /etc/ansible/roles/Juniper.junos/library/juniper_junos_config.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root
<127.0.0.1> EXEC /bin/sh -c 'ANSIBLE_NET_USERNAME=usename ANSIBLE_NET_PASSWORD=password /usr/local/bin/python3.6 && sleep 0'
fatal: [localhost]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"attempts": null,
"baud": null,
"check": true,
"check_commit_wait": null,
"comment": null,
"commit": false,
"commit_empty_changes": false,
"config_mode": "private",
"confirmed": null,
"console": null,
"dest": null,
"dest_dir": null,
"diff": null,
"diffs_file": null,
"filter": null,
"format": "text",
"host": "randomhost",
"ignore_warning": null,
"level": null,
"lines": null,
"load": "merge",
"logdir": null,
"logfile": null,
"mode": null,
"options": {},
"passwd": null,
"port": 830,
"retrieve": null,
"return_output": true,
"rollback": null,
"src": null,
"ssh_config": null,
"ssh_private_key_file": null,
"template": "template",
"timeout": 180,
"url": null,
**"user": "root",**
"vars": {
您可以看到用户是 root ,即使我正在设置ANSIBLE_NET_USERNAME变量,它也是环境变量USER设置的用户。
根据juniper.junos文档,选择用户变量的优先级如下:
1)ANSIBLE_NET_USERNAME环境变量。 (由Ansible Tower使用)
2)Ansible定义的remote_user。 Ansible通过多种方法设置此值,包括
a)ansible或ansible-playbook命令的-u或--user命令行参数。
b)ANSIBLE_REMOTE_USER环境变量。
c)remote_user配置设置。有关用于设置remote_user值的优先级,请参见Ansible文档。
3)USER环境变量。以下列表中的第一个定义的值
1)ANSIBLE_NET_PASSWORD环境变量。 (由Ansible Tower使用)
2)使用ansible或ansible-playbook命令的-k或--ask-pass命令行参数指定的值。
3)无(密码/密码为空)
我认为系统有问题,所以我添加了一个简单的任务:
- shell: echo ANSIBLE_NET_USERNAME is $ANSIBLE_NET_USERNAME
register: shellout
- debug: var=shellout
输出:
ok: [localhost] => {
"shellout": {
"changed": true,
"cmd": "echo ANSIBLE_NET_USERNAME is $ANSIBLE_NET_USERNAME",
"delta": "0:00:00.002403",
"end": "2018-09-20 10:14:27.806416",
"failed": false,
"rc": 0,
"start": "2018-09-20 10:14:27.804013",
"stderr": "",
"stderr_lines": [],
"stdout": "ANSIBLE_NET_USERNAME is username",
"stdout_lines": [
"ANSIBLE_NET_USERNAME is username"
]
}
}
到目前为止,我已经尝试了各种方法来设置环境变量,但是juniper.junos拒绝接受它,除非在使用'export'运行剧本之前将其设置为
有什么想法吗?