Sorry if I don’t follow the community guidelines properly
Im new in Ansible and my english is not good, I want to know if there is any way for provide isolated extra variables (--extra-vars
) from CLI when we use feature ansible.builtin.import_playbook: bbo-network.yaml
. Why I ask this, because without extra variables from CLI, we can make predefine isolate variable for each playbook when include the playbook in others.
Below is how I compose my playbook in bbo-compute-engine.yaml
---
# includes all dependencies
- name: Manage a Network
ansible.builtin.import_playbook: bbo-network.yaml
vars:
with_output: true
include_state: "present"
- name: Manage a External Compute Address
ansible.builtin.import_playbook: bbo-compute-address.yaml
vars:
with_output: true
include_state: "present"
- name: Manage a Compute Disk
ansible.builtin.import_playbook: bbo-compute-disk.yaml
vars:
with_output: true
include_state: "present"
# includes all dependencies
- name: Manage Compute Engine
hosts: localhost
gather_facts: false
vars:
cloud_provider: "gcp"
cloud_provider_resource_type:
- "compute-engine"
cloud_provider_auth:
project_id: "terpusat"
auth_kind: "serviceaccount"
service_acount_token: "../../credential.json"
cloud_provider_resource_detail:
compute_instance:
name: "bbo-instance-01"
zone: "asia-southeast2-a"
machine_type: "n1-standard-1"
can_ip_forward: true
labels:
creator: "dpanel"
environment: "development"
disks:
- auto_delete: 'true'
boot: 'true'
source: "{{ output_compute_disk['bbo-disk-01'] }}"
network_interfaces:
- network: "{{ output_compute_network['default'] }}"
access_configs:
- name: External NAT
nat_ip: "{{ output_compute_address['bbo-external-address-01'] }}"
type: ONE_TO_ONE_NAT
roles:
- role: dpanel.cloud-provider
Then I want to make the variable configurable from CLI, so I try to send variable from CLI with command:
ansible-playbook --extra-vars @/Users/prakasa/Projects/bbo-provision/ansible/extra-variables.json -vv playbooks/staging/bbo-compute-engine.yaml
Unfortunatelly, the method I tried make the variable available globally and replace all variables in included playbook as well. So the imported playbooks lost their isolated condition (all variables totally replaced by --extra-vars).
I expect, when we use --extra-variable
, it is only available for the main playbook, but it’s not.