feat: aggiunta capitolo roles
This commit is contained in:
parent
951d5105c6
commit
562522845a
5 changed files with 39 additions and 0 deletions
18
10_roles/README.md
Normal file
18
10_roles/README.md
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Alcuni esempi pratici sull'utilizzo dei roles in Ansible
|
||||||
|
|
||||||
|
I roles devono avere una struttura di directory ben precisa, dato un progetto "progetto_esempio" ed i roles "install, update", possiamo creare la struttura di directory con i seguenti comandi:
|
||||||
|
|
||||||
|
```
|
||||||
|
project=progetto_esempio role=install ; mkdir $project $project/$role $project/$role/tasks $project/$role/handlers $project/$role/templates $project/$role/files $project/$role/vars
|
||||||
|
project=progetto_esempio role=update ; mkdir $project $project/$role $project/$role/tasks $project/$role/handlers $project/$role/templates $project/$role/files $project/$role/vars
|
||||||
|
```
|
||||||
|
|
||||||
|
- per lanciare il playbook utilizziamo il seguente comando
|
||||||
|
```
|
||||||
|
ansible-playbook -iinventory runner.yaml
|
||||||
|
```
|
||||||
|
|
||||||
|
- per lanciare solamente uno dei roles del playbook, utilizare il seguente comando:
|
||||||
|
```
|
||||||
|
ansible-playbook -iinventory runner.yaml --tags install
|
||||||
|
```
|
||||||
6
10_roles/progetto_esempio/install/tasks/main.yaml
Normal file
6
10_roles/progetto_esempio/install/tasks/main.yaml
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
|
||||||
|
- name: Installo il pachetto httpd
|
||||||
|
ansible.builtin.package:
|
||||||
|
name: httpd
|
||||||
|
state: present
|
||||||
2
10_roles/progetto_esempio/inventory
Normal file
2
10_roles/progetto_esempio/inventory
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
servertest1
|
||||||
|
servertest2
|
||||||
7
10_roles/progetto_esempio/runner.yaml
Normal file
7
10_roles/progetto_esempio/runner.yaml
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
- hosts: all
|
||||||
|
roles:
|
||||||
|
- role: install
|
||||||
|
tags: install
|
||||||
|
- role: update
|
||||||
|
tags: update
|
||||||
6
10_roles/progetto_esempio/update/tasks/main.yaml
Normal file
6
10_roles/progetto_esempio/update/tasks/main.yaml
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
|
||||||
|
- name: Aggiorno il pachetto httpd
|
||||||
|
ansible.builtin.package:
|
||||||
|
name: httpd
|
||||||
|
state: latest
|
||||||
Loading…
Add table
Reference in a new issue