Tag: apache

Loops with lineinfile ansible module

Posted by – 12/02/2014

 

I just started playing with ansible recently. And I love it!

I am working on a playbook for configuring Apache 2.4 for a complex application. The plan to run the application on an IaaS cloud(ish) platform. We need to control the Apache worker settings via the playbook since there will be several “flavors” of cloud instances with different sizes and configurations. I was considering using a template for the configuration file. But since I am playing..Screen-Shot-2013-03-30-at-6.07.36-PM

I decided to take a shot at using the lineinfile module, which I find really cool! And to make this a bit more interesting, I wanted to this this using ansible loops, not one configuration item at a time.

So, basically, this is the first shot at getting this done, there is a lot of room for improvement:

– name: Setting Apache Prefork MPM
  lineinfile:
    dest=/etc/apache2/conf.d/mpm_prefork.conf
    regexp=”{{ item.key }}”
    line=”{{ item.value }}”
  with_items:
    – { key: “StartServers” , value: “StartServers {{ StartServers }}” }
    – { key: “MinSpareServers”, value: “MinSpareServers {{ MinSpareServers }}” }
    – { key: “MaxSpareServers”, value: “MaxSpareServers {{ MaxSpareServers }}” }
    – { key: “MaxClients”, value: “MaxClients {{ MaxClients }}” }
    – { key: “MaxRequestsPerChild”, value: “MaxRequestsPerChild {{ MaxRequestsPerChild }}”

Additionally, I added the values in the var file:

var:
  StartServers: 10
  MinSpareServers: 5
  MaxSpareServers: 10
  MaxClients: 300
  MaxRequestsPerChild: 0

This should do the trick!