How can I pass a hash to a role?

Hi folks,

I’m running a playbook that makes use of a few custom roles, and one of them would benefit from being able to receive a YAML hash containing an arbitrary number of items (think: passing in a set of environment variables that should be set while running an executable). However, I’m failing to figure out what the syntax for doing this might be. Here’s where I’m at right now:

`


---

- hosts: webservers

  roles:

  - { role: app,

      role_var_1: somevalue,

      role_var_2: someothervalue,

      canidothis:

        ENV_VAR_1: /some/path

        ENV_VAR_1: /some/other/path

    }

`

But that’s not valid YAML syntax, apparently.

I’d like to be able to:

  • Iterate over the list using the template module to emit key=value items from canidothis
  • Access canidothis.ENV_VAR_1 (or equivalent) in a task
    Am I missing some feature of YAML syntax that will let me accomplish this?

Thanks!

once you use shorthand mode you cannot regress to normal mode, this
should work (or doing all in yaml normal):

Thanks! This helped!