Using variables for module parameter names.

16 views
Skip to first unread message

David Blackburn

unread,
Mar 9, 2016, 4:15:01 PM3/9/16
to Ansible Project
I am trying to build a configuration file of default services, the service command doesn't seem read the variables until the section is executed so I have to prefix the variables with enable/state etc.  Is this expected and are there any ways around this?

Thanks
Dave 

---
services:
    default:
     ntpd: enabled=yes


-   name: Default services
#    debug: msg="name={{ item.key }} {{ item.value }}"
    service: name={{ item.key }} {{ item.value }}
    with_dict: "{{ services.default }}"


TASK [services : Default services] *********************************************
failed: [localhost] => (item={'value': u'enabled=yes', 'key': u'ntpd'}) => {"failed": true, "item": {"key": "ntpd", "value": "enabled=yes"}, "msg": "Neither 'state' nor 'enabled' set"}


When using debug it produces the expected results.

TASK [services : Default services] *********************************************
ok: [localhost] => (item={'value': u'enabled=yes', 'key': u'ntpd'}) => {
    "item": {
        "key": "ntpd",
        "value": "enabled=yes"
    },
    "msg": "name=ntpd enabled=yes"
}
Reply all
Reply to author
Forward
0 new messages