Upload var_files based on a value or ignore if not exist

  • hosts: server1
    vars_files:
  • main.yml
  • second.yml

Hi,

I have a a small playbook that is using variables based on a file.

Main.yml the file will always exist while second.yml might exist.

  1. Is it possible to configure the playbook to continue in case second.yml file does not existt?

  2. If I will add to the main. yam the following value

Additional_file: yes

Can I configure the playbook to load second.yml only in case Additional_file value = yes

Thanks

Add a stat task first and only include the file if it’s there