3 Commitit 23561faf02 ... d145752b2c

Tekijä SHA1 Viesti Päivämäärä
  Benoît Hubert d145752b2c Documentation vault et variables 1 vuosi sitten
  Benoît Hubert 26dc5256c5 ignore md 1 vuosi sitten
  Benoît Hubert 286ac416d0 dump dir content 1 vuosi sitten

+ 12 - 2
lemp-wordpress-with-roles/README.md

@@ -28,14 +28,24 @@ Ici le noeud cible n'a pas été configuré avec des clés SSH, d'où :
 Autres arguments :
 Autres arguments :
 
 
 - `--limit <hote>` pour n'exécuter que sur un certain hote référencé dans l'inventaire
 - `--limit <hote>` pour n'exécuter que sur un certain hote référencé dans l'inventaire
-- `-e @vars-debian-xyz.yml` inclure un fichier de variables spécifiques à cet hôte (exemple dans `vars-debian-113.yml`)
+- `-e @vars/debian-xyz-vault.yml` inclure un fichier **chiffré** de variables spécifiques à cet hôte (par exemple `vars/debian-113-vault.yml`)
+- `-e @vars/debian-xyz.yml` inclure un fichier **en clair** de variables spécifiques à cet hôte (exemple dans `vars/debian-113.yml`)
+
+Le **vault** doit avoir été créé avec `ansible-vault create vars/debian-xyz-vault.yml` et contenir ces variables (remplacer les valeurs) :
+
+```
+db_username: nom_utilisateur_mysql
+db_password: mot_de_passe_mysql
+wp_username: nom_utilisateur_admin_wordpress
+wp_password: mot_de_passe_admin_wordpress
+```
 
 
 ## Installer/désinstaller
 ## Installer/désinstaller
 
 
 ### Installer tout
 ### Installer tout
 
 
 ```
 ```
-ansible-playbook -i chemin/vers/inventory.ini site.yml -bkK --limit debian-113 -e @vars-debian-113.yml
+ansible-playbook -i chemin/vers/inventory.ini site.yml -bkK --limit debian-113 -e @vars/debian-113.yml -e @vars/debian-113-vault.yml --ask-vault-pass
 ```
 ```
 
 
 ### Désinstaller manuellement (exécuter sur le noeud cible)
 ### Désinstaller manuellement (exécuter sur le noeud cible)

+ 5 - 0
lemp-wordpress-with-roles/inventory.ini

@@ -0,0 +1,5 @@
+; inventory.ini - ansible inventory file
+[debian]
+debian-111 ansible_host=192.168.1.18 ansible_user=debian ansible_become=true ansible_become_method=sudo ansible_become_user=root ansible_python_interpreter=/usr/bin/python3 
+debian-112 ansible_host=192.168.1.85 ansible_user=debian ansible_become=true ansible_become_method=sudo ansible_become_user=root ansible_python_interpreter=/usr/bin/python3 
+debian-113 ansible_host=192.168.1.109 ansible_user=debian ansible_become=true ansible_become_method=sudo ansible_become_user=root ansible_python_interpreter=/usr/bin/python3 

+ 1 - 1
lemp-wordpress-with-roles/roles/wordpress/tasks/main.yml

@@ -68,7 +68,7 @@
 
 
 # Installer Wordpress avec wp core install (cwd: /var/www/wordpress)
 # Installer Wordpress avec wp core install (cwd: /var/www/wordpress)
 - name: Installer WordPress
 - name: Installer WordPress
-  command: sudo -u www-data wp core install --url={{ site_url }} --title=My\ Blog --admin_user=admin --admin_password=admin --admin_email=benoithubert@gmail.com
+  command: sudo -u www-data wp core install --url={{ wp_site_url }} --title="{{ wp_site_title }}" --admin_user={{ wp_username }} --admin_password={{ wp_password }} --admin_email={{ wp_admin_email }}
   # WP-CLI complains if we run it as root, so we become a regular user
   # WP-CLI complains if we run it as root, so we become a regular user
   become: no
   become: no
   # Shou
   # Shou

