• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Ansible split string into n number of variable

Resolved: Ansible split string into n number of variable

0
By Isaac Tonny on 16/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I have to update a config file with server IPs from a cluster. The cluster contains minimum 2 servers, however, the maximum number of servers in the cluster is unknown. I want to collect the IPs as a delimited list IP1|IP2|IPn and split them into separate variables. The below snippet is working fine with two variables.
Questions:
  1. How can I split a collected string into separate variables?
  2. How can I generalize the above insert to n number of IPs?

Answer:

With a list of comma delimited IP addresses (YAML) such as:
You can use the Python split method in your Jinja2 templating to obtain a list:
And template it out with the join Jinja2 filter:
The join filter takes 1 argument, which is the character to delimit each item in the list in the output of the template.
Line output:

If you have better answer, please add a comment about this, thank you!

ansible
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: net::ERR_HTTP2_PROTOCOL_ERROR by http get request angular 15.2

02/04/2023

Resolved: How do I stop the command from happening if the requirements for it to work aren’t sert Discord.js

02/04/2023

Resolved: How to scroll bottom of div at launch?

02/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.