need help in passing external variables using vars_prompt
working example i have a list of servers in a vars_file lparlist.yml
i need to use vars_prompt so i can provide the server name without editing
the playbook every time
working example
*inventory*
cat inventory
[hmc]
hmc1
hmc2
*vars_file*
cat lparlist.yml
---
- lpar1:
hmc: hmc1
ms: ms1
- lpar2:
hmc: hmc2
ms: ms2
*actual playbook:*
---
- name: Start a logical partition
hosts: "{{ lpar1.hmc }}"
collections:
- ibm.power_hmc
connection: local
vars_files:
- lparlist.yml
vars:
curr_hmc_auth:
username: username
password: password
tasks:
- name: Start a logical partition.
powervm_lpar_instance:
hmc_host: "{{ lpar1.hmc }}"
hmc_auth: "{{ curr_hmc_auth }}"
system_name: "{{ lpar1.ms }}"
vm_name: lpar1
action: poweron
*output*
PLAY [Start a logical partition]
*******************************************************************************************************************************************************************************
TASK [Gathering Facts]
********************************************************************************************************************************************************************************************
ok: [hmc1]
TASK [Start a logical partition.]
******************************************************************************************************************************************************************************
changed: [hmc1]
PLAY RECAP
********************************************************************************************************************************************************************************************************
hmc1 : ok=2 changed=1 unreachable=0 failed=0
skipped=0 rescued=0 ignored=0
*not working playbook*
---
- name: Start a logical partition
hosts: "{{ lpar1.hmc }}"
vars_prompt:
- name: target
prompt: Enter Server Name
private: false
collections:
- ibm.power_hmc
connection: local
vars_files:
- lparlist.yml
vars:
curr_hmc_auth:
username: username
password: password
tasks:
- name: Start a logical partition.
powervm_lpar_instance:
hmc_host: "{{ target.hmc }}"
hmc_auth: "{{ curr_hmc_auth }}"
system_name: "{{ target.ms }}"
vm_name: "{{ target }}"
action: poweron
*output*
PLAY [Start a logical partition]
*******************************************************************************************************************************************************************************
TASK [Gathering Facts]
********************************************************************************************************************************************************************************************
ok: [hmc1]
TASK [Start a logical partition.]
******************************************************************************************************************************************************************************
fatal: [hmc1]: FAILED! => {"msg": "The task includes an option with an
undefined variable. The error was: 'unicode object' has no attribute
'ms'\n\nThe error appears to be in '/home/inampk48/hmc/p3/poweron.yml':
line 17, column 7, but may\nbe elsewhere in the file depending on the exact
syntax problem.\n\nThe offending line appears to be:"\n - name: Start a
logical partition.\n ^ here\n"}
PLAY RECAP
********************************************************************************************************************************************************************************************************
hmc1 : ok=1 changed=0 unreachable=0 failed=1
skipped=0 rescued=0 ignored=0
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/7bcebfbc-93df-4efa-858c-df9ed8f0be0cn%40googlegroups.com.