Ich habe eine Rolle, die ich mehrmals ausführen möchte, jede Ausführung mit einer anderen Var. Ich möchte jedoch auch, dass einige dieser Hinrichtungen bedingt sind. HierBedingte Ansible-Rollen schlagen fehl, wenn sie bereits ausgeführt wurden
ist ein main.yml:
- hosts: localhost
roles:
- { role: test, test_files_group: 'a'}
- { role: test, test_files_group: 'b', when: False}
Hier ist die main.yml aus der 'Test' Rolle (roles/test/tasks/main.yml
):
- name: List files
command: "find . ! -path . -type f"
args:
chdir: "{{ role_path }}/files/{{ test_files_group }}"
register: files
- debug: var=files.stdout_lines
- name: do something with the files
shell: "echo {{ item }}"
with_items: "{{ files.stdout_lines }}"
Und hier ist ein Teil des ansible-Textbuch Befehlsausgabe:
TASK [test : List files]
*******************************************************
changed: [localhost]
TASK [test : debug] ************************************************************
ok: [localhost] => {
"files.stdout_lines": [
"./testfile-a"
]
}
TASK [test : do something with the files] **************************************
changed: [localhost] => (item=./testfile-a)
TASK [test : List files] *******************************************************
skipping: [localhost]
TASK [test : debug] ************************************************************
skipping: [localhost]
TASK [test : do something with the files] **************************************
fatal: [localhost]: FAILED! => {"failed": true, "msg": "'dict object' has no attribute 'stdout_lines'"}
Alles funktioniert für 'a' wie erwartet, aber dann die do something with the files
ta sk wird für b ausgeführt, obwohl ich when: False
gesetzt habe.
Ich fühle mich wie ich etwas vermisse - was ich will ist für alles in roles/test/tasks/main.yml
ausgeführt werden mit der test_files_group
var entsprechend eingestellt, oder gar nicht. Was mache ich falsch? :)
brilliant, danke! – Mark