diff --git a/08/copy_3files_debug.yml b/08/copy_3files_debug.yml new file mode 100644 index 0000000..fded4dc --- /dev/null +++ b/08/copy_3files_debug.yml @@ -0,0 +1,11 @@ +--- +- hosts: localhost + tasks: + - name: "[DEBUG] Copy 3 files" + ansible.builtin.debug: + msg: "src={{ item.0 }} dest={{ item.1 }}" + loop: + - [config1.cfg, /etc/config1.cfg] + - [config2.cfg, /etc/config2.cfg] + - [config3.cfg, /etc/daemon/config3.cfg] + diff --git a/08/copy_3files_debug_filter.yml b/08/copy_3files_debug_filter.yml new file mode 100644 index 0000000..21e453d --- /dev/null +++ b/08/copy_3files_debug_filter.yml @@ -0,0 +1,11 @@ +--- +- hosts: localhost + tasks: + - name: "[DEBUG] Copy 3 files" + ansible.builtin.debug: + msg: "src={{ item|basename }} dest={{ item }}" + loop: + - /etc/config1.cfg + - /etc/config2.cfg + - /etc/daemon/config3.cfg + diff --git a/08/loop_include.yml b/08/loop_include.yml new file mode 100644 index 0000000..d37e418 --- /dev/null +++ b/08/loop_include.yml @@ -0,0 +1,10 @@ +--- +- hosts: localhost + tasks: + - include_tasks: loop_include_sub.yml + loop: + - Aussen-1 + - Aussen-2 + loop_control: + loop_var: outer + diff --git a/08/loop_include_sub.yml b/08/loop_include_sub.yml new file mode 100644 index 0000000..3b9abc3 --- /dev/null +++ b/08/loop_include_sub.yml @@ -0,0 +1,9 @@ +--- +- debug: "msg='Innen: {{ item }}, Außen: {{ outer }} - {{ loop_index }}'" + loop: + - Innen-1 + - Innen-2 + loop_control: + label: "Aktueller Durchlauf {{ item }} - {{ loop_index }}" + index_var: loop_index + diff --git a/08/template-loop.yml b/08/template-loop.yml new file mode 100644 index 0000000..cd1bdce --- /dev/null +++ b/08/template-loop.yml @@ -0,0 +1,7 @@ +--- +- hosts: localhost + gather_facts: no + + roles: + - template-loop + diff --git a/08/uebung_lookup.yml b/08/uebung_lookup.yml new file mode 100644 index 0000000..515cf06 --- /dev/null +++ b/08/uebung_lookup.yml @@ -0,0 +1,38 @@ +--- +- hosts: localhost + gather_facts: no + + tasks: + - name: File-Loopup /etc/timezone + debug: + msg: "/etc/timezone: {{ lookup('file', '/etc/timezone') }}" + + - name: Password-Lookup 1 + debug: + msg: "Passwort: {{ lookup('password', '/tmp/.secret.pw') }}" + + - name: Password-Lookup 2 + debug: + msg: "Passwort: {{ lookup('password', '/tmp/.secret.pw') }}" + + - name: rm /tmp/.secret.pw + file: + dest: /tmp/.secret.pw + state: absent + + - name: Password-Lookup 3 + debug: + msg: "Passwort: {{ lookup('password', '/tmp/.secret.pw') }}" + + - name: Password-Lookup 4 + debug: + msg: "Passwort: {{ lookup('password', '/tmp/.secret.pw') }}" + + - name: dig-Lookup + debug: + var: "lookup('dig', 'heinlein-akademie.de', 'qtype=MX')" + + - name: dig-Query + debug: + var: "query('dig', 'heinlein-akademie.de', 'qtype=MX')" + diff --git a/helper/08_packages.sh b/helper/08_packages.sh new file mode 100755 index 0000000..8d4e627 --- /dev/null +++ b/helper/08_packages.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +sudo apt install --no-install-recommends --yes \ + python3-dnspython \ + diff --git a/roles/template-loop/tasks/main.yml b/roles/template-loop/tasks/main.yml new file mode 100644 index 0000000..cb6ddbd --- /dev/null +++ b/roles/template-loop/tasks/main.yml @@ -0,0 +1,32 @@ +--- +# Template-Dateien: +# template-loop/templates/etc/abc.conf +# template-loop/templates/usr/local/share/abc.conf +# template-loop/templates/var/lib/abc.conf + +- name: Template-Loop mit relativen Pfaden + debug: + msg: "Template-Argumente: src={{ item }} dest=/{{ item }} ..." + loop: + - etc/abc.conf + - usr/local/share/abc.conf + - var/lib/abc.conf + +- name: Template-Loop mit absoluten Pfaden + debug: + msg: "Template-Argumente: src={{ item|replace('/', '', count=1) }} dest={{ item }} ..." + loop: + - /etc/abc.conf + - /usr/local/share/abc.conf + - /var/lib/abc.conf + +- name: Template-Loop mit Mapping + debug: + msg: "Template-Argumente: src={{ item.key }} dest={{ item.value }} ..." + loop: "{{ configfiles|dict2items }}" + vars: + configfiles: + etc.conf: /etc/abc.conf + share.conf: /usr/local/share/abc.conf + lib.conf: /var/lib/abc.conf + diff --git a/roles/template-loop/templates/etc.conf b/roles/template-loop/templates/etc.conf new file mode 100644 index 0000000..e69de29 diff --git a/roles/template-loop/templates/etc/abc.conf b/roles/template-loop/templates/etc/abc.conf new file mode 100644 index 0000000..e69de29 diff --git a/roles/template-loop/templates/lib.conf b/roles/template-loop/templates/lib.conf new file mode 100644 index 0000000..e69de29 diff --git a/roles/template-loop/templates/share.conf b/roles/template-loop/templates/share.conf new file mode 100644 index 0000000..e69de29 diff --git a/roles/template-loop/templates/usr/local/share/abc.conf b/roles/template-loop/templates/usr/local/share/abc.conf new file mode 100644 index 0000000..e69de29 diff --git a/roles/template-loop/templates/var/lib/abc.conf b/roles/template-loop/templates/var/lib/abc.conf new file mode 100644 index 0000000..e69de29