You still need to specify the value as a complex arg:

   - name: Verify OSPF Information
     nxapi_ospf:
       host: "{{ inventory_hostname }}"
       user: "admin"
       passwd: "cisco.com"
       neighborInfo: "{{item.value}}"
     register: insieme.ospf
     with_dict: insieme.topo




On Wed, Jun 11, 2014 at 2:36 AM, Matt O <mier...@gmail.com> wrote:

> I have a play that uses a module that I created. I'm not having trouble
> with this play or this module - it's with feeding this module's output into
> another module.
>
> ---
> - name: Build topology
>   hosts: spine
>   connection: local
>   gather_facts: no
>
>
>   tasks:
>     - name: Download CDP info from spines
>       nxapi_topo_build:
>           host={{ inventory_hostname }}
>           user="admin"
>           passwd="cisco"
>       register: insieme
>     - name: Show neighbors
>       debug: msg={{ item.value }}
>       with_dict: insieme.topo
>
> As you can see, I'm writing a dictionary to insieme.topo, and calling it
> in a debug task. That ouput is below:
>
> ~ ansible-playbook playbooks/gettopo.yml
>
>
> PLAY [Build topology]
> *********************************************************
>
>
> TASK: [Download CDP info from spines]
> *****************************************
> ok: [10.2.1.8]
> ok: [10.2.1.9]
>
>
> TASK: [Show neighbors]
> ********************************************************
> ok: [10.2.1.9] => (item={'value': {u'local_if': u'Po100', u'mgmt_ipv4': u
> '192.168.1.123', u'remote_if': u'Po200'}, 'key': u'VDH=SAL1814PHJF'}) => {
>     "item": {
>         "key": "VDH=SAL1814PHJF",
>         "value": {
>             "local_if": "Po100",
>             "mgmt_ipv4": "192.168.1.123",
>             "remote_if": "Po200"
>         }
>     },
>     "msg": "{ulocal_if:"
> }
> ok: [10.2.1.8] => (item={'value': {u'local_if': u'Po100', u'mgmt_ipv4': u
> '192.168.1.123', u'remote_if': u'Po100'}, 'key': u'VDH=SAL1814PHJF'}) => {
>     "item": {
>         "key": "VDH=SAL1814PHJF",
>         "value": {
>             "local_if": "Po100",
>             "mgmt_ipv4": "192.168.1.123",
>             "remote_if": "Po100"
>         }
>     },
>     "msg": "{ulocal_if:"
> }
>
> That debug is straight out of the variable I'm registering to -
> insieme.topo. What I'd like to do is turn around and feed that dictionary
> into an argument for another module.
>
> I was directed here for info on passing complex args to a custom module:
>
>
> https://github.com/ansible/ansible-examples/blob/master/language_features/complex_args.yml
>
> I have added the "type='dict'" option to this second module - called
> "nxapi_ospf", as shown below:
>
> def main():
>     module = AnsibleModule(
>         argument_spec=dict( \
>             host=dict(required=True), \
>             user=dict(required=False, default='admin'), \
>             passwd=dict(required=False, default=None), \
>             neighborInfo=dict(type='dict',required=True, default=None), \
>             logfile=dict(required=False, default=None)), \
>         supports_check_mode=False)
>
> So I write a play to use this module and feed insieme.topo as an argument
> into neighborInfo:
>
> - name: Verify OSPF
>   hosts: spine
>   connection: local
>   gather_facts: no
>
>   tasks:
>     - name: Verify OSPF Information
>       nxapi_ospf:
>         host={{ inventory_hostname }}
>         user="admin"
>         passwd="cisco.com"
>         neighborInfo={{ item.value }}
>       register: insieme.ospf
>       with_dict: insieme.topo
>
> However, I'm still getting "this module requires key=value arguments"
> messages.
>
> PLAY [Verify OSPF]
> ************************************************************
>
>
> TASK: [Verify OSPF Information]
> ***********************************************
> failed: [10.2.1.8] => (item={'value': {u'local_if': u'Po100', u'mgmt_ipv4'
> : u'192.168.1.123', u'remote_if': u'Po100'}, 'key': u'VDH=aaaaaa'}) => {
> "failed": true, "item": {"key": "VDH=aaaaa", "value": {"local_if": "Po100"
> , "mgmt_ipv4": "192.168.1.123", "remote_if": "Po100"}}}
> failed: [10.2.1.9] => (item={'value': {u'local_if': u'Po100', u'mgmt_ipv4'
> : u'192.168.1.123', u'remote_if': u'Po200'}, 'key': u'VDH=aaaaaa'}) => {
> "failed": true, "item": {"key": "VDH=aaaaa", "value": {"local_if": "Po100"
> , "mgmt_ipv4": "192.168.1.123", "remote_if": "Po200"}}}
> msg: this module requires key=value arguments (['host=10.2.1.8',
> 'user=admin', 'passwd=cisco', 'neighborInfo={ulocal_if:', 'uPo100,',
> 'umgmt_ipv4:', 'u192.168.1.123,', 'uremote_if:', 'uPo100}'])
> msg: this module requires key=value arguments (['host=10.2.1.9',
> 'user=admin', 'passwd=cisco', 'neighborInfo={ulocal_if:', 'uPo100,',
> 'umgmt_ipv4:', 'u192.168.1.123,', 'uremote_if:', 'uPo200}'])
>
>
> FATAL: all hosts have already failed -- aborting
>
>
> PLAY RECAP
> ********************************************************************
>            to retry, use: --limit @/Users/mierdin/gettopo.retry
>
>
> 10.2.1.8                   : ok=2    changed=0    unreachable=0    failed=
> 1
> 10.2.1.9                   : ok=2    changed=0    unreachable=0    failed=
> 1
>
> I'm sure I'm just not passing the argument correctly for some reason, but
> all of the documentation I've seen for using dictionaries as complex
> arguments for modules involves defining them in the YAML directly. Instead,
> I'd like to be able to use a dictionary that is stored as a register by
> another module, as I've shown.
>
> Is this possible today? Thanks in advance.
>
>  --
> 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-project+unsubscr...@googlegroups.com.
> To post to this group, send email to ansible-project@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/24b75d94-3eec-4be9-a795-52e37a8b70f6%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/24b75d94-3eec-4be9-a795-52e37a8b70f6%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAMFyvFgvYhZuK7v_yz0zh8o%2Bu9-DQz9kZW6Vw39hwb0L9NqWAQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to