Aidvi
Aidvi

Reputation: 27

Setting apache2.conf variables with Ansible problem

i have a simple ansible playbook that sets two ini variables.

- name: set Apache timeout
  community.general.ini_file:
    path: /etc/apache2/apache2.conf
    section: null
    option: Timeout
    value: 900
    state: present
    exclusive: true

- name: set Proxy timeout
  community.general.ini_file:
    path: /etc/apache2/apache2.conf
    section: null
    option: ProxyTimeout
    value: 900
    state: present
    exclusive: true

Problem is that it sets them like

Timeout = 900
ProxyTimeout = 900

But i need them to be set like, WITHOUT "="

Timeout 900
ProxyTimeout 900

EDIT This fixed it.

- name: set Timeout
  ansible.builtin.lineinfile:
    path: /etc/apache2/apache2.conf
    regexp: '^Timeout '
    insertafter: '^#Timeout '
    line: Timeout 900

- name: set Proxy timeout
  ansible.builtin.lineinfile:
    path: /etc/apache2/apache2.conf
    regexp: '^ProxyTimeout '
    insertafter: '^Timeout '
    line: ProxyTimeout 900

Upvotes: 0

Views: 226

Answers (1)

Knell
Knell

Reputation: 36

As far as I know, this file is not following an INI structure. Therefore, the "ini_file" module might be the wrong one.

Personally, I'd recommend using the "lineinfile" module with regex.

(Copied this example from the module page - use the link above for additional information)

- name: Ensure the default Apache port is 8080
  ansible.builtin.lineinfile:
    path: /etc/httpd/conf/httpd.conf
    regexp: '^Listen '
    insertafter: '^#Listen '
    line: Listen 8080

Upvotes: 2

Related Questions