Ansible host group variables

I created a host group variable for ntp role downloaded from Galaxy to add ntp servers to ntp.conf file.

The readme for the ntp roles shows the list of ntp servers in an array so I create the host group variable as such: Name ntp_config_servers Value [ ‘0.us.pool.ntp.org’, ‘1.us.pool.ntp.org’ ]

The entry added to ntp.conf was as below.
server [
server
server ’
server 0
server .
server u
server s
server .
server p
server o
server o
server l
server .
server n
server t
server p
server .
server o
server r
server g
server ’
server ,
server
server ’
server 1
server .
server u
server s
server .
server p
server o
server o
server l
server .
server n
server t
server p
server .
server o
server r
server g
server ’
server
server ]

Should I not be using an array format? I tried a yaml format and still had same issue.

below is the is the relevant entry in the ntp.conf.j2 file

{% for server in ntp_config_server %}
server {{ server }}
{% endfor %}

using centos 7.5 and Foreman 1.18.

Unfortunately those kinds of parameters can’t be anything but strings, and iterating on a string like that results in “server” being each character.

This is a long standing request in Foreman tracked by https://projects.theforeman.org/issues/4127. Only recently someone opened a pull request with this feature.

In the interim, you might consider altering the ntp role and changing it to handle a comma-separated string, for example.

Hi stbenjam,

Thank you for you quick reply. I was not aware of the limitation I will try your suggestion to modify the ntp role to use a string instead of array.

Fab

resolved:

Changed:
{% for server in ntp_config_server %}
server {{ server }}
{% endfor %}

to:

{% for server in ntp_config_server.split(’,’) %}
server {{ server }} {% if not loop.last %}
{% endif %}
{% endfor %}