From 50081cc5d8b1432d8f0b4d7f86d26cc6d0cc6c11 Mon Sep 17 00:00:00 2001 From: Thomas Constans Date: Tue, 5 May 2020 22:56:05 +0200 Subject: [PATCH] make it work on more distros --- 17.3_variable/apache.yml | 2 -- 17.3_variable/host_vars/100.0.0.102 | 23 +++++------------------ 17.3_variable/myapache3/handlers/main.yml | 2 +- 17.3_variable/myapache3/tasks/main.yml | 21 ++++++++++++++------- 4 files changed, 20 insertions(+), 28 deletions(-) diff --git a/17.3_variable/apache.yml b/17.3_variable/apache.yml index 7e74290..dfd28d9 100644 --- a/17.3_variable/apache.yml +++ b/17.3_variable/apache.yml @@ -1,7 +1,5 @@ --- - name: install apache via ansible playbook hosts: all - user: root - become: false roles: - myapache3 diff --git a/17.3_variable/host_vars/100.0.0.102 b/17.3_variable/host_vars/100.0.0.102 index d2699a6..af87baa 100644 --- a/17.3_variable/host_vars/100.0.0.102 +++ b/17.3_variable/host_vars/100.0.0.102 @@ -1,18 +1,5 @@ -apache_vhosts: -- servername: cines.fr - serveralias: - - www.cines.fr - - cines.org - - www.cines.org - documentroot: /var/www/html/cines.fr - accesslog: /var/log/httpd/access_cines.fr_log - errorlog: /var/log/httpd/error_cines.fr_log -- servername: thomas.fr - serveralias: - - www.thomas.fr - - thomas.com - - www.thomas.cm - documentroot: /var/www/html/thomas.fr - accesslog: /var/log/httpd/access_thomas.fr_log - errorlog: /var/log/httpd/error_thomas.fr_log - documentrootoptions: indexes \ No newline at end of file +servername: laposte.net +serveralias: www.laposte.net +documentroot: /var/www/html/laposte.net +accesslog: /var/log/httpd/access_laposte.net_log +errorlog: /var/log/httpd/error_laposte.net_log \ No newline at end of file diff --git a/17.3_variable/myapache3/handlers/main.yml b/17.3_variable/myapache3/handlers/main.yml index c72410b..4bb4f11 100644 --- a/17.3_variable/myapache3/handlers/main.yml +++ b/17.3_variable/myapache3/handlers/main.yml @@ -2,7 +2,7 @@ # handlers file for myapache - name: reload httpd service: - name: httpd + name: "{{ apache_service_name }}" state: reloaded - name: reload firewalld diff --git a/17.3_variable/myapache3/tasks/main.yml b/17.3_variable/myapache3/tasks/main.yml index 9dedf3d..cc71c22 100644 --- a/17.3_variable/myapache3/tasks/main.yml +++ b/17.3_variable/myapache3/tasks/main.yml @@ -1,16 +1,22 @@ --- # tasks file for myapache -- name: install apache +# +- name: include distribution specific variables + include_vars: "{{ ansible_distribution|lower }}.yml" + +- name: install apache almost anywhere tags: httpd - yum: - name: httpd + package: + name: "{{ apache_package_name}}" state: latest + + - name: conf httpd tags: httpd notify: reload httpd template: src: vhost.conf.jj - dest: /etc/httpd/conf.d/vhost.conf + dest: "{{ apache_conf_dir}}/vhost.conf" mode: 0640 owner: root group: apache @@ -18,7 +24,7 @@ - name: activate apache tags: httpd service: - name: httpd + name: "{{ apache_service_name }}" enabled: yes - name: open firewall port @@ -30,11 +36,12 @@ state: enabled ignore_errors: yes notify: reload firewalld + when: ansible_distribution=="CentOS" or "RedHat" - name: create documentroot tags: httpd file: - name: "/var/www/html/{{ item.documentroot }}" + name: "{{ item.documentroot }}" state: directory with_items: - "{{ apache_vhosts }}" @@ -43,7 +50,7 @@ tags: httpd copy: src: index.html - dest: "/var/www/html/{{ item.documentroot }}/index.html" + dest: "{{ item.documentroot }}/index.html" mode: 0644 with_items: - "{{ apache_vhosts }}" \ No newline at end of file