What I want is set the priority of variables. I am passing the variable from inventory file and if the variable is not defined in inventory file then it should ask for user prompt. I am trying to use vars_prompt but when i run the playbook it directly gives me prompt and ask for the value, it doesn't checks in inventory file. So, I want first it should check the inventory file and if variable is not defined there and it should prompt me for the value on console. If ansible doesn't support this, then can we use shell or command module for this. Any help will be appreciated
Below is my playbook. and inventory file I am using ansible version 1.6 Inventory file
[test]
X.X.X.X cr="12"
Playbook
name: -> Apply common configuration to {{ target }} nodes hosts: "{{ target }}" gather_facts: True
user: root
pre_tasks:
name: -> Is cr defined??
fail: msg="Please make sure the variables 'cr' is specified in inventory host file"
when: (cr is not defined)
register: cr_value
vars_prompt:
name: cr
prompt: "Please mention the cr id"
private: no
when: cr_value|failed
name: Print the value of cr
debug: msg="{{ cr }}"