Skip to content

Commit

Permalink
Use lineinfile instead of the command module
Browse files Browse the repository at this point in the history
  • Loading branch information
Lenhard Reuter committed Jul 7, 2023
1 parent d3b8b8e commit 8a3da7e
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 101 deletions.
7 changes: 4 additions & 3 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
exclude_paths:
- .github
- tests
- .github
- tests
skip_list:
- role-name
- role-name
20 changes: 10 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
repos:
- repo: https://github.com/ansible-community/ansible-lint.git
rev: v6.17.2
hooks:
- id: ansible-lint
files: \.(yaml|yml)$
- repo: https://github.com/ansible-community/ansible-lint.git
rev: v6.17.2
hooks:
- id: ansible-lint
files: \.(yaml|yml)$

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
52 changes: 26 additions & 26 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
---
- name: Configurate horde
ansible.builtin.template:
src: '{{ item.src }}'
dest: '{{ item.dst }}'
mode: '0644'
group: "{{ item.group | default('www-data') }}"
loop: '{{ horde_templates_list }}'
src: "{{ item.src }}"
dest: "{{ item.dst }}"
mode: "0644"
group: "{{ item.group | default('www-data') }}"
loop: "{{ horde_templates_list }}"
notify: Restart services

# Enable HTTPS
- name: Copy certificate
ansible.builtin.copy:
src: '{{ item.src }}'
dest: '{{ item.dest }}'
mode: '{{ item.mode }}'
loop: '{{ horde_certificate }}'
src: "{{ item.src }}"
dest: "{{ item.dest }}"
mode: "{{ item.mode }}"
loop: "{{ horde_certificate }}"

- name: Remove default apache2 configs
ansible.builtin.file:
dest: /etc/apache2/{{ item }}
state: absent
dest: /etc/apache2/{{ item }}
state: absent
loop:
- sites-available/000-default.conf
- sites-enabled/000-default.conf
- sites-available/default-ssl.conf
- sites-enabled/default-ssl.conf
- conf-available/php-horde.conf
- conf-enabled/php-horde.conf
- sites-available/000-default.conf
- sites-enabled/000-default.conf
- sites-available/default-ssl.conf
- sites-enabled/default-ssl.conf
- conf-available/php-horde.conf
- conf-enabled/php-horde.conf
notify: Restart apache2

- name: Ensure log directory exist
ansible.builtin.file:
path: '{{ horde_log_path }}'
state: directory
mode: '0750'
path: "{{ horde_log_path }}"
state: directory
mode: "0750"

- name: Activate apache2_modules
community.general.apache2_module:
name: '{{ item }}'
state: present
loop: '{{ horde_apache2modules }}'
name: "{{ item }}"
state: present
loop: "{{ horde_apache2modules }}"
become: true

- name: Manual apache2 restart
ansible.builtin.service:
name: apache2
state: restarted
name: apache2
state: restarted

- name: Activate webmail
ansible.builtin.command: a2ensite webmail
args:
creates: /etc/apache2/sites-enabled/webmail.conf
creates: /etc/apache2/sites-enabled/webmail.conf
notify: Restart apache2
changed_when: false
42 changes: 16 additions & 26 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,41 @@
---
- name: Setup database
ansible.builtin.include_role:
name: mariadb
name: mariadb
vars:
mariadb_databases:
- name: '{{ horde_db_name }}'
mariadb_users:
[
{
name: '{{ horde_db_user }}',
password: '{{ horde_db_pass }}',
privileges: '{{ horde_db_name }}.*:ALL,GRANT',
},
]

mariadb_databases:
- name: "{{ horde_db_name }}"
mariadb_users: [{ name: "{{ horde_db_user }}", password: "{{ horde_db_pass }}", privileges: "{{ horde_db_name }}.*:ALL,GRANT" }]
- name: Gather os specific variables
ansible.builtin.include_vars: '{{ item }}'
ansible.builtin.include_vars: "{{ item }}"
with_first_found:
- '{{ ansible_distribution }}-{{ ansible_distribution_version }}.yml'
- default.yml
- "{{ ansible_distribution }}-{{ ansible_distribution_version }}.yml"
- default.yml

- name: Install required apt packages
become: true
ansible.builtin.apt:
name: '{{ horde_apt_packages }}'
state: present
update_cache: true
cache_valid_time: 3600
name: "{{ horde_apt_packages }}"
state: present
update_cache: true
cache_valid_time: 3600

- name: Install Horde via pear
ansible.builtin.include_tasks: pear.yml
when: ansible_distribution_version != '18.04'

