Ansible filter stdout_lines cut or split












0















I have a variable which contains a few lines and I want to find of a line having this value and after split based a delimiter and take only the first value of that specific line.



Task:1
- debug:
var: blabla.stdout_lines

Output
blabla.stdout_lines:
- 1 test1 aaa
- 2 test0 bbb
- 3 test444 ccc


Task:2
- name: test
debug:
msg: "{{ blabla.stdout | select('search', 'test1') | list }}"
Output
msg:
- 1 test1 aaa


I would like to have a split so it takes just the value "1" directly in the task2. I tried to do a textsplit and cut into it but seems it wasn't working.
I am trying to add another Jinja filter into the Task2.










share|improve this question























  • Your question is very opaque; do you mean that instead of "search", "test1" you want to only match on the leading numbers? Are you aware of regex_search()?

    – Matthew L Daniel
    Nov 25 '18 at 5:51











  • @MatthewLDaniel I want my output in task 2 to give me the "1" as the output instead of the full line. . The first select('search' ) looks for the line that contains the line I am looking for but after I want to do a split on the line so the output is "1" , Thank you for your help :)

    – Dusty
    Nov 25 '18 at 6:04













  • Thank you Matthew for the help ! Regex_search() was something I was looking for :)

    – Dusty
    Nov 25 '18 at 6:44
















0















I have a variable which contains a few lines and I want to find of a line having this value and after split based a delimiter and take only the first value of that specific line.



Task:1
- debug:
var: blabla.stdout_lines

Output
blabla.stdout_lines:
- 1 test1 aaa
- 2 test0 bbb
- 3 test444 ccc


Task:2
- name: test
debug:
msg: "{{ blabla.stdout | select('search', 'test1') | list }}"
Output
msg:
- 1 test1 aaa


I would like to have a split so it takes just the value "1" directly in the task2. I tried to do a textsplit and cut into it but seems it wasn't working.
I am trying to add another Jinja filter into the Task2.










share|improve this question























  • Your question is very opaque; do you mean that instead of "search", "test1" you want to only match on the leading numbers? Are you aware of regex_search()?

    – Matthew L Daniel
    Nov 25 '18 at 5:51











  • @MatthewLDaniel I want my output in task 2 to give me the "1" as the output instead of the full line. . The first select('search' ) looks for the line that contains the line I am looking for but after I want to do a split on the line so the output is "1" , Thank you for your help :)

    – Dusty
    Nov 25 '18 at 6:04













  • Thank you Matthew for the help ! Regex_search() was something I was looking for :)

    – Dusty
    Nov 25 '18 at 6:44














0












0








0








I have a variable which contains a few lines and I want to find of a line having this value and after split based a delimiter and take only the first value of that specific line.



Task:1
- debug:
var: blabla.stdout_lines

Output
blabla.stdout_lines:
- 1 test1 aaa
- 2 test0 bbb
- 3 test444 ccc


Task:2
- name: test
debug:
msg: "{{ blabla.stdout | select('search', 'test1') | list }}"
Output
msg:
- 1 test1 aaa


I would like to have a split so it takes just the value "1" directly in the task2. I tried to do a textsplit and cut into it but seems it wasn't working.
I am trying to add another Jinja filter into the Task2.










share|improve this question














I have a variable which contains a few lines and I want to find of a line having this value and after split based a delimiter and take only the first value of that specific line.



Task:1
- debug:
var: blabla.stdout_lines

Output
blabla.stdout_lines:
- 1 test1 aaa
- 2 test0 bbb
- 3 test444 ccc


Task:2
- name: test
debug:
msg: "{{ blabla.stdout | select('search', 'test1') | list }}"
Output
msg:
- 1 test1 aaa


I would like to have a split so it takes just the value "1" directly in the task2. I tried to do a textsplit and cut into it but seems it wasn't working.
I am trying to add another Jinja filter into the Task2.







python split ansible jinja2






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 25 '18 at 3:18









DustyDusty

49416




49416













  • Your question is very opaque; do you mean that instead of "search", "test1" you want to only match on the leading numbers? Are you aware of regex_search()?

    – Matthew L Daniel
    Nov 25 '18 at 5:51











  • @MatthewLDaniel I want my output in task 2 to give me the "1" as the output instead of the full line. . The first select('search' ) looks for the line that contains the line I am looking for but after I want to do a split on the line so the output is "1" , Thank you for your help :)

    – Dusty
    Nov 25 '18 at 6:04













  • Thank you Matthew for the help ! Regex_search() was something I was looking for :)

    – Dusty
    Nov 25 '18 at 6:44



















  • Your question is very opaque; do you mean that instead of "search", "test1" you want to only match on the leading numbers? Are you aware of regex_search()?

    – Matthew L Daniel
    Nov 25 '18 at 5:51











  • @MatthewLDaniel I want my output in task 2 to give me the "1" as the output instead of the full line. . The first select('search' ) looks for the line that contains the line I am looking for but after I want to do a split on the line so the output is "1" , Thank you for your help :)

    – Dusty
    Nov 25 '18 at 6:04













  • Thank you Matthew for the help ! Regex_search() was something I was looking for :)

    – Dusty
    Nov 25 '18 at 6:44

















Your question is very opaque; do you mean that instead of "search", "test1" you want to only match on the leading numbers? Are you aware of regex_search()?

– Matthew L Daniel
Nov 25 '18 at 5:51





Your question is very opaque; do you mean that instead of "search", "test1" you want to only match on the leading numbers? Are you aware of regex_search()?

– Matthew L Daniel
Nov 25 '18 at 5:51













@MatthewLDaniel I want my output in task 2 to give me the "1" as the output instead of the full line. . The first select('search' ) looks for the line that contains the line I am looking for but after I want to do a split on the line so the output is "1" , Thank you for your help :)

– Dusty
Nov 25 '18 at 6:04







@MatthewLDaniel I want my output in task 2 to give me the "1" as the output instead of the full line. . The first select('search' ) looks for the line that contains the line I am looking for but after I want to do a split on the line so the output is "1" , Thank you for your help :)

– Dusty
Nov 25 '18 at 6:04















Thank you Matthew for the help ! Regex_search() was something I was looking for :)

– Dusty
Nov 25 '18 at 6:44





Thank you Matthew for the help ! Regex_search() was something I was looking for :)

– Dusty
Nov 25 '18 at 6:44












1 Answer
1






active

oldest

votes


















0














Managed to used regex_search() as Matthew suggested



   - name: Extract valuevariables

set_fact:

webapps_not: "{{ blabla.stdout | regex_search('.+?(?=no)') }}"


- name: Show value

debug: var=blabla_not





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',
    autoActivateHeartbeat: false,
    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%2f53464347%2fansible-filter-stdout-lines-cut-or-split%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









    0














    Managed to used regex_search() as Matthew suggested



       - name: Extract valuevariables

    set_fact:

    webapps_not: "{{ blabla.stdout | regex_search('.+?(?=no)') }}"


    - name: Show value

    debug: var=blabla_not





    share|improve this answer




























      0














      Managed to used regex_search() as Matthew suggested



         - name: Extract valuevariables

      set_fact:

      webapps_not: "{{ blabla.stdout | regex_search('.+?(?=no)') }}"


      - name: Show value

      debug: var=blabla_not





      share|improve this answer


























        0












        0








        0







        Managed to used regex_search() as Matthew suggested



           - name: Extract valuevariables

        set_fact:

        webapps_not: "{{ blabla.stdout | regex_search('.+?(?=no)') }}"


        - name: Show value

        debug: var=blabla_not





        share|improve this answer













        Managed to used regex_search() as Matthew suggested



           - name: Extract valuevariables

        set_fact:

        webapps_not: "{{ blabla.stdout | regex_search('.+?(?=no)') }}"


        - name: Show value

        debug: var=blabla_not






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 25 '18 at 6:31









        DustyDusty

        49416




        49416
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53464347%2fansible-filter-stdout-lines-cut-or-split%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

            Costa Masnaga

            Fotorealismo

            Sidney Franklin