How can I pass a hash to a role?

75 views
Skip to first unread message

Collin Allen

unread,
Jan 21, 2015, 6:56:17 PM1/21/15
to ansible...@googlegroups.com
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!

Brian Coca

unread,
Jan 21, 2015, 7:14:54 PM1/21/15
to ansible...@googlegroups.com
once you use shorthand mode you cannot regress to normal mode, this
should work (or doing all in yaml normal):

---
- 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}
}


--
Brian Coca

Collin Allen

unread,
Jan 22, 2015, 2:19:32 PM1/22/15
to ansible...@googlegroups.com
Thanks! This helped!
Reply all
Reply to author
Forward
0 new messages