79525980

Date: 2025-03-21 16:01:53
Score: 2
Natty:
Report link

Thank you very much @β.εηοιτ.βε. Your answer pointed me to the good documentation.

And I found vars[item] to complete my research (here Ansible: how to construct a variable from another variable and then fetch it's value).

Thus my last version, that works with a list of variables :

---
- name: Playbook to try assert module
  hosts: all
  gather_facts: false

  vars:
    mandatories:
      - variableA
      - variableB
      - variableThatDoesNotExist

  tasks:
    - name: Check mandatory variableA
      assert:
        quiet: false
        that:
          - variableA is defined
          - variableA | length > 0

    - name: Check mandatory variableB
      assert:
        quiet: false
        that:
          - variableB is defined
          - variableB | length > 0

    - name: Check mandatory variables with loop
      assert:
        quiet: false
        that:
          - vars[item] is defined
          - vars[item] | length > 0
      loop: "{{ mandatories }}"

    - meta: end_play
Reasons:
  • Blacklisted phrase (0.5): Thank you
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Michel Briand