I am using the inventory script from below and I am pretty impressed with its simplicity and functionality.
I am trying to use a playbook for NTP configuration which expects an array “ntp_servers”.
When I define the variable in the playbook as [192.168.1.1] it works fine. If I try to pass the context var “ntp_servers” to the playbook the value is not interpreted as array.
I get a chrony.conf like this
server [ iburst
server " iburst
server 1 iburst
server 9 iburst
server 2 iburst
server . iburst
server 1 iburst
server 6 iburst
server 8 iburst
server . iburst
server 1 iburst
server . iburst
server 1 iburst
server " iburst
server ] iburst
Any help howto to pass the value in the correct way would be very much appreciated.
thanks. I finally had the chance to try your implementation. It is always good to have a choice.
I get a slightly better result, but still not the expected one.
When defining the ntp_servers = [192.168.1.1,ntp.company.loc] as context variable I end up with an ntp.conf only including the second value from the array:
server ntp.company.loc iburst
Expected result would be:
server 192.168.1.1 iburst
server ntp.company.loc iburst
When I define
ntp_servers: [192.168.1.1, ntp.pupisoft.loc]
within the ansible play I get the expected result.
Do you have an idea how to pass an array/list from OpenNebula to Ansible?
Hello, my implementation works with VM Lables. So you have to “tag” your two running VMs with label “ntp-servers”. My one-inv script will return array like this
When I understand it correctly, you have to define custom context vars and want on provisioned VM to configure right ntp servers. In that case, you should extend context scripts https://github.com/OpenNebula/addon-context-linux.
Another way is to extend my script (I can do that). My script also returns meta data “host vars” which reads from USER_TEMPLATE and ansible have access to that vars. So we can extend host vars generation to parse som einput as array. Also we can parse TEMPLATE/CONTEXT, it depends what you need and if is possible for you to use USER_TEMPATE instead of CONTEXT one
The NTP Server is just one use case where I want to use an array of values and pass it to ansible.
My plan is to use a TEMPLATE/CONTEXT variable, e.g.:
CONTEXT = [
NTP_SERVERS = “[192.168.1.1, ntp.company.loc]”,
…
…
“So we can extend host vars generation to parse som einput as array.”
-> I think this is exactly what is missing!