I am running Ansible 2.9.7 and am looking at the dynamic inventory scripts. I don’t have any of the various software listed (AWS, OpenStack etc) in the examples section and I need something where I can automatically set the remote IP address at the time that the playbook is executed, ideally after prompting the user for this information.
I have managed to craft together a simple Python script with hard-coded data (for test purposes) but I cannot fathom the output, other than it should be in JSON format. Nor can I find this documented anywhere.
Does anyone have any ideas, suggestions or pointers?
Failing that, can you suggest a way to do what I want, ask the user for the IP address of the remote server and also the software they want to install? (Yeah I know, two questions instead of one:-) )
... ideally after prompting the user for this information.
... ask the user for the IP address of the remote server and also the
software they want to install?
This is an example of the playbook you might be looking for, I think
- hosts: localhost
gather_facts: false
vars_prompt:
- name: "remote_host"
prompt: "Enter FQDN or OP of the remote host"
private: no
- name: "pkg"
prompt: "Enter name of the package"
private: no
tasks:
- add_host:
hostname: "{{ remote_host }}"
groups: my_group_01
sw: "{{ pkg }}"
Thanks for the response Vladimir. I had actually found and tried using that code, it works fine for a single prompt but not for two, or at least not where there second input variable is used in a role name. I was after: