ansible vars 变量传入测试

来源:本站原创 网络技术 超过139 views围观 0条评论

测试从

1 hosts传入

2 从yaml本身传入

目录

├── vars_files
│   └── varfiles.yaml
├── vartest.yaml

——–hosts———

[var_test]
192.168.142.10[2:4]
[var_test:vars]
key=test-var

———–测试vartest.yaml

– hosts: var_test
  #vars_files:
  #    – varfiles.yaml
  vars:
      key1: 1
      key2: 2
      key3: 3
  tasks:
    – name: 从hosts文件读取变量display var form hosts files 值为test-var
      debug: msg="the {{inventory_hostname}} value is {{key}}"
    – name: 从本文件读取变量from local vars key 值为2
      debug: msg="the {{inventory_hostname}} value is {{key2}}"
    #- name: from vars_files–> varfiles.yaml
    #  debug: msg="the {{inventory_hostname}} value is {{key22}}"

 

——测试结果———

[root@ansible_master yamllist]# ansible-playbook vartest.yaml

TASK [从hosts文件读取变量display var form hosts files] **************************************************************
ok: [192.168.142.102] => {
    "msg": "the 192.168.142.102 value is test-var"
}
ok: [192.168.142.103] => {
    "msg": "the 192.168.142.103 value is test-var"
}
ok: [192.168.142.104] => {
    "msg": "the 192.168.142.104 value is test-var"
}

TASK [从本文件读取变量from local vars key] ***************************************************************************
ok: [192.168.142.102] => {
    "msg": "the 192.168.142.102 value is 2"
}
ok: [192.168.142.103] => {
    "msg": "the 192.168.142.103 value is 2"
}
ok: [192.168.142.104] => {
    "msg": "the 192.168.142.104 value is 2"

文章出自:CCIE那点事 http://www.jdccie.com/ 版权所有。本站文章除注明出处外,皆为作者原创文章,可自由引用,但请注明来源。 禁止全文转载。
本文链接:http://www.jdccie.com/?p=3704转载请注明转自CCIE那点事
如果喜欢:点此订阅本站
  • 相关文章
  • 为您推荐
  • 各种观点

暂时还木有人评论,坐等沙发!
发表评论

快捷键:Ctrl+Enter