I am writing an ansible script to deploy django in centos 7. My problem is with nginx.
I have created /etc/nginx/sites-available and /etc/nginx/sites-enabled directories and have to include sites-available in /etc/nginx/nginx.conf file at the bottom if http { } block.
How do I insert the line include /etc/nginx/sites-available/*.conf inside the http {} block in my ansible script after creating the respective directories and copying the configuration files?
The output should be
http {
.....
.....
server {
.......
}
include /etc/nginx/sites-available/*.conf;
}
You can use the lineinfile module. Something like this should work:
- lineinfile: dest=/etc/nginx/nginx.conf regexp="^include /etc/nginx/sites-available/*.conf;" insertbefore="server {" line="include /etc/nginx/sites-available/*.conf;"
This will insert the line before the server block. You can play around with insertbefore and insert after and different regular expressions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With