运行 Ansible Play 级别问题的环境变量
Running Environment variable at Ansible Play level question
我在主剧本文件中声明了以下命令:
---
- name: Install config
hosts: all
become: yes
become_method: sudo
become_user: root
roles:
- initial_config
environment:
http_proxy: http://{{ProxyHost}}:{{ProxyPort}}
https_proxy: http://{{ProxyHost}}:{{ProxyPort}}
ftp_proxy: http://{{ProxyHost}}:{{ProxyPort}}
在我的 group_vars/ all 中:我已经声明了这些参数:
ProxyHost: proxy.test.com
ProxyPort: 9999
no_proxy: 'test.com'
但是当我 运行 主剧本 本地 说:
时我收到错误消息
ERROR! Syntax Error while loading YAML.
found unexpected end of stream
下图
shell> cat group_vars/all
ProxyHost: proxy.test.com
ProxyPort: 9999
no_proxy: test.com
shell> cat pb.yml
- hosts: test_01
environment:
http_proxy: "http://{{ ProxyHost }}:{{ ProxyPort }}"
https_proxy: "http://{{ ProxyHost }}:{{ ProxyPort }}"
ftp_proxy: "http://{{ ProxyHost }}:{{ ProxyPort }}"
tasks:
- shell: set | grep proxy
register: result
- debug:
var: result.stdout_lines
给予
shell> ansible-playbook pb.yml
PLAY [test_01] **********
TASK [shell] ************
changed: [test_01]
TASK [debug] ************
ok: [test_01] => {
"result.stdout_lines": [
"SUDO_COMMAND='/bin/sh -c echo BECOME-SUCCESS-hhojceebldohrrfvivcndrtjtvtrzgfg ; http_proxy=http://proxy.test.com:9999 https_proxy=http://proxy.test.com:9999 ftp_proxy=http://proxy.test.com:9999 /usr/local/bin/python3.7 /home/admin/.ansible/tmp/ansible-tmp-1588775688.2160842-43227888427690/AnsiballZ_command.py'",
"ftp_proxy=http://proxy.test.com:9999",
"http_proxy=http://proxy.test.com:9999",
"https_proxy=http://proxy.test.com:9999"
]
}
PLAY RECAP **********
test_01: ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
我在主剧本文件中声明了以下命令:
---
- name: Install config
hosts: all
become: yes
become_method: sudo
become_user: root
roles:
- initial_config
environment:
http_proxy: http://{{ProxyHost}}:{{ProxyPort}}
https_proxy: http://{{ProxyHost}}:{{ProxyPort}}
ftp_proxy: http://{{ProxyHost}}:{{ProxyPort}}
在我的 group_vars/ all 中:我已经声明了这些参数:
ProxyHost: proxy.test.com
ProxyPort: 9999
no_proxy: 'test.com'
但是当我 运行 主剧本 本地 说:
时我收到错误消息ERROR! Syntax Error while loading YAML.
found unexpected end of stream
下图
shell> cat group_vars/all
ProxyHost: proxy.test.com
ProxyPort: 9999
no_proxy: test.com
shell> cat pb.yml
- hosts: test_01
environment:
http_proxy: "http://{{ ProxyHost }}:{{ ProxyPort }}"
https_proxy: "http://{{ ProxyHost }}:{{ ProxyPort }}"
ftp_proxy: "http://{{ ProxyHost }}:{{ ProxyPort }}"
tasks:
- shell: set | grep proxy
register: result
- debug:
var: result.stdout_lines
给予
shell> ansible-playbook pb.yml
PLAY [test_01] **********
TASK [shell] ************
changed: [test_01]
TASK [debug] ************
ok: [test_01] => {
"result.stdout_lines": [
"SUDO_COMMAND='/bin/sh -c echo BECOME-SUCCESS-hhojceebldohrrfvivcndrtjtvtrzgfg ; http_proxy=http://proxy.test.com:9999 https_proxy=http://proxy.test.com:9999 ftp_proxy=http://proxy.test.com:9999 /usr/local/bin/python3.7 /home/admin/.ansible/tmp/ansible-tmp-1588775688.2160842-43227888427690/AnsiballZ_command.py'",
"ftp_proxy=http://proxy.test.com:9999",
"http_proxy=http://proxy.test.com:9999",
"https_proxy=http://proxy.test.com:9999"
]
}
PLAY RECAP **********
test_01: ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0