Hi
Can we run a playbook and have it prompt the user for the hostname to deploy the playbook tasks to?
This is what I have tried in my playbook.
Hi
Can we run a playbook and have it prompt the user for the hostname to deploy the playbook tasks to?
This is what I have tried in my playbook.
I don’t know if this will help, but I never prompt for a host, and never define one in my playbooks with anything other than a variable:
ie.
`
I believe your problem is that you are specifying hosts twice. The following works for me (gather facts is enabled for this example (to check ansible_fqdn), but wouldn’t be necessary for this to work):
`
Hi
sorry for late response. Actually, I have found a way that works for me, and I hope can help others looking for the same thing. I found this solution elsewhere on the Internet as well. Basically, it seems hosts cannot take in a variable that is just defined, so the way around this is to have hosts reference a dynamic group, and then have the inputted hostname be added to the group via the add_hosts task
I am trying to pass 2 switch IP’s to get the available ports on both the switches. When I am trying to pass one switch IP, It is executing fine. When i am trying to pass 2 IP’s separating by split “SPACE” it is only executing on First switch IP.But not taking the second IP. Please see execution output and respective playbook
---
- hosts: localhost
gather_facts: False
vars_prompt:
- name: ip_addr
prompt: Please enter the switch name
private: no
vars_files:
- ../vars/password.yml
tasks:
- add_host:
name : "{{ item }}"
groups: dynamically_created_hosts
with_items: "{{ip_addr.split(' ')}}"
- name: display all available ports
display_available_ports:
switch_ip: "{{ip_addr}}"
user: "{{user}}"
password: "{{password}}"
vfid: -1
register: result
- debug: var=result
[root@san1 working]# ansible-playbook port_available_test.yml
Please enter the switch name: 17.16.15.16
PLAY [localhost] ********************************************************************************************************************************************
TASK [add_host] *********************************************************************************************************************************************
changed: [localhost] => (item=17.16.15.16)
TASK [display all available ports] **************************************************************************************************************************
ok: [localhost]
TASK [debug] ************************************************************************************************************************************************
ok: [localhost] => {
"result": {
"available_ports": [
{
"name": "0/1",
"port-type": "F_PORT"
},
{
"name": "0/2",
"port-type": "F_PORT"
}
],
"changed": false,
"failed": false
}
}
PLAY RECAP **************************************************************************************************************************************************
localhost : ok=3 changed=1 unreachable=0 failed=0
[root@san1 working]# ansible-playbook port_available_test.yml
Please enter the switch name: 17.16.15.16 17.16.15.17
PLAY [localhost] ********************************************************************************************************************************************
TASK [add_host] *********************************************************************************************************************************************
changed: [localhost] => (item=17.16.15.16)
changed: [localhost] => (item=17.16.15.17)
TASK [display all available ports] **************************************************************************************************************************
ok: [localhost]
TASK [debug] ************************************************************************************************************************************************
ok: [localhost] => {
"result": {
"available_ports": [
{
"name": "0/1",
"port-type": "F_PORT"
},
{
"name": "0/2",
"port-type": "F_PORT"
}
],
"changed": false,
"failed": false
}
}
PLAY RECAP **************************************************************************************************************************************************
localhost : ok=3 changed=1 unreachable=0 failed=0