On Thu, 12 Oct 2023 at 15:41, Y.G Kumar <ygkuma...@gmail.com> wrote: > Hi All, > > I am declaring an environment variables in a playbook as shown below: > -- > --- > - hosts: localhost > environment: > script_var1: hi > script_var2: there > tasks: > - name: List > shell: bash test.sh > -- > > I want to test the existence of the above environment variables in a > separate task.yml file. How do I test their existence ? What is the syntax > ? >
Testing for existence means (in ansible terms) that you check if they're defined. If you just want to make sure they're defined, you could use the assert module: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/assert_module.html ansible.builtin.assert: that: - script_var1 is defined - script_var2 is defined etc You say "separate task.yml file" - but what you have is not a task file but a playbook. If you want to have the assert task in another file, then you should create that and then import that in your main playbook. For example: - tasks: - import_tasks: separate.yml -- > 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 ansible-project+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/1e7a8869-6360-4396-95e6-cd6f078dcd24n%40googlegroups.com > <https://groups.google.com/d/msgid/ansible-project/1e7a8869-6360-4396-95e6-cd6f078dcd24n%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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAF8BbLavbEmYiB9b3Bhm7%2BfNApV4CPNK4DOgXR9dfdgXHFJ_yg%40mail.gmail.com.