diff --git a/Readme.md b/Readme.md index 64f7b74..df1fa94 100644 --- a/Readme.md +++ b/Readme.md @@ -10,14 +10,14 @@ ** Pratique ** -Adapter le playbook apache.yml pour qu'il fonctionne sur la machine _debian_: +En examinant les différents fichiers présents dans ce dépôt, essayez de +déterminez de quelle manière ce playbook a été adapté pour fonctionner aussi +bien sur une CentOS qu'une Debian. - 1. identifiez les différences entre OS (nom des packages, des services, répertoires différents, ...) - 2. essayez de trouver une solution permettant de gérer ses différences. +La tâche "conf httpd" ne fonctionnera pas sur Debian. Pourquoi ? Proposez une solution. + +Ce playbook n'est pas complet. Déterminez les éléments manquants et corrigez. ** Validation: -le playbook s'exécute correctement sur la machine debian - -Chaque cible héberge plusieurs sites différents. -Proposition de solution: voir la branche "solution" \ No newline at end of file +le playbook s'exécute correctement sur la machine debian \ No newline at end of file diff --git a/apache.yml b/apache.yml index 518f699..0e4fb7e 100644 --- a/apache.yml +++ b/apache.yml @@ -1,15 +1,72 @@ --- - name: install apache via ansible playbook - hosts: centos + hosts: all + handlers: + - name: restart apache + service: + name: "{{ apache_service_name }}" + state: restarted tasks: + - name: install apache - yum: - name: httpd + package: + name: "{{ apache_package_name }}" state: present + - name: conf httpd + template: + src: vhost.conf + dest: "{{ apache_config_dir}}/vhost.conf" + mode: 0640 + owner: root + group: apache + notify: restart apache + - name: activate apache service: - name: httpd + name: "{{ apache_service_name }}" enabled: yes - state: started \ No newline at end of file + state: started + + - name: remove default site conf + file: + path: /etc/apache2/sites-enabled/000-default.conf + state: absent + notify: restart apache + + - name: setup firewall + block: + - name: install firewalld packages + yum: + name: + - python3-firewall + - firewalld + state: present + + - name: enable firewalld service + service: + name: firewalld + enabled: true + state: started + + - name: open firewall port + firewalld: + service: http + permanent: yes + immediate: yes + state: enabled + ignore_errors: true + when: ansible_distribution == 'CentOS' + + + - name: create documentroot + file: + name: /var/www/html/example.org/ + state: directory + + - name: copy index file + template: + src: index.txt + dest: /var/www/html/example.org/index.html + mode: 0644 \ No newline at end of file diff --git a/centos.yml b/centos.yml new file mode 100644 index 0000000..901f5e2 --- /dev/null +++ b/centos.yml @@ -0,0 +1,5 @@ +#/home/formation/sib_10_premier_playbook/centos.yml +apache_service_name: httpd +apache_package_name: httpd +apache_config_dir: /etc/httpd/conf.d +apache_log_dir: /var/log/httpd diff --git a/debian.yml b/debian.yml new file mode 100644 index 0000000..e20b885 --- /dev/null +++ b/debian.yml @@ -0,0 +1,5 @@ +#/home/formation/sib_10_premier_playbook/debian.yml +apache_service_name: apache2 +apache_package_name: apache2 +apache_config_dir: /etc/apache2/sites-enabled/ +apache_log_dir: /var/log/apache2 diff --git a/index.txt b/index.txt new file mode 100644 index 0000000..416474e --- /dev/null +++ b/index.txt @@ -0,0 +1 @@ +

hello World

\ No newline at end of file diff --git a/vhost.conf b/vhost.conf new file mode 100644 index 0000000..f47d8dd --- /dev/null +++ b/vhost.conf @@ -0,0 +1,25 @@ +#/home/formation/sib_10_premier_playbook/vhost.conf + + ServerName example.org + ServerAlias www.example.org + ServerAlias {{ inventory_hostname }} + DocumentRoot /var/www/html/example.org + CustomLog {{ apache_log_dir }}/example.org_access.log combined + ErrorLog {{ apache_log_dir }}/example.org_error.log + + Options none + Allowoverride none + Require all denied + + + + Require all granted + + + Options indexes + AuthName "stop" + AuthType Basic + AuthUserFile /etc/{{ apache_service_name }}/passwd + require valid-user + + \ No newline at end of file