+ 2 - 1
lemp-wordpress-with-roles/site.yml

@@ -2,7 +2,8 @@
 - name: Déployer la stack LEMP + WordPress sur Debian 12
 - name: Déployer la stack LEMP + WordPress sur Debian 12
   hosts: all
   hosts: all
   become: yes
   become: yes
-
+  vars_files:
+    - vars/common.yml
   roles:
   roles:
     - common
     - common
     - nginx
     - nginx

+ 0 - 4
lemp-wordpress-with-roles/vars-debian-113.yml

@@ -1,4 +0,0 @@
-db_username: wordpress
-db_password: wordpress
-db_name: wordpress
-site_url: debian-113

+ 2 - 0
lemp-wordpress-with-roles/vars/common.yml

@@ -0,0 +1,2 @@
+db_name: wordpress
+wp_admin_email: benoit.hubert+wpansible@gmail.com

+ 11 - 0
lemp-wordpress-with-roles/vars/debian-113-vault.yml

@@ -0,0 +1,11 @@
+$ANSIBLE_VAULT;1.1;AES256
+64313064363432336461626435333237333865646662633836396438363932633531333932626162
+3136366230636638353531343465636439333664626531300a386332666431663864383162623035
+34353661316531323864383564653030383530623530306361303662383337326366653066613036
+6331383936323761650a316637613335303461646466306632303133386364373936653962393030
+34383266646566633161323839643932653835323233373566306437303032653661386166346537
+36623463373935646431376338343432323363636539383935393237356261616462383661313935
+36396363386639643838333863306531323962663266623539363262616461663630376266333036
+39633530346364653164663266353261626463376237636631656163316666346432623137333631
+38373561663132346536616238353163373033646163363630356166633163656435356264356539
+6165626231303566366365376534346438613934303930303730

+ 2 - 0
lemp-wordpress-with-roles/vars/debian-113.yml

@@ -0,0 +1,2 @@
+wp_site_url: debian-113
+wp_site_title: Le Site WordPress de la Ansible Company

+ 54 - 0
misc-tools/dump-directory-content.js

@@ -0,0 +1,54 @@
+// dump-directory-content.js
+// Accepts one argument (a directory path).
+// Recursively read the content of the given directory and then:
+// 1. print a tree-like structure of directories and files
+// 2. in a Markdown style, print each file (full path relative to arg) in bold and its content in a fenced code block (with the language if the extension is known)
+
+const fs = require('fs');
+const path = require('path');
+
+function printDirectoryContent(directoryPath, indent = '') {
+  const files = fs.readdirSync(directoryPath);
+
+  for (const file of files) {
+    // Should exclude markdown files
+    if (file.endsWith('.md')) {
+      continue;
+    }
+    const filePath = path.join(directoryPath, file);
+    const stats = fs.statSync(filePath);
+
+    if (stats.isDirectory()) {
+      console.log(indent + file + '/');
+      printDirectoryContent(filePath, indent + '  ');
+    } else {
+      const fileContent = fs.readFileSync(filePath, 'utf8');
+      const fileExtension = path.extname(filePath).toLowerCase();
+      const language = getLanguageFromExtension(fileExtension);
+
+      console.log(indent + '**' + file + '**\n');
+      console.log('```' + language);
+      console.log(fileContent);
+      console.log('```');
+    }
+  }
+}
+
+function getLanguageFromExtension(extension) {
+  // Add more extensions and their corresponding languages as needed
+  switch (extension) {
+    case '.yml':
+      return 'javascript';
+    case '.js':
+      return 'javascript';
+    case '.py':
+      return 'python';
+    case '.java':
+      return 'java';
+    default:
+      return '';
+  }
+}
+
+const directoryPath = process.argv[2];
+printDirectoryContent(directoryPath);