Browse Source

Teil 11 Loops

master
Olli Graf 1 week ago
parent
commit
a9f3b8347f
  1. 2
      .gitignore
  2. 8
      loop.yml
  3. 7
      loop_files.yml
  4. 8
      noloop.yml
  5. 7
      roles/loop/tasks/main.yml
  6. 21
      roles/noloop/tasks/main.yml
  7. 10
      roles/subtasks/setuploop.yml
  8. 13
      roles/with_items/tasks/main.yml
  9. 8
      with_items.yml

2
.gitignore

@ -0,0 +1,2 @@
test

8
loop.yml

@ -0,0 +1,8 @@
- hosts: "{{ target }}"
vars_files:
- loop_files.yml
gather_facts: false
remote_user: pi
roles:
- loop

7
loop_files.yml

@ -0,0 +1,7 @@
testfiles:
- test1.txt
- test1.json
- test2.txt
- test3.txt
- test4.dat

8
noloop.yml

@ -0,0 +1,8 @@
- hosts: "{{ target }}"
vars_files:
- loop_files.yml
gather_facts: false
remote_user: pi
roles:
- noloop

7
roles/loop/tasks/main.yml

@ -0,0 +1,7 @@
- include: ../subtasks/setuploop.yml
- name: erzeuge Testdateien
ansible.builtin.file:
path: "test/{{ item }}"
state: touch
loop: "{{ testfiles }}"

21
roles/noloop/tasks/main.yml

@ -0,0 +1,21 @@
- include: ../subtasks/setuploop.yml
- name: erzeuge test1.txt
ansible.builtin.file:
path: "test/test1.txt"
state: touch
- name: erzeuge test1.json
ansible.builtin.file:
path: "test/test1.json"
state: touch
- name: erzeuge test2.txt
ansible.builtin.file:
path: "test/test2.txt"
state: touch
- name: erzeuge test3.txt
ansible.builtin.file:
path: "test/test3.txt"
state: touch
- name: erzeuge testr4.dat
ansible.builtin.file:
path: "test/test4.dat"
state: touch

10
roles/subtasks/setuploop.yml

@ -0,0 +1,10 @@
---
- name: create test dir
ansible.builtin.file:
path: test
state: directory
- name: delete test files
ansible.builtin.file:
path: "test/*"
state: absent

13
roles/with_items/tasks/main.yml

@ -0,0 +1,13 @@
- include: ../subtasks/setuploop.yml
- name: erzeuge Testdateien
ansible.builtin.file:
path: "test/{{ item }}"
state: touch
with_items:
- test1.txt
- test1.json
- test2.txt
- test3.txt
- test4.dat

8
with_items.yml

@ -0,0 +1,8 @@
- hosts: "{{ target }}"
vars_files:
- loop_files.yml
gather_facts: false
remote_user: pi
roles:
- with_items
Loading…
Cancel
Save