win_dsc UrlAcl and passing int[]

I’m trying to integrate my existing DSC configuration into my Ansible setup. I’m using the UrlAcl module (https://www.powershellgallery.com/packages/HttpSys/1.0.1/Content/UrlAcls%5CUrlAcls.ps1) and its Port property is an int. This is what I’m trying:

  • name: UrlAcls - Http Wcf interface specific
    win_dsc:
    resource_name: UrlAcl
    Protocol: “http”
    HostName: “{{ ansible_hostname }}.domain.com”
    Port: [46000…46100]
    SecurityContext: “{{ ansible_hostname }}\UrlAclPermitted”

It’s telling me that it can’t convert from string to int.

How do I define the Port property as int?

You should be using a YAML list or a Python list like the below;

`
Port:

  • 46000
  • 46100

or

Port: [46000, 46100]

`

Thanks

Jordan

Thanks Jordan, but a explicitly written list is not really practical when you have a range 100 or 1000 in length.

{{ range(46000,46100) | list }}

Ahh sorry I thought you only wanted those numbers. The suggestion above should work.

Hi Kai

This:

Port: {{ range(43000,43200) | list }}

produces:
`
ERROR! Syntax Error while loading YAML.
found unacceptable key (unhashable type: ‘AnsibleMapping’)
The offending line appears to be:

HostName: “+”
Port: {{ range(43000,43200) | list }}
^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:

with_items:

  • {{ foo }}

Should be written as:

with_items:

  • “{{ foo }}”
    `

So I removed the interpolation:

Port: range(43000,43200) | list

which produces:

fatal: [dev21-sfapp12]: FAILED! => {"changed": false, "module_version": "1.0.1", "msg": "Convert property 'Port' value from type 'STRING[]' to type 'SINT32[]' failed\r\n At line:11, char:2\r\n Buffer:\r\n Protocol = \"http\";\n};^\n\ninsta\r\n", "reboot_required": false}

Any thoughts?

As the error message says you need to add quotes.
When a { comes after a colon you need to quote it with single or double quotes.

  Port: "{{ range(43000,43200) | list }}"

Sure, but then I’m passing a single string to an int array.

No you are not, the jinja2 block is evaluated before it’s passed to the module so the data will contain the array you are looking for. Did you try it out?

I thought so, but will try again to confirm.

You were right Jordan.

I have to say, I really dislike the use of quotes here. It is really not intuitive what data you are passing.

Thanks for everyone’s help.