Kapitel 08: register, conditionals
This commit is contained in:
parent
c497f07565
commit
2e7d8c0e7f
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 }}"
|
||||||
|
|
Loading…
Reference in a new issue