【发布时间】:2015-03-12 23:02:32
【问题描述】:
我正在尝试创建一个 Ansible 配置,该配置将运行一个剧本并利用单个变量文件来创建具有多个项目的单个配置。我正在尝试以下语法,但它失败了。我该如何解决这个问题?
vars/main.yml
---
or1host1:
- interface: 1/1
description: or1-servertest
TRUNK: true
allowedVlans: 101-103
NVLAN: true
nativeVLAN: 101
ACCESS: false
accessVlan: none
PC: true
pcNUM: 10
- interface: 1/2
description: or1-servertest2
TRUNK: false
allowedVlans: 101-103
NVLAN: false
nativeVLAN: 101
ACCESS: true
accessVlan: none
PC: true
pcNUM: 10
模板/nxos.j2
{% for interface in or1host1 %}
interface Ethernet{{item.interface}}
description {{item.description}}
{% if item.TRUNK %}
switchport mode trunk
switchport trunk allowed vlan {{item.allowedVlans}}
spanning-tree port type edge trunk
{% if item.NVLAN %}
switchport trunk native vlan {{item.nativeVLAN}}
{% endif %}
{% endif %}
{% if item.ACCESS %}
switchport mode access
switchport access vlan {{item.accessVlan}}
spanning-tree port type edge
{% endif %}
{% if item.PC %}
channel-group {{item.pcNUM}} mode active
{% endif %}
no shut
{% endfor %}
我在运行 playbook 时收到以下错误。
PLAY [Generate Configuration Files] *******************************************
GATHERING FACTS ***************************************************************
ok: [localhost]
TASK: [nxos | Generate configuration files] ***********************************
fatal: [localhost] => {'msg': "AnsibleUndefinedVariable: One or more undefined variables: 'str object' has no attribute 'interface'", 'failed': True}
fatal: [localhost] => {'msg': 'One or more items failed.', 'failed': True, 'changed': False, 'results': [{'msg': "AnsibleUndefinedVariable: One or more undefined variables: 'str object' has no attribute 'interface'", 'failed': True}]}
FATAL: all hosts have already failed -- aborting
PLAY RECAP ********************************************************************
to retry, use: --limit @/home/gituser/site.retry
localhost : ok=1 changed=0 unreachable=1 failed=
0
【问题讨论】:
-
你遇到了什么样的错误?
-
我编辑了我的原始问题以考虑到下面提到的一些更改,并包含以下错误。
标签: python networking yaml ansible ansible-playbook