LOGBOOK

HELP

Quiz Entry - updated: 2026.11.12

How does the lab copy the certificate and the key with one looped task, and what goes wrong if you follow the text literally and loop over web_config_files?

The play defines ssl_config_files, a list of two dictionaries with src and dest; the copy task loops over it and uses item['src'] and item['dest']. web_config_files is never defined, so a loop over it fails with an undefined-variable error.

vars:
  ssl_cert:
    src: files/itia.crt
    dest: "{{ ssl_cert_dir }}/itia.crt"
  ssl_key:
    src: files/itia.key
    dest: "{{ ssl_key_dir }}/itia.key"
  ssl_config_files:
    - "{{ ssl_cert }}"
    - "{{ ssl_key }}"
- name: Konfigurationsdateien kopieren
  ansible.builtin.copy:
    src: "{{ item['src'] }}"
    dest: "{{ item['dest'] }}"
  loop: "{{ ssl_config_files }}"
  notify: Restart web service

Each element bundles a source and a destination, so the two values for one file can't get mixed up. The task text asks to loop over web_config_files, but that name exists nowhere in the playbook; the code uses ssl_config_files.

Note that the variables refer to each other: ssl_cert['dest'] uses ssl_cert_dir from the variables file. Ansible templates variables lazily, when they are used, so the order of definition doesn't matter as long as every name exists by the time the task runs.

A related slip: the play loads vars_files: lhe_vars.yml, but the file is created in the vars subfolder. vars_files paths are relative to the playbook's directory, so the entry has to be vars/lhe_vars.yml, as in the vault lab; otherwise Ansible can't find the file and the play stops before its first task.

Go deeper:

From Quiz: ITIA / Ansible Task Control: Loops, Conditionals, Handlers and Error Handling | Updated: Nov 12, 2026