Hello guys:

There's something I've been struggling with for some hours without knowing
exactly how to solve it.
Through AWX, I want users to enter the size of disks for a virtual machine
using a text area in a survey, like this:

100
20
130
230

When I assign this input to a variable, I see that ansible converts them to
a list, like this:

mydisks: |-
  100
  20
  130
  230

By using vmware_guest module, I'd like to convert it to something like...

vmware_guest:
  disk:
    - size_gb: 100
      type: None
    - size_gb: 20
      type: None
    - size_gb: 130
      type: None
    - size_gb: 230
      type: None

So I found some references on Internet that look like this jinja2
expressions:

vmware_guest:
  disk: >-
    [{% for size in mydisks.split() %}'{ size_gb: {{ size }}, type: None
}', {% endfor %}]

However, when I run the playbook I got an ugly error like this:

TASK [Create virtual machine]
********************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use
-vvv. The error was: AttributeError: 'str' object has no attribute 'get'
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr":
"Traceback (most recent call last):\n  File
\"/home/arengifo/.ansible/tmp/ansible-tmp-1561181905.46-145468152234880/AnsiballZ_vmware_guest.py\",
line 114, in <module>\n    _ansiballz_main()\n  File
\"/home/arengifo/.ansible/tmp/ansible-tmp-1561181905.46-145468152234880/AnsiballZ_vmware_guest.py\",
line 106, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path,
ANSIBALLZ_PARAMS)\n  File
\"/home/arengifo/.ansible/tmp/ansible-tmp-1561181905.46-145468152234880/AnsiballZ_vmware_guest.py\",
line 49, in invoke_module\n    imp.load_module('__main__', mod, module,
MOD_DESC)\n  File \"/tmp/ansible_vmware_guest_payload_iGarsa/__main__.py\",
line 2630, in <module>\n  File
\"/tmp/ansible_vmware_guest_payload_iGarsa/__main__.py\", line 2619, in
main\n  File \"/tmp/ansible_vmware_guest_payload_iGarsa/__main__.py\", line
2135, in deploy_vm\n  File
\"/tmp/ansible_vmware_guest_payload_iGarsa/__main__.py\", line 1811, in
configure_disks\nAttributeError: 'str' object has no attribute 'get'\n",
"module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the
exact error", "rc": 1}

Would someone, please, help me with this issue? I'm sure my jinja2
expression it's wrong, but I can figure out what's the right way to do it.

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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAA3McK_WPie0bMK%2B%3Dxmndy7kMFs2GxyfGn4CuhLTEBTpu6Sy1w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to