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.










share|improve this question























  • 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'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














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.










share|improve this question























  • 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'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












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.










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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'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
















  • 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'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















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












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





share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    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

























    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





    share|improve this answer
























      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





      share|improve this answer






















        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





        share|improve this answer












        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






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 9 at 22:22









        larsks

        111k18181193




        111k18181193



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Use pre created SQLite database for Android project in kotlin

            Darth Vader #20

            Ondo