- name: Install required pip packages
ansible.builtin.pip:
name: '{{ horde_pip_packages }}'
name: "{{ horde_pip_packages }}"

- name: Run webmail install
ansible.builtin.expect:
args:
command: webmail-install
responses: '{{ horde_webinstall_responses }}'
echo: true
command: webmail-install
responses: "{{ horde_webinstall_responses }}"
echo: true
register: expect_webmail_install_result
failed_when:
expect_webmail_install_result.rc != 0 and 'Thank you for using Horde
Groupware Webmail Edition!' not in expect_webmail_install_result.stdout
failed_when: expect_webmail_install_result.rc != 0 and 'Thank you for using Horde Groupware Webmail Edition!' not in expect_webmail_install_result.stdout
become: true

- name: Configure Horde and Apache
Expand Down
72 changes: 36 additions & 36 deletions tasks/pear.yml
Original file line number Diff line number Diff line change
@@ -1,93 +1,93 @@
---
- name: Check if horde pear channel is installed
ansible.builtin.shell:
cmd: |
set -o pipefail
pear list-channels | grep pear.horde.org
cmd: |
set -o pipefail
pear list-channels | grep pear.horde.org
args:
executable: /bin/bash
executable: /bin/bash
register: channel_registered
failed_when: channel_registered.rc >= 2
changed_when: channel_registered.stdout

- name: Discover horde PEAR channel
ansible.builtin.shell:
cmd: |
set -o pipefail
pear channel-discover pear.horde.org
cmd: |
set -o pipefail
pear channel-discover pear.horde.org
args:
executable: /bin/bash
executable: /bin/bash
changed_when: false
when: channel_registered.stdout == ''

- name: Check if horde pear package is installed
ansible.builtin.shell:
cmd: |
set -o pipefail
pear list -c pear.horde.org | grep Horde_Role
cmd: |
set -o pipefail
pear list -c pear.horde.org | grep Horde_Role
args:
executable: /bin/bash
executable: /bin/bash
register: package_installed
failed_when: package_installed.rc >= 2
changed_when: package_installed.stdout == ''

- name: Install horde package
ansible.builtin.shell:
cmd: pear install horde/horde_role
cmd: pear install horde/horde_role
args:
executable: /bin/bash
executable: /bin/bash
changed_when: false
become: true
when: package_installed.stdout == ''

- name: Fix unexpected 'new' (T_NEW) error
ansible.builtin.shell:
cmd: 'pear uninstall {{ item }}'
cmd: pear uninstall {{ item }}
args:
executable: /bin/bash
executable: /bin/bash
changed_when: false
loop:
- File_Fstab
- Services_Weather
- horde/Horde_Service_Weather
- File_Fstab
- Services_Weather
- horde/Horde_Service_Weather

- name: Fixing syntax error in a dependency PHP module.
- name: Fixing syntax error in a dependency PHP module
become: true
ansible.builtin.command:
cmd: sed -i '167s/&//' /usr/share/php/Services/Weather.php
ansible.builtin.lineinfile:
path: /usr/share/php/Services/Weather.php
regexp: ^.*$
line: ""
backup: true
changed_when: false
failed_when: false
when: package_installed.stdout == ''
tags:
- skip_ansible_lint

- name: Execute Horde run scripts
become: true
ansible.builtin.expect:
args:
command: pear run-scripts horde/horde_role
responses: '{{ horde_run_scripts_responses }}'
echo: true
command: pear run-scripts horde/horde_role
responses: "{{ horde_run_scripts_responses }}"
echo: true
register: run_scripts_install_result
failed_when:
run_scripts_install_result.rc != 0 and 'Install scripts complete' not in
run_scripts_install_result.stdout
failed_when: run_scripts_install_result.rc != 0 and 'Install scripts complete' not in run_scripts_install_result.stdout

- name: Check if horde pear webmail is installed
ansible.builtin.shell:
cmd: |
set -o pipefail
pear list -c pear.horde.org | grep webmail
cmd: |
set -o pipefail
pear list -c pear.horde.org | grep webmail
args:
executable: /bin/bash
executable: /bin/bash
register: webmail_package_installed
failed_when: webmail_package_installed.rc >= 2
changed_when: webmail_package_installed.stdout == ''

- name: Install horde webmail
become: true
ansible.builtin.shell:
cmd: pear install -a -B --force horde/webmail
cmd: pear install -a -B --force horde/webmail
args:
executable: /bin/bash
executable: /bin/bash
changed_when: false
when: webmail_package_installed.stdout == ''

0 comments on commit 8a3da7e

Please sign in to comment.