HELP using group_vars and roles

68 views
Skip to first unread message

Eric Marquez

unread,
Dec 16, 2016, 12:43:55 PM12/16/16
to ansible-project (ansible-project@googlegroups.com)
I have a question about the use of group_vars in Ansible. I would like to use the data dictionaries values from swtich.json, I also need it to be global set of values almost like all. When I call it in Ansible it becomes unknown... Is there a way to do it?

Ansible debug output:
TASK [basebmc : debug] *********************************************************
task path: /mnt/c/Users/emarq/Documents/Source/Repos/Solutions.Network.Automation/MAS/Ansible/hpe/roles/basebmc/tasks/main.yml:20
fatal: [b43-1u15-d00-5900AFbmc]: FAILED! => {
"failed": true,
"msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: dict object has no element 5900\n\nThe error appears to have been in '/mnt/c/Users/emarq/Documents/Source/Repos/Solutions.Network.Automation/MAS/Ansible/hpe/roles/basebmc/tasks/main.yml': line 20, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- debug:\n ^ here\n"
}



group_vars/
baseagg.yml basebmc.yml basetor.yml switch.json


Ansible.hosts:
[swtich:children]
basebmc
[basebmc]
bmcdevice1


Role baesbmc/tasks/main.yml:
- debug:
msg: "name: {{ inventory_hostname }} {{ portmap.HPE.5900.Port.46.Port }}"
verbosity: 4
with_dict: "{{ portmap }}"


playbook.yml
---
# Setup playbook to deploy a switch NTP settings using common
- name: BMC base config
hosts: basebmc
remote_user: admin
gather_facts: no
connection: local
roles:
- basebmc


switch.json
{
"portmap": {
"HPE": {
"5900": {
"DEVICETYPE": "BMC",
"Port": {
"46": {
"Type": "GigabitEthernet",
"Port": "1/0/46"
},
"management": {
"Type": "M_GigabitEthernet",
"Port": "0/0/0"
}
}
}
}
}
}


winmail.dat

Brian Coca

unread,
Dec 16, 2016, 2:07:11 PM12/16/16
to ansible...@googlegroups.com
try:
    msg: "name: {{ inventory_hostname }} {{ portmap['HPE']['5900']['Port']['46']['Port'] }}"


----------
Brian Coca

Eric Marquez

unread,
Dec 16, 2016, 2:19:29 PM12/16/16
to ansible...@googlegroups.com

I updated my msg to the following.

- debug:

    msg: "name: {{ inventory_hostname }} {{ portmap['HPE']['5900']['Port']['46']['Port'] }}"

    verbosity: 4

  with_dict: "{{ portmap }}"

 

 

TASK [basebmc : debug] *********************************************************

task path: /mnt/c/Users/emarq/Documents/Source/Repos/Solutions.Network.Automation/MAS/Ansible/hpe/roles/basebmc/tasks/main.yml:20

