From 33ce25edd0ee086d78df9eb34faa844c96009518 Mon Sep 17 00:00:00 2001 From: Thomas Constans Date: Fri, 13 Oct 2023 09:25:36 +0200 Subject: [PATCH] solution --- apache.yml | 2 +- sib.apache/handlers/main.yml | 2 +- sib.apache/tasks/main.yml | 39 ++++++++++++++++++++++++++---------- sib.apache/vars/debian.yml | 4 ++++ sib.apache/vars/main.yml | 3 ++- sib.apache/vars/redhat.yml | 4 ++++ 6 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 sib.apache/vars/debian.yml create mode 100644 sib.apache/vars/redhat.yml diff --git a/apache.yml b/apache.yml index bc21901..165d708 100644 --- a/apache.yml +++ b/apache.yml @@ -1,4 +1,4 @@ --- -- hosts: centos +- hosts: cibles roles: - sib.apache \ No newline at end of file diff --git a/sib.apache/handlers/main.yml b/sib.apache/handlers/main.yml index d99d2f2..ac87c25 100644 --- a/sib.apache/handlers/main.yml +++ b/sib.apache/handlers/main.yml @@ -2,5 +2,5 @@ # handlers file for sib.apache - name: restart httpd service: - name: httpd + name: "{{ apache_service_name }}" state: restarted \ No newline at end of file diff --git a/sib.apache/tasks/main.yml b/sib.apache/tasks/main.yml index 1a6c8a0..ed634bb 100644 --- a/sib.apache/tasks/main.yml +++ b/sib.apache/tasks/main.yml @@ -1,22 +1,36 @@ --- # tasks file for sib.apache -- name: install apache - yum: - name: httpd + +- name: read OS vars + tags: always + ansible.builtin.include_vars: "{{ ansible_os_family | lower }}.yml" + + +- name: install apache on Centos + package: + name: "{{ apache_package_name }}" state: present - name: conf httpd template: - src: vhost.conf - dest: /etc/httpd/conf.d/vhost.conf + src: vhost.conf.jj + dest: "{{ apache_config_dir }}" mode: 0640 owner: root - group: apache + group: "{{ apache_group_name }}" notify: restart httpd +- name: delete default conf on debian + tags: debian + file: + path: "{{ apache_config_dir }}/000-default.conf" + state: absent + notify: restart httpd + when: ansible_os_family | lower == 'debian' + - name: activate apache service: - name: httpd + name: "{{ apache_service_name }}" enabled: yes state: started @@ -41,15 +55,18 @@ permanent: yes immediate: yes state: enabled - ignore_errors: true + ignore_errors: true + when: ansible_os_family == 'RedHat' - name: create documentroot file: - name: /var/www/html/example.org/ + name: '{{ item.documentroot }}' state: directory + loop: "{{ apache_vhosts }}" - name: copy index file template: src: index.txt - dest: /var/www/html/example.org/index.html - mode: 0644 \ No newline at end of file + dest: "{{ item.documentroot }}" + mode: 0644 + loop: "{{ apache_vhosts }}" \ No newline at end of file diff --git a/sib.apache/vars/debian.yml b/sib.apache/vars/debian.yml new file mode 100644 index 0000000..c463ce5 --- /dev/null +++ b/sib.apache/vars/debian.yml @@ -0,0 +1,4 @@ +apache_service_name: apache2 +apache_package_name: apache2 +apache_group_name: www-data +apache_config_dir: /etc/apache2/sites-enabled/ \ No newline at end of file diff --git a/sib.apache/vars/main.yml b/sib.apache/vars/main.yml index 6c7777f..cf773f0 100644 --- a/sib.apache/vars/main.yml +++ b/sib.apache/vars/main.yml @@ -1,2 +1,3 @@ --- -# vars file for sib.apache \ No newline at end of file +# vars file for sib.apache +http_port: 80 \ No newline at end of file diff --git a/sib.apache/vars/redhat.yml b/sib.apache/vars/redhat.yml new file mode 100644 index 0000000..55fe13e --- /dev/null +++ b/sib.apache/vars/redhat.yml @@ -0,0 +1,4 @@ +apache_service_name: httpd +apache_package_name: httpd +apache_group_name: apache +apache_config_dir: /etc/httpd/conf.d/