From 6e42991efa28f19850c4fa28173ccb9826839957 Mon Sep 17 00:00:00 2001 From: Thomas Constans Date: Tue, 14 Sep 2021 15:01:18 +0200 Subject: [PATCH] mise au point support multi distribution --- ansible_apache_formation/README.md | 9 +++++++++ ansible_apache_formation/defaults/main.yml | 4 ++-- ansible_apache_formation/handlers/main.yml | 9 +++++---- ansible_apache_formation/tasks/apache.yml | 19 +++++++++++-------- ansible_apache_formation/templates/vhost.conf | 17 ++++++++--------- ansible_apache_formation/vars/centos7.yml | 1 + ansible_apache_formation/vars/centos8.yml | 6 ++++++ ansible_apache_formation/vars/debian10.yml | 7 +++++++ 8 files changed, 49 insertions(+), 23 deletions(-) create mode 100644 ansible_apache_formation/vars/centos7.yml create mode 100644 ansible_apache_formation/vars/centos8.yml create mode 100644 ansible_apache_formation/vars/debian10.yml diff --git a/ansible_apache_formation/README.md b/ansible_apache_formation/README.md index 6093f71..95e23b3 100644 --- a/ansible_apache_formation/README.md +++ b/ansible_apache_formation/README.md @@ -14,6 +14,15 @@ None Role Variables -------------- +apache_server_name - nom du site + +apache_service_name - nom du service +apache_package_name - nom du package +apache_config_dir - répertoire de config +apache_group_name - nom du groupe apache +#apache_listen_port - port d'écoute - defaut 80 + + Dependencies ------------ diff --git a/ansible_apache_formation/defaults/main.yml b/ansible_apache_formation/defaults/main.yml index 5794a03..a4eb219 100644 --- a/ansible_apache_formation/defaults/main.yml +++ b/ansible_apache_formation/defaults/main.yml @@ -1,3 +1,3 @@ +#/home/formation/ansible_apache_formation/defaults/main.yml --- -apache_service_name: httpd -apache_package_name: httpd +apache_listen_port: 80 diff --git a/ansible_apache_formation/handlers/main.yml b/ansible_apache_formation/handlers/main.yml index 81a5908..ac81c71 100644 --- a/ansible_apache_formation/handlers/main.yml +++ b/ansible_apache_formation/handlers/main.yml @@ -1,4 +1,5 @@ -- name: reload httpd - service: - name: "{{ apache_service_name }}" - state: reloaded +--- + - name: reload httpd + service: + name: "{{ apache_service_name }}" + state: reloaded diff --git a/ansible_apache_formation/tasks/apache.yml b/ansible_apache_formation/tasks/apache.yml index 7325121..4073949 100644 --- a/ansible_apache_formation/tasks/apache.yml +++ b/ansible_apache_formation/tasks/apache.yml @@ -1,4 +1,7 @@ --- +- name: import OS variables + include_vars: "{{ ansible_distribution |lower }}{{ ansible_distribution_major_version }}.yml" + - name: installation package: name: "{{ apache_package_name }}" @@ -8,10 +11,10 @@ notify: reload httpd template: src: vhost.conf - dest: /etc/httpd/conf.d/vhost.conf + dest: "{{ apache_config_dir }}/vhost.conf" mode: 0640 owner: root - group: apache + group: "{{ apache_group_name }}" - name: enable service service: @@ -28,30 +31,30 @@ - name: create documentroot file: - name: "{{ apache_documentroot }}" + name: "/var/www/{{ apache_server_name }}" state: directory - name: create index file template: src: index.html - dest: "{{ apache_documentroot }}/index.html" + dest: "/var/www/{{ apache_server_name }}/index.html" mode: 0644 - name: install python passlib package package: - name: python3-passlib + name: "{{ python_passlib_package }}" state: present - name: passwd file htpasswd: - path: "/etc/httpd/passwd" + path: "{{ apache_config_dir }}/passwd" name: tom password: "123Soleil" mode: 0640 owner: root - group: "apache" + group: "{{ apache_group_name }}" - name: start service service: name: "{{ apache_service_name }}" - state: restarted \ No newline at end of file + state: started \ No newline at end of file diff --git a/ansible_apache_formation/templates/vhost.conf b/ansible_apache_formation/templates/vhost.conf index b9cd35c..3379e1d 100644 --- a/ansible_apache_formation/templates/vhost.conf +++ b/ansible_apache_formation/templates/vhost.conf @@ -1,24 +1,23 @@ - ServerName {{ apache_server_name }} - ServerAlias www.{{ apache_server_name }} - ServerAlias {{ inventory_hostname }} - DocumentRoot {{ apache_documentroot }} - CustomLog /var/log/httpd/{{ apache_server_name }}_access.log combined - ErrorLog /var/log/httpd/{{ apache_server_name }}_error.log + ServerName {{ apache_server_name }}" + ServerAlias www.{{ apache_server_name }}" + DocumentRoot /var/www/{{ apache_server_name }}" + CustomLog /var/log/{{ apache_service_name }}/{{ apache_server_name }}"_access.log combined + ErrorLog /var/log/{{ apache_service_name }}/{{ apache_server_name }}"_error.log Options none Allowoverride none Require all denied - + Require all granted - + Options indexes AuthName "stop" AuthType Basic - AuthUserFile /etc/httpd/passwd + AuthUserFile {{ apache_config_dir }}/passwd require valid-user \ No newline at end of file diff --git a/ansible_apache_formation/vars/centos7.yml b/ansible_apache_formation/vars/centos7.yml new file mode 100644 index 0000000..e9aa13b --- /dev/null +++ b/ansible_apache_formation/vars/centos7.yml @@ -0,0 +1 @@ +python_passlib_package: python-passlib diff --git a/ansible_apache_formation/vars/centos8.yml b/ansible_apache_formation/vars/centos8.yml new file mode 100644 index 0000000..cee3cf0 --- /dev/null +++ b/ansible_apache_formation/vars/centos8.yml @@ -0,0 +1,6 @@ +#/home/formation/ansible_apache_formation/vars/centos8.yml +python_passlib_package: python3-passlib +apache_service_name: httpd +apache_package_name: httpd +apache_config_dir: /etc/httpd/conf.d +apache_group_name: apache diff --git a/ansible_apache_formation/vars/debian10.yml b/ansible_apache_formation/vars/debian10.yml new file mode 100644 index 0000000..662d2ec --- /dev/null +++ b/ansible_apache_formation/vars/debian10.yml @@ -0,0 +1,7 @@ +#/home/formation/ansible_apache_formation/vars/debian10.yml +python_passlib_package: python3-passlib +apache_service_name: apache2 +apache_package_name: apache2 +apache_config_dir: /etc/apache2/sites-enabled +apache_group_name: www-data +