Reputation: 37
Is this possible? I have a playbook looking like this:
vars: BDNAME: ""
- name: Add a tenant using a JSON string
aci_bd:
tenant: "common"
bd: "{{ BDNAME }}"
vrf: "PIGGE"
hostname: '1.1.1.1'
username: "x"
password: "x"
use_ssl: yes
validate_certs: false
It works if i provide an extra variable in the commandline:
ansible-playbook apic.yml -i server.yml --extra-vars BDNAME='pooh'
Then BDNAME gets the value pooh. But is there any way that i can define pooh as a variable. So if i run the playbook like i just did, BDNAME get the value of that variable.
So something like vars: BDNAME: "" POOH: nisse
Then BDNAME should be nisse.
Upvotes: 3
Views: 861
Reputation: 1930
Define BDNAME in playbook directly from the extra variable POOH. That should do what you want. But it would be easier to use POOH instead of BDNAME.
Here is a example playbook:
---
- hosts: localhost
vars:
BDNAME: "{{ POOH }}"
tasks:
- name: print BDNAME
debug:
msg: "{{ BDNAME }}"
if you call it with:
ansible-playbook playbook.yml -e '{"POOH": "Oliver"}'
you will see:
TASK [print BDNAME] **********************************************************************************************************************************************************************************************************************************************************
ok: [localhost] => {
"changed": false,
"msg": "Oliver"
}
Upvotes: 1