在Ansible中,有没有办法将位于JSON变量中的键/值对的动态列表转换为可在不使用文件系统的情况下在Playbook中访问的变量名称/值?
IE - 如果我在变量中有以下JSON(在我的情况下,已经从URI调用中导入):
{
"ansible_facts": {
"list_of_passwords": {
"ansible_password": "abc123",
"ansible_user": "user123",
"blue_server_password": "def456",
"blue_server_user": "user456"
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法将该JSON变量转换为equivelant:
vars:
ansible_password: abc123
ansible_user: user123
blue_server_password: def456
blue_server_user: user456
Run Code Online (Sandbox Code Playgroud)
通常,我会将变量写入文件,然后使用导入它vars_files:.我们的目标是不将秘密写入文件系统.
您可以使用uri模块进行调用,然后注册对变量的响应:
例如:
- uri:
url: http://www.mocky.io/v2/59667604110000040ec8f5c6
body_format: json
register: response
- debug:
msg: "{{response.json}}"
- set_fact: {"{{ item.key }}":"{{ item.val }}"}
with_dict: "{{response.json.ansible_facts.list_of_passwords}}"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3792 次 |
| 最近记录: |