Nested Playbook with dynamic group Variables

Hi,

I am trying to figure out how I could use the vars in one role can be used in another role. Below is init.yaml file which has 2 different plays. I want to use the “env” variable passed in the first play (provision the server) to be used in the second play (config base server). attached the error below. What is the best way to achieve this scenario?

init.yml file


# Provision Server

- hosts: localhost
 gather_facts: no
 connection: local
 become: yes
 become_user: root
 remote_user: root
 vars:
 env: "leo"
 machine_size: 'small'
 machine_type: 'distributed'
 machine_count: 1
 roles:
 - { role: provisioning, tags: ['provisioning'] }

#END Provision Server

# CONFIG BASE SERVER

- hosts: "{{env}}"
 gather_facts: True
 remote_user: root
 become: yes
 roles:
 - { role: kickstart, tags: ['kickstart'] }

# END CONFIG BASE SERVER

`
Error:

fatal: [localhost]: FAILED! => {“failed”: true, “reason”: “Syntax Error while loading YAML.\n\n\nThe error appears to have been
in ‘/Users/pawan/Documents/projects/clc/roles/provisioning/tasks/kickstart.yaml’: line 2, column 11, but may\nbe elsewhere in
the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n—\n- hosts: {{env}}\n ^ here
\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes.
Always quote template expression brackets when they\nstart a value.
For instance:\n\n with_items:\n - {{ foo }}\n\nShould be written as:\n\n with_items:\n - "{{ foo }}"\n”}

`