0

I am writing ansible template and I want that the template will create ntp.conf while keeping the lines after the ip address with the same amount of space To keep the lines straight and nice, the ntp.conf should look like:

server 10.13.1.1 restrict 10.13.1.1 mask 255.255.255.255 nomodify notrap noquery server 10.13.21.91 restrict 10.13.21.91 mask 255.255.255.224 nomodify notrap noquery server 10.13.16.26 restrict 10.13.16.26 mask 255.255.255.224 nomodify notrap noquery 

As you see the lines starting with 'mask' are organized with the same spacing but with my existing code on the template it not getting be aligned

Here is my code on the template:

note: restrict='mask 255.255.255.224 nomodify notrap noquery' {% for ns in default_ntpservers %} server {{ ns }} restrict {{ ns }}{{ restrict | indent( width=2, indentfirst=True) }} {% endfor %} 

I am getting on the client:

server 10.13.1.1 restrict 10.13.1.1 mask 255.255.255.255 nomodify notrap noquery server 10.13.21.91 restrict 10.13.21.91 mask 255.255.255.224 nomodify notrap noquery server 10.13.16.26 restrict 10.13.16.26 mask 255.255.255.224 nomodify notrap noquery 

1 Answer 1

4

Use format filter for ns:

{{ '%-18s' | format(ns) }} 

You can find additional info about string padding with python format here.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.