feat: aggiunto playbook
This commit is contained in:
parent
2bb83bccc9
commit
070819687e
3 changed files with 47 additions and 2 deletions
41
5_primi_playbooks/2_playbook.yaml
Normal file
41
5_primi_playbooks/2_playbook.yaml
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
---
|
||||
- name: Installazione httpd, tasks vari e handler # nome di questo play
|
||||
hosts: all # specifica su quali hosts o gruppi di hosts deve essere eseguito questo play
|
||||
become: true # utilizza i privilegi di root (default false)
|
||||
gather_facts: true # raccoglie i dati sull'host (default true)
|
||||
|
||||
tasks:
|
||||
- name: Installo httpd
|
||||
ansible.builtin.dnf:
|
||||
name: httpd # nome del pacchetto da installare
|
||||
state: present # desiderata (latest per ultima versione aggiornata, present se è sufficiente che sia presente)
|
||||
|
||||
- name: Creo la directory
|
||||
ansible.builtin.file:
|
||||
path: /etc/httpd/conf.vhosts # percorso dove deve essere presente la directory
|
||||
state: directory # tipologia di file richiesto
|
||||
owner: root # owner
|
||||
group: root # gruppo
|
||||
mode: '0755' # acl del file
|
||||
|
||||
- name: Eseguo il "touch" del file example.txt in locale
|
||||
ansible.builtin.file:
|
||||
path: files/example.txt # percorso del file in locale
|
||||
state: touch # desiderata
|
||||
delegate_to: localhost # non esegue questo task sull'host target, ma esegue in locale
|
||||
|
||||
- name: Copio il file di testo
|
||||
ansible.builtin.copy:
|
||||
src: example.txt # percorso del file in locale
|
||||
dest: /etc/httpd/conf.vhosts/ # destinazione del file sulla macchina remota
|
||||
owner: root # owner
|
||||
group: root # gruppo
|
||||
mode: '0644' # acl del file
|
||||
notify:
|
||||
- Restart apache # **
|
||||
|
||||
handlers:
|
||||
- name: Restart apache # questo deve essere uguale al valore scritto nel notify **
|
||||
ansible.builtin.service:
|
||||
name: httpd
|
||||
state: restarted
|
||||
|
|
@ -37,3 +37,9 @@ ansible-playbook 13_playbook.yaml -u user -k -iinventory
|
|||
```
|
||||
ansible-playbook 14_playbook.yaml -u user -k -iinventory
|
||||
```
|
||||
|
||||
2) Esempio di playbook per che utilizza un handler per il restart di httpd se il file di conf viene modificato.
|
||||
- per lanciare il playbook:
|
||||
```
|
||||
ansible-playbook 2_playbook.yaml -u user -k -iinventory
|
||||
```
|
||||
|
|
|
|||
|
|
@ -7,5 +7,3 @@
|
|||
#host4
|
||||
#host5
|
||||
#host6
|
||||
|
||||
asdevstage01vm.ad.lepida.it
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue