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

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현