Re: [ansible-project] Dictionary parameters to custom modules

437 views
Skip to first unread message

Michael DeHaan

unread,
Dec 17, 2012, 7:14:54 PM12/17/12
to ansible...@googlegroups.com
It is true that modules can generally only take key=value arguments.

What is the nature of the module you are writing? I am generally not
in favor of the idea of modules needing to read a config file and do
not want that to become common, but it may serve as a workaround in
your case.

On Mon, Dec 17, 2012 at 6:20 PM, Oren Shomron <sho...@gmail.com> wrote:
> Hi,
>
> I have a case where I would like to pass a dictionary to a custom module I
> am writing.
> This is something that works find when passing to the template module, but
> not to a custom module,
> where _load_parameters seems to die with: "this module requires key=value
> arguments" if I nest everything under a node,
>
> or this:
>
> fatal: [db-master] => Traceback (most recent call last):
> File "/usr/lib/pymodules/python2.7/ansible/runner/__init__.py", line 236,
> in _executor
> exec_rc = self._executor_internal(host)
> File "/usr/lib/pymodules/python2.7/ansible/runner/__init__.py", line 292,
> in _executor_internal
> return self._executor_internal_inner(host, self.module_name,
> self.module_args, inject, port)
> File "/usr/lib/pymodules/python2.7/ansible/runner/__init__.py", line 340,
> in _executor_internal_inner
> module_args = utils.template(self.basedir, module_args, inject,
> expand_lists=True)
> File "/usr/lib/pymodules/python2.7/ansible/utils/template.py", line 240,
> in template
> text = varReplace(basedir, unicode(text), vars,
> expand_lists=expand_lists)
> File "/usr/lib/pymodules/python2.7/ansible/utils/template.py", line 196,
> in varReplace
> replacement = ",".join(replacement)
> TypeError: sequence item 0: expected string, dict found
>
> if I have a list of dictionaries directly.
>
> Is this something that should be possible?
>
> Thanks again,
> - Oren
>
> --
>
>

Oren Shomron

unread,
Dec 18, 2012, 11:49:55 AM12/18/12
to ansible...@googlegroups.com
I was trying to write a module to preseed configuration settings for debconf. I was hoping to get away with simple key=value, but each key in debconf has a type as well.

I saw that if I don't inherit any of the AnsibleModule code, I can go straight to the parameters file and parse the json myself, but it is a bit of a hassle.

Otherwise, like you said, I need to use template to create a preseed file, and then feed that into debconf as a separate step.

Michael DeHaan

unread,
Dec 18, 2012, 8:43:57 PM12/18/12
to ansible...@googlegroups.com
Yeah I debated JSON parameters to modules at one point, but decided
against. The idea of having structured parameters in the YAML made
it somewhat verbose.

You're correct on the raw string hack, at least for now.
> --
>
>
Reply all
Reply to author
Forward
0 new messages