在使用Ansible管理ACI时,如果要使用变量,请确保变量值不包含任何特殊字符,如逗号、冒号、反斜杠等。否则,您将会得到以下错误信息:
An unhandled exception occurred while running the lookup plugin 'aci_rest'
Error was a , BaseResponse({'totalCount': '1', 'imdata': [{'error': {'attributes': {'code': '400', 'text': 'Bad Request: Incorrect JSON format'}}}]})`
以下是在ACI上使用Ansible时避免此错误的示例代码:
vars:
tenant_name: my_tenant
contract_name: my_contract
filter_name: my_filter
filter_entries:
- { name: 'entry1', ether_type: 'ipv4', action: 'deny', arp_opcode: 'unspecified', dest_from: '', dest_to: '', source_from: '', source_to: '', dport_from: '', dport_to: '', sport_from: '', sport_to: ''}
tasks:
- name: Create Tenant
aci_rest:
host: "{{ aci_host }}"
username: "{{ aci_username }}"
password: "{{ aci_password }}"
method: post
path: /api/mo/uni.json
content: "{{ lookup('template', 'aci/create_tenant.j2') }}"
register: tenant_result
- name: Create Contract
aci_rest:
host: "{{ aci_host }}"
username: "{{ aci_username }}"
password: "{{ aci_password }}"
method: post
path: /api/mo/uni.json
content: "{{ lookup('template', 'aci/create_contract.j2') }}"
register: contract_result
- name: Create Filter Entries
aci_rest:
host: "{{ aci_host }}"
username: "{{ aci_username }}"
password: "{{ aci_password }}"
method: post
path: /api/mo/uni.json
content: "{{ lookup('template', 'aci/create_filter_entries.j2') }}"
register: filter_entries_result
在这个