You could use the assert task to check that the variable exist before starting the run
Get Outlook for iOS<https://aka.ms/o0ukef> ________________________________ From: 'Neil Young' via Ansible Project <[email protected]> Sent: Thursday, January 6, 2022 6:16:28 AM To: Ansible Project <[email protected]> Subject: [ansible-project] Variable state depending on existence of a file on host system - possible? I'm currently having a var in my ./vars/default.yml, which is used at several points in my playbook for branching installation operations. boolean_var: true Depending on this I'm performing (or not) install steps .... when: not boolean_var So far so good. I'm also using this var in some j2 templates like so: {% if boolean_var %} ... {% endif %} My problem is, that I mostly forget to set this variable to a proper state, which reflects the real status on the host system, so I have to abort an update. I would rather like to derive it from a pre_task, checking the existence of a particular file on the host before starting all operations. Is there a way to define a variable with the same scope (playbook and templates) at runtime? -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]<mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/5da6e38e-ae18-4b28-98f9-4341465c2cbfn%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/5da6e38e-ae18-4b28-98f9-4341465c2cbfn%40googlegroups.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/SYBP282MB35259E19C8AA647EF3B46381AD4B9%40SYBP282MB3525.AUSP282.PROD.OUTLOOK.COM.
