ansible vars 變量傳入測試

來源:本站原創 網絡技術 超過1,219 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}}"

 

——測試結果———

[[email protected]_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.qdxgqk.live/ 版權所有。本站文章除注明出處外,皆為作者原創文章,可自由引用,但請注明來源。 禁止全文轉載。
本文鏈接:http://www.qdxgqk.live/?p=3704轉載請注明轉自CCIE那點事
如果喜歡:點此訂閱本站
  • 相關文章
  • 為您推薦
  • 各種觀點
?
暫時還木有人評論,坐等沙發!
發表評論

您必須 [ 登錄 ] 才能發表留言!

?
?
萌宠夺宝游戏