Fiche modules lineinfile: blockinfile: replace: #01-07-2021 20:50
---

- name: Replace Apache DocumentRoot default
  lineinfile:
    path: /etc/apache2/sites-enabled/000-default.conf
    regexp: 'DocumentRoot'
    line: 'DocumentRoot /var/www/monsite'
  notify:
    - restart_apache

- name: Configure clamscan_daily admin_contact
  lineinfile:
    dest: /etc/cron.daily/clamscan_daily
    regexp: "^EMAIL_TO=.*$"
    line: EMAIL_TO="{{ admin_contact }}";
    state: present
    # Backrefs yes will replace the line only if it is find regexp line
    # and so do not add a new line !
    backrefs: yes

- name: blowfish phpmyadmin
  lineinfile:
    path: "/var/www/phpmyadmin/config.inc.php"
    regexp: "^\\$cfg\\['blowfish_secret'\\] =.*"
    line: "$cfg['blowfish_secret'] = '{{ blowfish_md5 }}';"

- name: Configure php 7.4 ini
  lineinfile:
    path: /etc/php/7.4/fpm/php.ini
    regexp: "{{ item.From }}"
    line: "{{ item.To }}"
    state: present
  with_items:
   - { From: '^memory_limit =.*$', To: 'memory_limit = 256M'}
   - { From: '^max_execution_time =.*$', To: 'max_execution_time = 60'}
  notify: restart_php74fpm

- name: remove blank lines
  connection: local
  lineinfile:
    path: rapport.out
    regexp: '^$'
    state: absent
  run_once: true

- name: remove start tab and whitespaces
  connection: local
  replace:
    path: rapport.out
    regexp: '^[ \t]{,}(.+)$'
    replace: '\1'
  run_once: true

- name: Add text block nanorc
  blockinfile:
    path: /etc/nanorc
    block: "{{ lookup('file', 'files/nanorc') }}"
    marker: "# -- {mark} ANSIBLE MANAGED BLOCK --"