1 回答

TA貢獻(xiàn)2051條經(jīng)驗(yàn) 獲得超10個(gè)贊
我建議使用查找插件管道和將變量轉(zhuǎn)儲(chǔ)到 json 的 python 文件:
Python 文件 vars.py:
import json
initial = [{'name': "MyTestSite",
'alias': 'site1',
'website_url': ['website1.test.com' ,'website1.othertest.com'],
'projectname':'Testsite',
'id':'12345678'},
{'name': '"OtherTestSite"',
'alias': 'foobar',
'website_url': ['foobar.test.com' ,'foobar2.test.com'],
'projectname':'foobar',
'id':'98765432'}]
print(json.dumps(initial))
和劇本代碼:
---
- name: Test command
hosts: localhost
tasks:
- name: Load variable to fact
set_fact:
the_var: "{{ lookup('pipe', 'python vars.py') | from_json }}"
- name: Test command
debug:
msg: "{{ item }}"
with_list: "{{ the_var }}"
在使用之前不要忘記將文件上傳到節(jié)點(diǎn)。
使用 ansible 2.7.6 進(jìn)行測(cè)試
添加回答
舉報(bào)