I have a simple jinja file called test.cinf.j2 as below.
#SELF_IP is the IP of the node where this file resides.
SELF_IP={{ INTERNAL_IP }}
#IP of Node 1
NODE_1_IP={{ NODE_1_IP }}
#IP of Node 2
NODE_2_IP={{ NODE_2_IP }}
#IP of Node 3
NODE_3_IP={{ NODE_3_IP }}
#IP of Node 3
NODE_4_IP={{ NODE_4_IP }}
EOF
And I have a simple playbook that uses above template as below:
- name: Substitute values
template:
src: test.cinf.j2
dest: /etc/etcd
mode: 0777
And I need to set the variables INTERNAL_IP, NODE_1_IP, NODE_2_IP, NODE_3_IP and NODE_4_IP, but these should be assigned from values taken from a file called values.txt
values.txt contains the values as below:
192.168.1.1
192.168.1.2
192.168.1.3
192.168.1.4
192.168.1.6
How can I get each line value from the above file and pass them to the jinja template?
I haven't done like this before, so is there a better way of doing this?