Browse Source

Création du projet Ansible de présentation.

* Déploiement d'un motd
 * Configuration des locales et timezone
 * Installation de paquets
 * Déploiement d'une tâche cron
 * Role MySQL pour créer des utilisateurs et DB
 * Inventaire et variables d'exemple
master
Guillaume Tredez 3 years ago
parent
commit
0109a69e8c
15 changed files with 216 additions and 2 deletions
  1. +17
    -2
      README.md
  2. +15
    -0
      configuration.yml
  3. +20
    -0
      group_vars/all
  4. +5
    -0
      group_vars/centos
  5. +4
    -0
      group_vars/debian
  6. +8
    -0
      group_vars/mysql-server
  7. +7
    -0
      host_vars/hostcentos
  8. +27
    -0
      host_vars/hostdebian
  9. +12
    -0
      mon_inventaire
  10. +4
    -0
      roles/common/handlers/main.yml
  11. +13
    -0
      roles/common/tasks/centosbase.yml
  12. +24
    -0
      roles/common/tasks/debianbase.yml
  13. +28
    -0
      roles/common/tasks/main.yml
  14. +7
    -0
      roles/common/templates/motd.j2
  15. +25
    -0
      roles/mysql/tasks/main.yml

+ 17
- 2
README.md View File

@ -1,3 +1,18 @@
# noskillbrain_ansible_prez
# Noskillbrain: projet Ansible
Repo de prez ansible, article https://noskillbrain.fr/2017/10/18/ansible/
Projet de présentation Ansible du blog noskillbrain.fr, article https://noskillbrain.fr/2017/10/18/ansible/
## Prérequis
* Ansible >= 2.4.0
* https://noskillbrain.fr/2017/10/18/ansible/
## Utilisation
```
ansible-playbook -i mon_inventaire configuration.yml -v
```
## Contributeurs
- [Guillaume Tredez](https://noskillbrain.fr) - [Twitter: @noskillbrain](https://twitter.com/noskillbrain)

+ 15
- 0
configuration.yml View File

@ -0,0 +1,15 @@
---
# playbook de presentation https://noskillbrain.fr/2017/10/18/ansible/
- name: Récupération des gather facts
hosts: all
user: root
gather_facts: yes
- hosts: all
roles:
- common
- hosts: mysql-server
roles:
- mysql

+ 20
- 0
group_vars/all View File

@ -0,0 +1,20 @@
---
locales:
- fr_FR.UTF-8
- en_US.UTF-8
default_locale: fr_FR.UTF-8
timezone: Europe/Paris
motd: "Serveur {{ ansible_fqdn }} OS: {{ansible_lsb.description}}"
common_packages:
- vim
- rsync
- unzip
packages:
- "{{ common_packages }}"
- "{{ more_packages }}"

+ 5
- 0
group_vars/centos View File

@ -0,0 +1,5 @@
---
more_packages:
- epel-release
- MySQL-python

+ 4
- 0
group_vars/debian View File

@ -0,0 +1,4 @@
---
more_packages:
- locales

+ 8
- 0
group_vars/mysql-server View File

@ -0,0 +1,8 @@
locales:
- fr_FR.UTF-8
- en_US.UTF-8
- en_GB.UTF-8
more_packages:
- mysql-server
- python-mysqldb

+ 7
- 0
host_vars/hostcentos View File

@ -0,0 +1,7 @@
---
# fichier de variables de configuration pour le serveur hostcentos
# https://noskillbrain.fr/2017/10/18/ansible/
hostname: hostcentos
ip_address: 192.168.2.87

+ 27
- 0
host_vars/hostdebian View File

@ -0,0 +1,27 @@
---
# fichier de variables de configuration pour le serveur hostdebian
# https://noskillbrain.fr/2017/10/18/ansible/
hostname: hostdebian
ip_address: 192.168.2.109
#
# DISCLAMER: les mots de passe sont définis en clair à titre d'exemple.
# L'utilisation d'ansible Vault est largement recommendé dans ce type de cas.
# Ansible vault: http://docs.ansible.com/ansible/latest/vault.html
#
mysql_user:
noskillbrain1:
password: i0eFuprAYZQQ
databases:
- noskillbrain1_db_1
privs:
- noskillbrain1_db_1.*:ALL
noskillbrain2:
password: V17pPyOsUO6Q
databases:
- noskillbrain2_db_1
- noskillbrain2_db_2
privs:
- noskillbrain2_db_1.*:ALL
- noskillbrain2_db_2.*:SELECT

+ 12
- 0
mon_inventaire View File

@ -0,0 +1,12 @@
[linux-server]
hostcentos ansible_host=192.168.2.87
hostdebian ansible_host=192.168.2.109
[debian]
hostdebian
[centos]
hostcentos
[mysql-server]
hostdebian

+ 4
- 0
roles/common/handlers/main.yml View File

@ -0,0 +1,4 @@
---
- name: restart ssh
service: name=ssh state=restarted

+ 13
- 0
roles/common/tasks/centosbase.yml View File

@ -0,0 +1,13 @@
---
# Module YUM: http://docs.ansible.com/ansible/latest/yum_module.html
- name: Installation des paquets
yum:
name: "{{ item }}"
state: present
with_items: "{{ packages }}" # variable du group all
tags: packages
# Module COMMAND: http://docs.ansible.com/ansible/latest/command_module.html
- name: Configuration de la locale par défaut
command: localectl set-locale LANG={{ default_locale }}

+ 24
- 0
roles/common/tasks/debianbase.yml View File

@ -0,0 +1,24 @@
---
# Module APT: http://docs.ansible.com/ansible/latest/apt_module.html
- name: Installation des paquets
apt:
name: "{{ item }}"
state: present
update_cache: true
with_items: "{{ packages }}" # variable du group all
tags: packages
# Module LOCALE_GEN: http://docs.ansible.com/ansible/latest/locale_gen_module.html
- name: Génération des locales
locale_gen:
name: "{{ item }}"
state: present
with_items: "{{ locales }}"
# Module LINEINFILE: http://docs.ansible.com/ansible/latest/lineinfile_module.html
- name: Configuration de la locale par défaut
lineinfile:
dest: /etc/default/locale
regexp: "LANG="
line: "LANG={{ default_locale }}"

+ 28
- 0
roles/common/tasks/main.yml View File

@ -0,0 +1,28 @@
---
# Tâches pour Debian 9 ou supérieur
- import_tasks: debianbase.yml
when: ansible_os_family == 'Debian' and ansible_distribution_major_version | int >= 9
# Tâches pour CentOS 7 ou supérieur
- import_tasks: centosbase.yml
when: ansible_os_family == 'RedHat' and ansible_distribution_major_version | int >= 7
# Module TIMEZONE: http://docs.ansible.com/ansible/latest/timezone_module.html
- name: Configuration de la timezone
timezone:
name: "{{ timezone }}"
- name: Déploiement du motd
template:
src: motd.j2
dest: /etc/motd
tags: motd
notify: restart ssh
- name: Déploiement d'une tâche cron
cron:
name: "Tache cron de test"
minute: "12"
hour: "12"
job: "echo 'Hello World'"

+ 7
- 0
roles/common/templates/motd.j2 View File

@ -0,0 +1,7 @@
Hostname: {{ ansible_fqdn }}
OS: {{ansible_distribution}} {{ansible_distribution_major_version}} ({{ansible_distribution_version}})
IP: {% for ip in ansible_all_ipv4_addresses %}{{ip}} {% endfor %}
CPU: {% for cpu in ansible_processor %} {{cpu}} {% endfor %}

+ 25
- 0
roles/mysql/tasks/main.yml View File

@ -0,0 +1,25 @@
---
# Module MYSQL USER: http://docs.ansible.com/ansible/latest/mysql_user_module.html
- name: Création des utilisateur SQL
mysql_user:
name: "{{ item.key }}"
password: "{{ item.value.password }}"
priv: "{{ item.value.privs | join('/') }}"
host: "127.0.0.1"
state: present
with_dict: "{{ mysql_user }}"
tags:
- mysql
- mysql_user
- name: Création des bases de données SQL
mysql_db:
name: "{{ item.1 }}"
state: present
with_subelements:
- "{{ mysql_user }}"
- databases
tags:
- mysql
- mysql_db

Loading…
Cancel
Save