---
- hosts: localhost
gather_facts: false
vars:
neo4j:
name: neo4j
api_service:
name: api_service
pid: /var/api/pid
tasks:
- debug:
msg: "{{item.pid|default('/var/run/{{item.name}}/{{item.name}}.pid')}}"
You cant't nest {{ }}
with_items:
- "{{ vars[service] }}"ansible-playbook play.yml --extra-vars service=api-service
how will I debug both dictionaries?
I know that I can't give
--extra-vars service=api-service,neo4j or as a llistor is there any way to dynamically iterate using user given dictionaries.
You could do something like this
- debug:
msg: "{{ vars[item].pid | default('/var/run/' ~ vars[item].name ~ '/' ~ vars[item].name ~ '.pid')}}"
with_items:
- "{{ service.split(',') }}"
And then you can use a comma separated values in --extra-vars