Subject: [ansible-project] playbook without hosts desribed


On 08.08.2019 03:53, Veera wrote:

You could use this
  hosts: '{{ "" if myvar == "all" else myvar }}'

If myvar is all hosts becomes empty sting and that is not allowed and Ansible will fail.

But this is easily defeated but adding a comma at the end myvar=all,
To fix that you would need to use the search/regex[1] test and craft a appropriate regexp for this.
[1] https://docs.ansible.com/ansible/latest/user_guide/playbooks_tests.html#testing-strings
--
Kai Stian Olstad

--