When running the ansible playbook, i am providing the extra vars especially for modules variable where i am passing multiple values.
ansible-playbook abc.yml --extra-vars "status=enable modules='redis apache zookeeper'"
I want to run the below task when the modules in extra vars has "redis"
- name: fetch ports
shell: ll | grep -i "ports"
when: modules == "redis"
However, the above task is getting skipped even when the module in extra vars has "redis". Any help would be appreciated.
the modules
variable you supplied is a string, you have 2 options:
redisv2 apache zookeeper
.for the 2nd option, here is how to do it:
- name: fetch ports
shell: ll | grep -i "ports"
when: '"redis" in modules.split(" ")'
hope it helps.