ok: [b43-1u15-d00-5900AFbmc] => (item={'key': u'HPE', 'value': {u'5900': {u'DEVICETYPE': u'BMC', u'Port': {u'45': {u'Type': u'GigabitEthernet', u'Port': u'1/0/45'}, u'42': {u'Type': u'GigabitEthernet', u'Port': u'1/0/42'}, u'48': {u'Type': u'GigabitEthernet', u'Port': u'1/0/48'}, u'43': {u'Type': u'GigabitEthernet', u'Port': u'1/0/43'}, u'36': {u'Type': u'GigabitEthernet', u'Port': u'1/0/36'}, u'35': {u'Type': u'GigabitEthernet', u'Port': u'1/0/35'}, u'32': {u'Type': u'GigabitEthernet', u'Port': u'1/0/32'}, u'04': {u'Type': u'GigabitEthernet', u'Port': u'1/0/4'}, u'24': {u'Type': u'GigabitEthernet', u'Port': u'1/0/24'}, u'25': {u'Type': u'GigabitEthernet', u'Port': u'1/0/25'}, u'26': {u'Type': u'GigabitEthernet', u'Port': u'1/0/26'}, u'management': {u'Type': u'M_GigabitEthernet', u'Port': u'0/0/0'}, u'20': {u'Type': u'GigabitEthernet', u'Port': u'1/0/20'}, u'21': {u'Type': u'GigabitEthernet', u'Port': u'1/0/21'}, u'22': {u'Type': u'GigabitEthernet', u'Port': u'1/0/22'}, u'23': {u'Type': u'GigabitEthernet', u'Port': u'1/0/23'}, u'46': {u'Type': u'GigabitEthernet', u'Port': u'1/0/46'}, u'47': {u'Type': u'GigabitEthernet', u'Port': u'1/0/47'}, u'44': {u'Type': u'GigabitEthernet', u'Port': u'1/0/44'}, u'09': {u'Type': u'GigabitEthernet', u'Port': u'1/0/9'}, u'28': {u'Type': u'GigabitEthernet', u'Port': u'1/0/28'}, u'29': {u'Type': u'GigabitEthernet', u'Port': u'1/0/29'}, u'40': {u'Type': u'GigabitEthernet', u'Port': u'1/0/40'}, u'41': {u'Type': u'GigabitEthernet', u'Port': u'1/0/41'}, u'27': {u'Type': u'GigabitEthernet', u'Port': u'1/0/27'}, u'05': {u'Type': u'GigabitEthernet', u'Port': u'1/0/5'}, u'02': {u'Type': u'GigabitEthernet', u'Port': u'1/0/2'}, u'03': {u'Type': u'GigabitEthernet', u'Port': u'1/0/3'}, u'39': {u'Type': u'GigabitEthernet', u'Port': u'1/0/39'}, u'34': {u'Type': u'GigabitEthernet', u'Port': u'1/0/34'}, u'01': {u'Type': u'GigabitEthernet', u'Port': u'1/0/1'}, u'30': {u'Type': u'GigabitEthernet', u'Port': u'1/0/30'}, u'06': {u'Type': u'GigabitEthernet', u'Port': u'1/0/6'}, u'38': {u'Type': u'GigabitEthernet', u'Port': u'1/0/38'}, u'07': {u'Type': u'GigabitEthernet', u'Port': u'1/0/7'}, u'11': {u'Type': u'GigabitEthernet', u'Port': u'1/0/11'}, u'10': {u'Type': u'GigabitEthernet', u'Port': u'1/0/10'}, u'13': {u'Type': u'GigabitEthernet', u'Port': u'1/0/13'}, u'12': {u'Type': u'GigabitEthernet', u'Port': u'1/0/12'}, u'15': {u'Type': u'GigabitEthernet', u'Port': u'1/0/15'}, u'14': {u'Type': u'GigabitEthernet', u'Port': u'1/0/14'}, u'17': {u'Type': u'GigabitEthernet', u'Port': u'1/0/17'}, u'16': {u'Type': u'GigabitEthernet', u'Port': u'1/0/16'}, u'19': {u'Type': u'GigabitEthernet', u'Port': u'1/0/19'}, u'18': {u'Type': u'GigabitEthernet', u'Port': u'1/0/18'}, u'31': {u'Type': u'GigabitEthernet', u'Port': u'1/0/31'}, u'49': {u'Type': u'Ten_GigabitEthernet', u'Port': u'1/0/49'}, u'51': {u'Type': u'Ten_GigabitEthernet', u'Port': u'1/0/51'}, u'50': {u'Type': u'Ten_GigabitEthernet', u'Port': u'1/0/50'}, u'53': {u'Type': u'FortyGigE', u'Port': u'1/0/53'}, u'52': {u'Type': u'Ten_GigabitEthernet', u'Port': u'1/0/52'}, u'33': {u'Type': u'GigabitEthernet', u'Port': u'1/0/33'}, u'37': {u'Type': u'GigabitEthernet', u'Port': u'1/0/37'}, u'54': {u'Type': u'FortyGigE', u'Port': u'1/0/54'}, u'08': {u'Type': u'GigabitEthernet', u'Port': u'1/0/8'}}}}}) => {

    "invocation": {

        "module_args": {

            "msg": "name: b43-1u15-d00-5900AFbmc 1/0/46",

            "verbosity": 4

        },

        "module_name": "debug"

    },

    "item": {

        "key": "HPE",

        "value": {

            "5900": {

                "DEVICETYPE": "BMC",

                "Port": {

                    "01": {

                        "Port": "1/0/1",

                        "Type": "GigabitEthernet"

                    },

                    "02": {

                        "Port": "1/0/2",

                        "Type": "GigabitEthernet"

                    },

                    "03": {

                        "Port": "1/0/3",

                        "Type": "GigabitEthernet"

                    },

                    "04": {

                        "Port": "1/0/4",

                        "Type": "GigabitEthernet"

                    },

                    "05": {

                        "Port": "1/0/5",

                        "Type": "GigabitEthernet"

                    },

                    "06": {

                        "Port": "1/0/6",

                        "Type": "GigabitEthernet"

                    },

                    "07": {

                        "Port": "1/0/7",

                        "Type": "GigabitEthernet"

                    },

                    "08": {

                        "Port": "1/0/8",

                        "Type": "GigabitEthernet"

                    },

                    "09": {

                        "Port": "1/0/9",

                        "Type": "GigabitEthernet"

                    },

                    "10": {

                        "Port": "1/0/10",

                        "Type": "GigabitEthernet"

                    },

                    "11": {

                        "Port": "1/0/11",

                        "Type": "GigabitEthernet"

                    },

                    "12": {

                        "Port": "1/0/12",

                        "Type": "GigabitEthernet"

                    },

                    "13": {

                        "Port": "1/0/13",

                        "Type": "GigabitEthernet"

                    },

                    "14": {

                        "Port": "1/0/14",

                        "Type": "GigabitEthernet"

                    },

                    "15": {

                        "Port": "1/0/15",

                        "Type": "GigabitEthernet"

                    },

                    "16": {

                        "Port": "1/0/16",

                        "Type": "GigabitEthernet"

                    },

                    "17": {

                        "Port": "1/0/17",

                        "Type": "GigabitEthernet"

                    },

                    "18": {

                        "Port": "1/0/18",

                        "Type": "GigabitEthernet"

                    },

                    "19": {

                        "Port": "1/0/19",

                        "Type": "GigabitEthernet"

                    },

                    "20": {

                        "Port": "1/0/20",

                        "Type": "GigabitEthernet"

                    },

                    "21": {

                        "Port": "1/0/21",

                        "Type": "GigabitEthernet"

                    },

                    "22": {

                        "Port": "1/0/22",

                        "Type": "GigabitEthernet"

                    },

                    "23": {

                        "Port": "1/0/23",

                        "Type": "GigabitEthernet"

                    },

                    "24": {

                        "Port": "1/0/24",

                        "Type": "GigabitEthernet"

                    },

                    "25": {

                        "Port": "1/0/25",

                        "Type": "GigabitEthernet"

                    },

                    "26": {

                        "Port": "1/0/26",

                        "Type": "GigabitEthernet"

                    },

                    "27": {

                        "Port": "1/0/27",

                        "Type": "GigabitEthernet"

                    },

                    "28": {

                        "Port": "1/0/28",

                        "Type": "GigabitEthernet"

                    },

                    "29": {

                        "Port": "1/0/29",

                        "Type": "GigabitEthernet"

                    },

                    "30": {

                        "Port": "1/0/30",

                        "Type": "GigabitEthernet"

                    },

                    "31": {

                        "Port": "1/0/31",

                        "Type": "GigabitEthernet"

                    },

                    "32": {

                        "Port": "1/0/32",

                        "Type": "GigabitEthernet"

                    },

                    "33": {

                        "Port": "1/0/33",

                        "Type": "GigabitEthernet"

                    },

                    "34": {

                        "Port": "1/0/34",

                        "Type": "GigabitEthernet"

                    },

                    "35": {

                        "Port": "1/0/35",

                        "Type": "GigabitEthernet"

                    },

                    "36": {

                        "Port": "1/0/36",

                        "Type": "GigabitEthernet"

                    },

                    "37": {

                        "Port": "1/0/37",

                        "Type": "GigabitEthernet"

                    },

                    "38": {

                        "Port": "1/0/38",

                        "Type": "GigabitEthernet"

                    },

                    "39": {

                        "Port": "1/0/39",

                        "Type": "GigabitEthernet"

                    },

                    "40": {

                        "Port": "1/0/40",

                        "Type": "GigabitEthernet"

                    },

                    "41": {

                        "Port": "1/0/41",

                        "Type": "GigabitEthernet"

                    },

                    "42": {

                        "Port": "1/0/42",

                        "Type": "GigabitEthernet"

                    },

                    "43": {

                        "Port": "1/0/43",

                        "Type": "GigabitEthernet"

                    },

                    "44": {

                        "Port": "1/0/44",

                        "Type": "GigabitEthernet"

                    },

                    "45": {

                        "Port": "1/0/45",

                        "Type": "GigabitEthernet"

                    },

                    "46": {

                        "Port": "1/0/46",

                        "Type": "GigabitEthernet"

                    },

                    "47": {

                        "Port": "1/0/47",

                        "Type": "GigabitEthernet"

                    },

                    "48": {

                        "Port": "1/0/48",

                        "Type": "GigabitEthernet"

                    },

                    "49": {

                        "Port": "1/0/49",

                        "Type": "Ten_GigabitEthernet"

                    },

                    "50": {

                        "Port": "1/0/50",

                        "Type": "Ten_GigabitEthernet"

                    },

                    "51": {

                        "Port": "1/0/51",

                        "Type": "Ten_GigabitEthernet"

                    },

                    "52": {

                        "Port": "1/0/52",

                        "Type": "Ten_GigabitEthernet"

                    },

                    "53": {

                        "Port": "1/0/53",

                        "Type": "FortyGigE"

                    },

                    "54": {

                        "Port": "1/0/54",

                        "Type": "FortyGigE"

                    },

                    "management": {

                        "Port": "0/0/0",

                        "Type": "M_GigabitEthernet"

                    }

                }

            }

        }

    },

    "msg": "name: b43-1u15-d00-5900AFbmc 1/0/46"

}

 

TASK [basebmc : set access ports] **********************************************

task path: /mnt/c/Users/emarq/Documents/Source/Repos/Solutions.Network.Automation/MAS/Ansible/hpe/roles/basebmc/tasks/main.yml:25

fatal: [b43-1u15-d00-5900AFbmc]: FAILED! => {

    "failed": true,

    "msg": "{u'SwitchMgmt': {u'VLAN': 5, u'TYPE': u'{{ portmap.HPE.5900.Port.46.Type }}', u'PORT': [u'{{ portmap.HPE.5900.Port.46.Port }}', u'{{ portmap.HPE.5900.Port.47.Port }}', u'{{ portmap.HPE.5900.Port.48.Port }}'], u'SHUTDOWN': False, u'DESC': u'SwitchMgmt'}}: dict object has no element 5900"

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CACVha7cX5XG5CGeyRGqPnAdJ_sq8qQzQcBw_ofwio1Cqps7xww%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Brian Coca

unread,
Dec 16, 2016, 2:36:58 PM12/16/16
to ansible...@googlegroups.com
Your output does not seem to match what you are saying: `{{ portmap.HPE.5900.Port.46.Type }}`


​btw, you can remove the useless with_dict entry to get cleaner output

----------
Brian Coca

Eric Marquez

unread,
Dec 16, 2016, 4:14:06 PM12/16/16
to ansible...@googlegroups.com

This is very odd, when I replace 5900 with FOO, it works.  What’s special about the number 5900?

 

TASK [basebmc : debug] *********************************************************

task path: /mnt/c/Users/emarq/Documents/Source/Repos/Solutions.Network.Automation/MAS/Ansible/hpe/roles/basebmc/tasks/main.yml:20

ok: [b43-1u15-d00-5900AFbmc] => {

    "msg": "name:portmap[HPE][FOO][Port][46][Port]: 1/0/46"

Brian Coca

unread,
Dec 16, 2016, 4:24:43 PM12/16/16
to ansible...@googlegroups.com
string vs number

x[21] is not the same as x['21']

​I avoid using numbers as dictionary keys due to similar issues.​

----------
Brian Coca

Eric Marquez

unread,
Dec 16, 2016, 5:08:41 PM12/16/16
to ansible...@googlegroups.com

That was it.  Thanks for the help. 

 

From: ansible...@googlegroups.com [mailto:ansible...@googlegroups.com] On Behalf Of Brian Coca
Sent: Friday, December 16, 2016 1:25 PM
To: ansible...@googlegroups.com
Subject: Re: [ansible-project] HELP using group_vars and roles

 

string vs number

--

You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages