Sumit Sharma
Sumit Sharma

Reputation: 1

Ansible play is not able to take variable

C:\CYGWIN64\ETC\ANSIBLE\ANSIBLE-ACI-CONFIG
├───environments
│   ├───houston
│   └───munich
├───group_vars
├───plays
├───plugins
│   └───filter
│       └───__pycache__
└───roles
    ├───aci-fabric-onboarding
    │   └───tasks

variable file:

oob_nodes: 
   - { node_id: "101", obb_address: "10.10.10.10", obb_cidr: "27" , obb_gateway: "10.10.10.1" }
   - { node_id: "102", obb_address: "10.10.10.11", obb_cidr: "27" , obb_gateway: "10.10.10.1" }
   - { node_id: "201", obb_address: "10.10.10.12", obb_cidr: "27" , obb_gateway: "10.10.10.1" }
play
========

- name: Setup ACI Fabric
  hosts: "{{ target }}"
  gather_facts: no
  any_errors_fatal: true

  tasks:
    - include_vars:
        file: "{{ ACI_SSoT_path }}/fabricsetup.yml"
       

    - include_vars:
        file: "{{ ACI_SSoT_path }}/oob.yml"
    
    # Intent Statement
    - include_role:
        name: aci-fabric-onboarding
        
roles
==============

# Adding OBB address 
- name: Add OBB address 
  delegate_to: localhost
  aci_rest:
    host: "{{ aci_ip }}"
    username: ansible
    private_key: ansible.key
    certificate_name: ansible  
    use_ssl: yes
    validate_certs: false
    path: /api/node/mo/uni/tn-mgmt/mgmtp-default/oob-default/rsooBStNode-[topology/pod-1/node-"{{item.node_id}}"].json
    method: post
    content: 
            {
          "mgmtRsOoBStNode":{
              "attributes":{
                "tDn":"topology/pod-1/node-101",
                "addr":"25.96.131.61/27",
                "gw":"25.96.131.33",
                "status":"created"
              },
              "children":[
                
              ]
          }
        }
    with_items: "{{ oob_nodes }}"

error:

TASK [aci-fabric-onboarding : Add OBB address] *****************************************************************************************************************************************************
task path: /etc/ansible/Ansible-Aci-config/roles/aci-fabric-onboarding/tasks/apply-oob-config.yml:4
fatal: [25.96.131.30]: FAILED! => {
    "msg": "The task includes an option with an undefined variable. The error was: 'item' is undefined\n\nThe error appears to be in '/etc/ansible/Ansible-Aci-config/roles/aci-fabric-onboarding/tasks/apply-oob-config.yml': line 4, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n# Adding OBB address\n- name: Add OBB address\n  ^ here\n"
}

Upvotes: 0

Views: 103

Answers (1)

toydarian
toydarian

Reputation: 4554

That looks like an indention error to me. You have with_items with the same indention as aci_rest:

# Adding OBB address 
- name: Add OBB address 
  delegate_to: localhost
  aci_rest:
    host: "{{ aci_ip }}"
    username: ansible
    private_key: ansible.key
    certificate_name: ansible  
    use_ssl: yes
    validate_certs: false
    path: /api/node/mo/uni/tn-mgmt/mgmtp-default/oob-default/rsooBStNode-[topology/pod-1/node-"{{  item.node_id  }}"].json
    method: post
    content: 
            {
          "mgmtRsOoBStNode":{
              "attributes":{
                "tDn":"topology/pod-1/node-101",
                "addr":"25.96.131.61/27",
                "gw":"25.96.131.33",
                "status":"created"
              },
              "children":[
                
              ]
          }
        }
  with_items: "{{ oob_nodes }}"

Have a look at the documentation as well.

Upvotes: 1

Related Questions