【发布时间】:2019-05-11 15:15:49
【问题描述】:
我正在尝试为接口变量动态提供字典名称。
我的 ansible 任务如下所示。
- name: Setting interface list
set_fact:
one_fact: "{{ host_name }}_interfaces"
- name: deb
debug: var={{ one_fact }}
- name: Managing Interfaces
ios_interface:
enabled: "{{ item['value']['enabled'] }}"
name: "{{ item['key'] }}"
state: "{{ item['value']['state'] }}"
with_dict: "{{ one_fact }}"
字典看起来像这样
---
h1_interfaces:
Ethernet1/1:
description: Firewall
enabled: true
speed: auto
state: present
Ethernet1/2:
description: asd
enabled: true
speed: auto
state: present
h2_interfaces:
Ethernet1/1:
description: Firewall
enabled: true
speed: auto
state: present
Ethernet1/2:
description: asd
enabled: true
speed: auto
state: present
当我设置with_dict: {{ one_fact }} 时,我得到一个错误FAILED! => {"msg": "with_dict expects a dict"}
但是当我提供with_dict: {{ h1_interfaces }} 时,它就像一个魅力。我做错了什么?
【问题讨论】:
-
我真的不明白你想要完成什么......
with_dict确实在期待一个字典,但one_fact被初始化为一个字符串。您能否详细说明您的预期结果是什么?
标签: dictionary variables ansible