Kapitel 08: register/ignore_errors
This commit is contained in:
parent
e0f5beb46d
commit
559128450c
12
08/grep_einfach.yml
Normal file
12
08/grep_einfach.yml
Normal file
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
- hosts: localhost
|
||||
gather_facts: no
|
||||
|
||||
tasks:
|
||||
- name: grep aufrufen
|
||||
command: grep root /etc/passwd
|
||||
register: output
|
||||
|
||||
- name: Rückgabe ausgeben
|
||||
debug: var=output
|
||||
|
13
08/grep_einfach_fehler.yml
Normal file
13
08/grep_einfach_fehler.yml
Normal file
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
- hosts: localhost
|
||||
gather_facts: no
|
||||
|
||||
tasks:
|
||||
- name: grep aufrufen
|
||||
command: grep toor /etc/passwd
|
||||
register: output
|
||||
ignore_errors: true
|
||||
|
||||
- name: Rückgabe ausgeben
|
||||
debug: var=output
|
||||
|
25
08/grep_username.yml
Normal file
25
08/grep_username.yml
Normal file
|
@ -0,0 +1,25 @@
|
|||
---
|
||||
- hosts: localhost
|
||||
gather_facts: no
|
||||
|
||||
tasks:
|
||||
- name: Variable muss definiert sein
|
||||
assert:
|
||||
that:
|
||||
- username is defined
|
||||
|
||||
- name: Rufe grep auf
|
||||
command: 'grep {{ username }} /etc/passwd'
|
||||
register: result
|
||||
ignore_errors: True
|
||||
|
||||
- name: "{{ username }} existiert"
|
||||
debug:
|
||||
msg: '{{ username }} exists'
|
||||
when: result is success
|
||||
|
||||
- name: "{{ username }} existiert nicht"
|
||||
debug:
|
||||
msg: '{{ username }} does not exist'
|
||||
when: result is failed
|
||||
|
18
08/var_definiert_oder_nicht.yml
Normal file
18
08/var_definiert_oder_nicht.yml
Normal file
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
- hosts: localhost
|
||||
gather_facts: no
|
||||
|
||||
tasks:
|
||||
- debug:
|
||||
msg: "{{ inhalt }}"
|
||||
when: inhalt|default(False)
|
||||
|
||||
- debug:
|
||||
msg: "Variable nicht definiert"
|
||||
when: inhalt is not defined
|
||||
|
||||
- debug:
|
||||
msg:
|
||||
- "inhalt|default(False) → {{ inhalt|default(False) }} → {{ inhalt|default(False)|bool }}"
|
||||
- "inhalt is not defined → {{ inhalt is not defined }} → {{ inhalt is not defined|bool }}"
|
||||
|
13
08/weiteres/debug1.yml
Normal file
13
08/weiteres/debug1.yml
Normal file
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
- hosts: localhost
|
||||
|
||||
tasks:
|
||||
- command: grep root /etc/passwd
|
||||
register: output
|
||||
|
||||
- debug:
|
||||
var: output
|
||||
|
||||
- debug:
|
||||
var: output.stdout
|
||||
|
14
08/weiteres/debug2.yml
Normal file
14
08/weiteres/debug2.yml
Normal file
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
- hosts: localhost
|
||||
|
||||
tasks:
|
||||
- command: grep toor /etc/passwd
|
||||
register: output
|
||||
ignore_errors: yes
|
||||
|
||||
- debug:
|
||||
var: output
|
||||
|
||||
- debug:
|
||||
var: output.stdout
|
||||
|
9
08/weiteres/debug_folie.yml
Normal file
9
08/weiteres/debug_folie.yml
Normal file
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
- hosts: localhost
|
||||
tasks:
|
||||
- command: grep root2 /etc/passwd
|
||||
register: output
|
||||
ignore_errors: True
|
||||
|
||||
- debug: var=output
|
||||
|
18
08/weiteres/debug_zusammen.yml
Normal file
18
08/weiteres/debug_zusammen.yml
Normal file
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
- hosts: localhost
|
||||
|
||||
tasks:
|
||||
- command: grep root /etc/passwd
|
||||
register: abc1
|
||||
ignore_errors: yes
|
||||
|
||||
- command: grep toor /etc/passwd
|
||||
register: abc2
|
||||
ignore_errors: yes
|
||||
|
||||
- debug:
|
||||
msg: "{{ abc1.failed }} --- {{ abc2.failed }}"
|
||||
|
||||
- debug:
|
||||
msg: "{{ abc1 is failed }} --- {{ abc2 is failed }}"
|
||||
|
18
extra/changed_failed_when.yml
Normal file
18
extra/changed_failed_when.yml
Normal file
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
- hosts:
|
||||
- tn00-debian12
|
||||
- tn00-alpine3i
|
||||
|
||||
gather_facts: no
|
||||
|
||||
tasks:
|
||||
- name: "Gebe CHANGED zurück, wenn /etc/hostname den String 'debian' enthält"
|
||||
command: cat /etc/hostname
|
||||
register: output
|
||||
changed_when: '"debian" in output.stdout'
|
||||
|
||||
- name: "Gebe FAILED zurück, wenn /etc/hostname den String 'alpine' enthält"
|
||||
command: cat /etc/hostname
|
||||
register: output
|
||||
failed_when: '"alpine" in output.stdout'
|
||||
|
9
extra/changed_when.yml
Normal file
9
extra/changed_when.yml
Normal file
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
- hosts: all
|
||||
gather_facts: no
|
||||
|
||||
tasks:
|
||||
- command: cat /etc/hosts
|
||||
register: output
|
||||
changed_when: '"ubu" in output.stdout'
|
||||
|
26
extra/ein_rechner_failed.yml
Normal file
26
extra/ein_rechner_failed.yml
Normal file
|
@ -0,0 +1,26 @@
|
|||
---
|
||||
- hosts:
|
||||
- tn00-debian12
|
||||
- tn00-alpine3i
|
||||
|
||||
gather_facts: no
|
||||
|
||||
tasks:
|
||||
- name: Debian bricht ab
|
||||
debug:
|
||||
msg: "Hallo"
|
||||
failed_when: '"debian" in inventory_hostname'
|
||||
|
||||
|
||||
- hosts:
|
||||
- tn00-debian12
|
||||
- tn00-alpine3i
|
||||
|
||||
gather_facts: no
|
||||
|
||||
tasks:
|
||||
- name: "Wer lebt noch?"
|
||||
debug:
|
||||
msg: "Lebenszeichen"
|
||||
|
||||
|
8
extra/wireguard-key-anlegen_changed_when.yml
Normal file
8
extra/wireguard-key-anlegen_changed_when.yml
Normal file
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
- hosts: localhost
|
||||
gather_facts: no
|
||||
tasks:
|
||||
- shell: "[ ! -f wg.pub ] && wg genkey | tee wg.priv | wg pubkey | tee wg.pub || true"
|
||||
register: output
|
||||
changed_when: output.stdout != ""
|
||||
|
8
extra/wireguard-key-anlegen_creates.yml
Normal file
8
extra/wireguard-key-anlegen_creates.yml
Normal file
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
- hosts: localhost
|
||||
gather_facts: no
|
||||
tasks:
|
||||
- shell: "wg genkey | tee wg.priv | wg pubkey | tee wg.pub"
|
||||
args:
|
||||
creates: wg.pub
|
||||
|
Loading…
Reference in a new issue