Resources attached to the Road To DevOps tutorial
https://blog.noobtoroot.xyz/road-to-devops/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.2 KiB
56 lines
1.2 KiB
2 years ago
|
## TP Structures de contrôle
|
||
|
|
||
|
Utiliser les boucles pour :
|
||
|
|
||
|
1. gérer l'installation des packages,
|
||
|
|
||
|
2. effectuer les modifications sur le fichier de configuration de Wordpress.
|
||
|
|
||
|
|
||
|
Installation des packages avec `loop`
|
||
|
|
||
|
```yaml
|
||
|
- name: Install packages
|
||
|
yum:
|
||
|
name: "{{ item }}"
|
||
|
state: present
|
||
|
loop:
|
||
|
- php
|
||
|
- php-mysql
|
||
|
- httpd
|
||
|
```
|
||
|
|
||
|
Ou en passant une liste au module `yum`
|
||
|
```yaml
|
||
|
- name: Install packages
|
||
|
yum:
|
||
|
name:
|
||
|
- php
|
||
|
- php-mysql
|
||
|
- httpd
|
||
|
state: present
|
||
|
```
|
||
|
|
||
|
|
||
|
Configuration de Wordpress avec `loop`
|
||
|
|
||
|
<!-- .slide: data-state="medium-code" -->
|
||
|
```yaml
|
||
|
- name: Create wordpress configuration file
|
||
|
copy:
|
||
|
src: /var/www/html/wordpress/wp-config-sample.php
|
||
|
dest: /var/www/html/wordpress/wp-config.php
|
||
|
remote_src: true
|
||
|
|
||
|
- name: Update wordpress configuration file
|
||
|
replace:
|
||
|
path: /var/www/html/wordpress/wp-config.php
|
||
|
regexp: "{{ item.regexp }}"
|
||
|
replace: "{{ item.replace }}"
|
||
|
loop:
|
||
|
- { regexp: 'database_name_here', replace: '{{ DB_NAME }}'}
|
||
|
- { regexp: 'username_here', replace: '{{ DB_USER }}'}
|
||
|
- { regexp: 'password_here', replace: '{{ DB_PASSWORD }}'}
|
||
|
- { regexp: 'localhost', replace: '{{ DB_HOST }}'}
|
||
|
```
|