Make a Array in ansible by user Prompt
up vote
0
down vote
favorite
I want to make an array in ansible where the user can enter items too.
For example :
The user should be able to enter the applications one by one and I want to save the application in an array.
Tried the following playbook but does not work
- hosts: TestServer
vars_prompt:
- name: "application_list"
prompt: "Please specify the applications"
private: "No"
loop: 'length'
tasks:
- set_fact:
application_list: "{{ application_lists | default()"
- name:
with_items : 'application_lists'
debug :
msg: "application_list"
I am very new to ansible please help. Thanks in advance.
ansible ansible-facts
add a comment |
up vote
0
down vote
favorite
I want to make an array in ansible where the user can enter items too.
For example :
The user should be able to enter the applications one by one and I want to save the application in an array.
Tried the following playbook but does not work
- hosts: TestServer
vars_prompt:
- name: "application_list"
prompt: "Please specify the applications"
private: "No"
loop: 'length'
tasks:
- set_fact:
application_list: "{{ application_lists | default()"
- name:
with_items : 'application_lists'
debug :
msg: "application_list"
I am very new to ansible please help. Thanks in advance.
ansible ansible-facts
What about just having your users put data into a vars file and then including that with-e @myfile.yml
?
– larsks
Nov 9 at 21:20
thanks for your comment but i need the it be done through vars_prompt, is there a way i can acheive this ?? please help
– Azmy
Nov 9 at 21:25
vars_prompt
isn't a task, so you can'tloop
it the way you're trying. You could ask the user for a comma-separated list of applications and then split the response.
– larsks
Nov 9 at 21:27
if i do split as you said how do i access each word splitted?
– Azmy
Nov 9 at 21:46
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to make an array in ansible where the user can enter items too.
For example :
The user should be able to enter the applications one by one and I want to save the application in an array.
Tried the following playbook but does not work
- hosts: TestServer
vars_prompt:
- name: "application_list"
prompt: "Please specify the applications"
private: "No"
loop: 'length'
tasks:
- set_fact:
application_list: "{{ application_lists | default()"
- name:
with_items : 'application_lists'
debug :
msg: "application_list"
I am very new to ansible please help. Thanks in advance.
ansible ansible-facts
I want to make an array in ansible where the user can enter items too.
For example :
The user should be able to enter the applications one by one and I want to save the application in an array.
Tried the following playbook but does not work
- hosts: TestServer
vars_prompt:
- name: "application_list"
prompt: "Please specify the applications"
private: "No"
loop: 'length'
tasks:
- set_fact:
application_list: "{{ application_lists | default()"
- name:
with_items : 'application_lists'
debug :
msg: "application_list"
I am very new to ansible please help. Thanks in advance.
ansible ansible-facts
ansible ansible-facts
edited Nov 9 at 21:09
lgwilliams
521317
521317
asked Nov 9 at 21:07
Azmy
32
32
What about just having your users put data into a vars file and then including that with-e @myfile.yml
?
– larsks
Nov 9 at 21:20
thanks for your comment but i need the it be done through vars_prompt, is there a way i can acheive this ?? please help
– Azmy
Nov 9 at 21:25
vars_prompt
isn't a task, so you can'tloop
it the way you're trying. You could ask the user for a comma-separated list of applications and then split the response.
– larsks
Nov 9 at 21:27
if i do split as you said how do i access each word splitted?
– Azmy
Nov 9 at 21:46
add a comment |
What about just having your users put data into a vars file and then including that with-e @myfile.yml
?
– larsks
Nov 9 at 21:20
thanks for your comment but i need the it be done through vars_prompt, is there a way i can acheive this ?? please help
– Azmy
Nov 9 at 21:25
vars_prompt
isn't a task, so you can'tloop
it the way you're trying. You could ask the user for a comma-separated list of applications and then split the response.
– larsks
Nov 9 at 21:27
if i do split as you said how do i access each word splitted?
– Azmy
Nov 9 at 21:46
What about just having your users put data into a vars file and then including that with
-e @myfile.yml
?– larsks
Nov 9 at 21:20
What about just having your users put data into a vars file and then including that with
-e @myfile.yml
?– larsks
Nov 9 at 21:20
thanks for your comment but i need the it be done through vars_prompt, is there a way i can acheive this ?? please help
– Azmy
Nov 9 at 21:25
thanks for your comment but i need the it be done through vars_prompt, is there a way i can acheive this ?? please help
– Azmy
Nov 9 at 21:25
vars_prompt
isn't a task, so you can't loop
it the way you're trying. You could ask the user for a comma-separated list of applications and then split the response.– larsks
Nov 9 at 21:27
vars_prompt
isn't a task, so you can't loop
it the way you're trying. You could ask the user for a comma-separated list of applications and then split the response.– larsks
Nov 9 at 21:27
if i do split as you said how do i access each word splitted?
– Azmy
Nov 9 at 21:46
if i do split as you said how do i access each word splitted?
– Azmy
Nov 9 at 21:46
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
If you really need to prompt the user for this information, you could
ask for a comma-delimited list:
- hosts: TestServer
vars_prompt:
- name: application_list_csv
prompt: "Please specify the applications, separated by commas"
And then split it in task into an actual list:
tasks:
- set_fact:
application_list: " application_list_csv.split(',') "
You can then loop over the values using a loop
, like this:
- debug:
msg: "item"
loop: "application_list"
Having said that, I still think you're better having the user putting the information into a file, like this:
application_list:
- app1
- app2
- app3
And then including that in your play:
ansible-playbook playbook.yml -e @applist.yml
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
If you really need to prompt the user for this information, you could
ask for a comma-delimited list:
- hosts: TestServer
vars_prompt:
- name: application_list_csv
prompt: "Please specify the applications, separated by commas"
And then split it in task into an actual list:
tasks:
- set_fact:
application_list: " application_list_csv.split(',') "
You can then loop over the values using a loop
, like this:
- debug:
msg: "item"
loop: "application_list"
Having said that, I still think you're better having the user putting the information into a file, like this:
application_list:
- app1
- app2
- app3
And then including that in your play:
ansible-playbook playbook.yml -e @applist.yml
add a comment |
up vote
0
down vote
accepted
If you really need to prompt the user for this information, you could
ask for a comma-delimited list:
- hosts: TestServer
vars_prompt:
- name: application_list_csv
prompt: "Please specify the applications, separated by commas"
And then split it in task into an actual list:
tasks:
- set_fact:
application_list: " application_list_csv.split(',') "
You can then loop over the values using a loop
, like this:
- debug:
msg: "item"
loop: "application_list"
Having said that, I still think you're better having the user putting the information into a file, like this:
application_list:
- app1
- app2
- app3
And then including that in your play:
ansible-playbook playbook.yml -e @applist.yml
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
If you really need to prompt the user for this information, you could
ask for a comma-delimited list:
- hosts: TestServer
vars_prompt:
- name: application_list_csv
prompt: "Please specify the applications, separated by commas"
And then split it in task into an actual list:
tasks:
- set_fact:
application_list: " application_list_csv.split(',') "
You can then loop over the values using a loop
, like this:
- debug:
msg: "item"
loop: "application_list"
Having said that, I still think you're better having the user putting the information into a file, like this:
application_list:
- app1
- app2
- app3
And then including that in your play:
ansible-playbook playbook.yml -e @applist.yml
If you really need to prompt the user for this information, you could
ask for a comma-delimited list:
- hosts: TestServer
vars_prompt:
- name: application_list_csv
prompt: "Please specify the applications, separated by commas"
And then split it in task into an actual list:
tasks:
- set_fact:
application_list: " application_list_csv.split(',') "
You can then loop over the values using a loop
, like this:
- debug:
msg: "item"
loop: "application_list"
Having said that, I still think you're better having the user putting the information into a file, like this:
application_list:
- app1
- app2
- app3
And then including that in your play:
ansible-playbook playbook.yml -e @applist.yml
answered Nov 9 at 22:22
larsks
111k18181193
111k18181193
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233281%2fmake-a-array-in-ansible-by-user-prompt%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What about just having your users put data into a vars file and then including that with
-e @myfile.yml
?– larsks
Nov 9 at 21:20
thanks for your comment but i need the it be done through vars_prompt, is there a way i can acheive this ?? please help
– Azmy
Nov 9 at 21:25
vars_prompt
isn't a task, so you can'tloop
it the way you're trying. You could ask the user for a comma-separated list of applications and then split the response.– larsks
Nov 9 at 21:27
if i do split as you said how do i access each word splitted?
– Azmy
Nov 9 at 21:46