Ver Fonte

clase 08/02/23

Student User há 2 anos atrás
pai
commit
5a1f628707

+ 9 - 0
T2-Ej/Ej2-ad-hoc/ansible.cfg

@@ -0,0 +1,9 @@
+[defaults]
+inventory = mis_maquinas
+remote_user = devops
+
+[privilege_escalation]
+become = true
+become_method = sudo
+become_user = root
+become_ask_pass = false

+ 1 - 0
T2-Ej/Ej2-ad-hoc/host_vars/localhost

@@ -0,0 +1 @@
+ansible_connection: smart

+ 7 - 0
T2-Ej/Ej2-ad-hoc/mis_maquinas

@@ -0,0 +1,7 @@
+[produccion]
+servera
+serverd
+[desarrollo]
+serverb
+[sistemas]
+serverc

+ 9 - 0
T2-Ej/Ej4-Playbooks-sencillos/ansible.cfg

@@ -0,0 +1,9 @@
+[defaults]
+inventory = systems
+remote_user = devops
+[privilege_escalation]
+become = true
+become_method = sudo
+become_user = root
+become_ask_pass = false
+ 

+ 9 - 0
T2-Ej/Ej4-Playbooks-sencillos/borra_fichero_hola.yaml

@@ -0,0 +1,9 @@
+- name: Borra fichero hola en los hosts
+  hosts:
+    - all
+    - localhost
+  tasks:
+    - name: borra hola.txt
+      file:
+        path: /tmp/hola.txt
+        state: absent

+ 8 - 0
T2-Ej/Ej4-Playbooks-sencillos/borra_user_pepe.yml

@@ -0,0 +1,8 @@
+- name: Borra al usuario pepe
+  hosts: all
+  tasks:
+    - name: borra pepe y directorio
+      user:
+        name: pepe
+        state: absent
+        remove: true

+ 9 - 0
T2-Ej/Ej4-Playbooks-sencillos/crea_fichero_hola.yaml

@@ -0,0 +1,9 @@
+- name: Crea fichero hola en los hosts
+  hosts:
+    - all
+    - localhost
+  tasks:
+    - name: crea el contenido de hola.txt
+      copy:
+        dest: /tmp/hola.txt
+        content: 'Hola Mundo!'

+ 8 - 0
T2-Ej/Ej4-Playbooks-sencillos/crea_user_pepe.yml

@@ -0,0 +1,8 @@
+- name: Crea el usuario pepe en los hosts
+  hosts: all
+  tasks:
+    - name: crea al usuario pepe
+      user:
+        name: pepe
+        state: present
+

+ 1 - 0
T2-Ej/Ej4-Playbooks-sencillos/host_vars/localhost

@@ -0,0 +1 @@
+ansible_connection: smart

+ 9 - 0
T2-Ej/Ej4-Playbooks-sencillos/modifica_motd.yaml

@@ -0,0 +1,9 @@
+- name: Modifica MOTD en los hosts
+  hosts:
+    - all
+    - localhost
+  tasks:
+    - name: cambia el contenido de MOTD
+      copy:
+        dest: /etc/motd
+        content: 'Sistema gestionado por Ansible'

+ 7 - 0
T2-Ej/Ej4-Playbooks-sencillos/systems

@@ -0,0 +1,7 @@
+[produccion]
+servera.lab.example.com
+serverd.lab.example.com
+[desarrollo]
+serverb.lab.example.com
+[sistemas]
+serverc.lab.example.com

+ 6 - 0
T2-Ej/secrets/datos1.yml

@@ -0,0 +1,6 @@
+$ANSIBLE_VAULT;1.2;AES256;secreto1
+33383063363362646331643032393539643165663964623063663137363464623632353234336565
+3561653562303265313662313966623430633361626263660a323865643734633733366535376363
+38323463336534343762636461396563633232346430373363333162626437313464336135623533
+3131653939383466620a363565316666613036653539356631323035323235363633653230613638
+3966

+ 6 - 0
T2-Ej1/inventario

@@ -0,0 +1,6 @@
+[web]
+servera.lab.example.com
+
+[db]
+serverc.lab.example.com
+serverd.lab.example.com

+ 9 - 0
T5/Ej1/almacena_facts-jinja2.yaml

@@ -0,0 +1,9 @@
+- name: template hosts.j2
+  hosts: all
+  become: true
+  tasks:
+    - name: deploy template
+      template:
+        src: hosts.j2
+        dest: /root/hosts
+      when: inventory_hostname == 'servera'

+ 3 - 0
T5/Ej1/ansible.cfg

@@ -0,0 +1,3 @@
+[defaults]
+remote_user = root
+inventory = inventory

+ 3 - 0
T5/Ej1/hosts.j2

@@ -0,0 +1,3 @@
+{% for host in groups['all'] if inventory_hostname != 'serverd' %}
+{{ hostvars[host]['ansible_facts']['default_ipv4'] }} {{ hostvars[host]['ansible_facts']['fqdn'] }}
+{% endfor %} 

+ 7 - 0
T5/Ej1/inventory

@@ -0,0 +1,7 @@
+[dev]
+servera
+serverd
+
+[prod]
+serverb
+serverc

+ 1 - 0
labo/ansible.cfg

@@ -7,3 +7,4 @@ become=true
 become_method=sudo
 become_user=root
 become_ask_pass=true
+

+ 1 - 1
labo/host_vars/localhost

@@ -1 +1 @@
-ansible_connection = smart
+ansible_connection: smart

+ 22 - 0
labo/magic.yml

@@ -0,0 +1,22 @@
+- name: escupe variables
+  hosts: all
+  gather_facts: yes
+  tasks:
+    - name: facts
+      debug:
+        var: ansible_facts
+    - name: hostvars
+      debug: 
+        var: hostvars
+    - name: groupnames
+      debug:
+        var: group-vars
+    - nema: groups
+      debug:
+        var: groups
+    - name: inventory_hostname
+      debug:
+        var: inventory_hostname
+    - name: ansible_play_hosts
+      debug:
+        var: ansible_play_hosts

+ 1 - 1
labo/set_hosts.yml

@@ -1,5 +1,5 @@
 - name: set /etc/hosts in managed hosts
-  hosts: all
+  hosts: all,localhost
   remote_user: student
   gather_facts: yes
   tasks: