Ansible looping items in file The Next CEO of Stack OverflowAnsible playbook shell outputansible using loop and multiple variablesloops over the registered variable to inspect the results in ansibleAnsible Command, Shell modules not executing scriptload variables from a local file in ansibleLoop through hosts with ansibleansible expression to use with with_itemGet item value in a loop with failed tasks in Ansibleansible nested loops with subelementsAnsible how to use looping to run multiple tasks one host at time

What is meant by a M next to a roman numeral?

Inappropriate reference requests from Journal reviewers

Why do remote companies require working in the US?

Implement the Thanos sorting algorithm

Why does GHC infer a monomorphic type here, even with MonomorphismRestriction disabled?

How to use tikz in fbox?

How do spells that require an ability check vs. the caster's spell save DC work?

Opposite of a diet

Why is there a PLL in CPU?

Too much space between section and text in a twocolumn document

Rotate a column

Unreliable Magic - Is it worth it?

Anatomically Correct Strange Women In Ponds Distributing Swords

Why does C# sound extremely flat when saxophone is tuned to G?

Why does standard notation not preserve intervals (visually)

How do I construct this japanese bowl?

Why didn't Theresa May consult with Parliament before negotiating a deal with the EU?

Can a caster that cast Polymorph on themselves stop concentrating at any point even if their Int is low?

Is the concept of a "numerable" fiber bundle really useful or an empty generalization?

Should I tutor a student who I know has cheated on their homework?

Example of a Mathematician/Physicist whose Other Publications during their PhD eclipsed their PhD Thesis

Why didn't Khan get resurrected in the Genesis Explosion?

How to start emacs in "nothing" mode (`fundamental-mode`)

What's the point of interval inversion?



Ansible looping items in file



The Next CEO of Stack OverflowAnsible playbook shell outputansible using loop and multiple variablesloops over the registered variable to inspect the results in ansibleAnsible Command, Shell modules not executing scriptload variables from a local file in ansibleLoop through hosts with ansibleansible expression to use with with_itemGet item value in a loop with failed tasks in Ansibleansible nested loops with subelementsAnsible how to use looping to run multiple tasks one host at time










0















I have a file(a_file.txt) like this:



22
23
8080


I need to loop each item in a_file.txt with my host and formatted to be host:22, host:23, host:8080...and so on, so I can use shell module in playbook like this:



---
- hosts: host1
tasks:
- name: Remote hostname
shell: hostname
register: hostname

- name: Read items from a_file.txt
shell: cat a_file.txt
register: item_output

- name: Run shell command
shell: someCommand nice_to_yaml:item
with_items: item_output.stdout_lines


However, my someCommand failed because I have:



nice_to_yaml = - hostnamen
<item in a_file.txt> = [u'22, u'23, u'8080]









share|improve this question


























    0















    I have a file(a_file.txt) like this:



    22
    23
    8080


    I need to loop each item in a_file.txt with my host and formatted to be host:22, host:23, host:8080...and so on, so I can use shell module in playbook like this:



    ---
    - hosts: host1
    tasks:
    - name: Remote hostname
    shell: hostname
    register: hostname

    - name: Read items from a_file.txt
    shell: cat a_file.txt
    register: item_output

    - name: Run shell command
    shell: someCommand nice_to_yaml:item
    with_items: item_output.stdout_lines


    However, my someCommand failed because I have:



    nice_to_yaml = - hostnamen
    <item in a_file.txt> = [u'22, u'23, u'8080]









    share|improve this question
























      0












      0








      0








      I have a file(a_file.txt) like this:



      22
      23
      8080


      I need to loop each item in a_file.txt with my host and formatted to be host:22, host:23, host:8080...and so on, so I can use shell module in playbook like this:



      ---
      - hosts: host1
      tasks:
      - name: Remote hostname
      shell: hostname
      register: hostname

      - name: Read items from a_file.txt
      shell: cat a_file.txt
      register: item_output

      - name: Run shell command
      shell: someCommand nice_to_yaml:item
      with_items: item_output.stdout_lines


      However, my someCommand failed because I have:



      nice_to_yaml = - hostnamen
      <item in a_file.txt> = [u'22, u'23, u'8080]









      share|improve this question














      I have a file(a_file.txt) like this:



      22
      23
      8080


      I need to loop each item in a_file.txt with my host and formatted to be host:22, host:23, host:8080...and so on, so I can use shell module in playbook like this:



      ---
      - hosts: host1
      tasks:
      - name: Remote hostname
      shell: hostname
      register: hostname

      - name: Read items from a_file.txt
      shell: cat a_file.txt
      register: item_output

      - name: Run shell command
      shell: someCommand nice_to_yaml:item
      with_items: item_output.stdout_lines


      However, my someCommand failed because I have:



      nice_to_yaml = - hostnamen
      <item in a_file.txt> = [u'22, u'23, u'8080]






      ansible






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 21 at 16:21









      codingcoding

      4019




      4019






















          1 Answer
          1






          active

          oldest

          votes


















          1














          you have to use:



          - name: Run shell command
          shell: someCommand nice_to_yaml:item
          with_items: " item_output.stdout_lines "





          share|improve this answer


















          • 1





            This works. Thanks!

            – coding
            yesterday











          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%2f55284975%2fansible-looping-items-in-file%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









          1














          you have to use:



          - name: Run shell command
          shell: someCommand nice_to_yaml:item
          with_items: " item_output.stdout_lines "





          share|improve this answer


















          • 1





            This works. Thanks!

            – coding
            yesterday















          1














          you have to use:



          - name: Run shell command
          shell: someCommand nice_to_yaml:item
          with_items: " item_output.stdout_lines "





          share|improve this answer


















          • 1





            This works. Thanks!

            – coding
            yesterday













          1












          1








          1







          you have to use:



          - name: Run shell command
          shell: someCommand nice_to_yaml:item
          with_items: " item_output.stdout_lines "





          share|improve this answer













          you have to use:



          - name: Run shell command
          shell: someCommand nice_to_yaml:item
          with_items: " item_output.stdout_lines "






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 21 at 19:22









          ilias-spilias-sp

          1,7662821




          1,7662821







          • 1





            This works. Thanks!

            – coding
            yesterday












          • 1





            This works. Thanks!

            – coding
            yesterday







          1




          1





          This works. Thanks!

          – coding
          yesterday





          This works. Thanks!

          – coding
          yesterday



















          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%2f55284975%2fansible-looping-items-in-file%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

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript