Ansible 'with_items' doesn't pass over to Ansible role2019 Community Moderator ElectionSpecifying Ansible inventory directoryUsing set_facts and with_items together in AnsibleAnsible playbook only add role dependency variablesAnsible passing variables to rolesAnsible template module not parsing with_items variableLoop through hosts with ansibleHow can I pass a parameter to a role in Ansible from inventory file?How to use variables in with_items in anisble playbookSet hosts value with an extra-vars doesn't work for my Ansible roleansible dynamic inventory refresh

How exactly does an Ethernet collision happen in the cable, since nodes use different circuits for Tx and Rx?

Logistic regression BIC: what's the right N?

What should I do when a paper is published similar to my PhD thesis without citation?

When to use a QR code on a business card?

How do we create new idioms and use them in a novel?

What does the Digital Threat scope actually do?

The (Easy) Road to Code

Are E natural minor and B harmonic minor related?

Computation logic of Partway in TikZ

Is it appropriate to ask a former professor to order a book for me through an inter-library loan?

Can I negotiate a patent idea for a raise, under French law?

Movie: boy escapes the real world and goes to a fantasy world with big furry trolls

If sound is a longitudinal wave, why can we hear it if our ears aren't aligned with the propagation direction?

What will happen if my luggage gets delayed?

Are small insurances worth it?

How to write a chaotic neutral protagonist and prevent my readers from thinking they are evil?

Translation of 答えを知っている人はいませんでした

Locked Away- What am I?

Is divide-by-zero a security vulnerability?

Cycles on the torus

Trocar background-image com delay via jQuery

Has a sovereign Communist government ever run, and conceded loss, on a fair election?

Rationale to prefer local variables over instance variables?

Under what conditions can the right to remain silent be revoked in the USA?



Ansible 'with_items' doesn't pass over to Ansible role



2019 Community Moderator ElectionSpecifying Ansible inventory directoryUsing set_facts and with_items together in AnsibleAnsible playbook only add role dependency variablesAnsible passing variables to rolesAnsible template module not parsing with_items variableLoop through hosts with ansibleHow can I pass a parameter to a role in Ansible from inventory file?How to use variables in with_items in anisble playbookSet hosts value with an extra-vars doesn't work for my Ansible roleansible dynamic inventory refresh










0















I can't figure this out. I have host_vars that I want to pass into my Ansible role. I can iterate through the items in my playbook, but it doesn't work if I give the item into my Ansible role. My host inventory looks like this:



hosts:
host_one:
domain: one
ip: 172.18.1.1
connection:
- connection_name: two
connection_ip: 172.18.1.2

- connection_index: three
local_hub_ip: 172.18.1.3

host_two:
domain: two
ip: 172.18.1.2


For instance,this works correctly:



 tasks:
- debug:
msg: "item.connection_name"
with_items:
- " connection "


will correctly print out the connections.connection_name for each connection I have, "two" and "three". However, if I try to pass it into a role:



 tasks:
- name: Adding several connections
include_role:
name: connection-create
with_items:
- " connection "


in which my role "connection-create" uses a variable called "connection_name" I get a:




FAILED! => "msg": "'connection_name' is undefined"




Why doesn't this work?










share|improve this question


























    0















    I can't figure this out. I have host_vars that I want to pass into my Ansible role. I can iterate through the items in my playbook, but it doesn't work if I give the item into my Ansible role. My host inventory looks like this:



    hosts:
    host_one:
    domain: one
    ip: 172.18.1.1
    connection:
    - connection_name: two
    connection_ip: 172.18.1.2

    - connection_index: three
    local_hub_ip: 172.18.1.3

    host_two:
    domain: two
    ip: 172.18.1.2


    For instance,this works correctly:



     tasks:
    - debug:
    msg: "item.connection_name"
    with_items:
    - " connection "


    will correctly print out the connections.connection_name for each connection I have, "two" and "three". However, if I try to pass it into a role:



     tasks:
    - name: Adding several connections
    include_role:
    name: connection-create
    with_items:
    - " connection "


    in which my role "connection-create" uses a variable called "connection_name" I get a:




    FAILED! => "msg": "'connection_name' is undefined"




    Why doesn't this work?










    share|improve this question
























      0












      0








      0








      I can't figure this out. I have host_vars that I want to pass into my Ansible role. I can iterate through the items in my playbook, but it doesn't work if I give the item into my Ansible role. My host inventory looks like this:



      hosts:
      host_one:
      domain: one
      ip: 172.18.1.1
      connection:
      - connection_name: two
      connection_ip: 172.18.1.2

      - connection_index: three
      local_hub_ip: 172.18.1.3

      host_two:
      domain: two
      ip: 172.18.1.2


      For instance,this works correctly:



       tasks:
      - debug:
      msg: "item.connection_name"
      with_items:
      - " connection "


      will correctly print out the connections.connection_name for each connection I have, "two" and "three". However, if I try to pass it into a role:



       tasks:
      - name: Adding several connections
      include_role:
      name: connection-create
      with_items:
      - " connection "


      in which my role "connection-create" uses a variable called "connection_name" I get a:




      FAILED! => "msg": "'connection_name' is undefined"




      Why doesn't this work?










      share|improve this question














      I can't figure this out. I have host_vars that I want to pass into my Ansible role. I can iterate through the items in my playbook, but it doesn't work if I give the item into my Ansible role. My host inventory looks like this:



      hosts:
      host_one:
      domain: one
      ip: 172.18.1.1
      connection:
      - connection_name: two
      connection_ip: 172.18.1.2

      - connection_index: three
      local_hub_ip: 172.18.1.3

      host_two:
      domain: two
      ip: 172.18.1.2


      For instance,this works correctly:



       tasks:
      - debug:
      msg: "item.connection_name"
      with_items:
      - " connection "


      will correctly print out the connections.connection_name for each connection I have, "two" and "three". However, if I try to pass it into a role:



       tasks:
      - name: Adding several connections
      include_role:
      name: connection-create
      with_items:
      - " connection "


      in which my role "connection-create" uses a variable called "connection_name" I get a:




      FAILED! => "msg": "'connection_name' is undefined"




      Why doesn't this work?







      ansible






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 6 at 13:30









      hotcheetoshotcheetos

      153




      153






















          1 Answer
          1






          active

          oldest

          votes


















          1














          The loop with_items: " connection " creates the loop variable item. The included role can use



          item.connection_name
          item.connection_ip


          The loop variable can be renamed, if needed. See Loop control






          share|improve this answer























          • I see, the issue was in my role I had another "with_items" task so I had to restructure it so I could use the 'item.connection_name'

            – hotcheetos
            2 days ago










          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%2f55024287%2fansible-with-items-doesnt-pass-over-to-ansible-role%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














          The loop with_items: " connection " creates the loop variable item. The included role can use



          item.connection_name
          item.connection_ip


          The loop variable can be renamed, if needed. See Loop control






          share|improve this answer























          • I see, the issue was in my role I had another "with_items" task so I had to restructure it so I could use the 'item.connection_name'

            – hotcheetos
            2 days ago















          1














          The loop with_items: " connection " creates the loop variable item. The included role can use



          item.connection_name
          item.connection_ip


          The loop variable can be renamed, if needed. See Loop control






          share|improve this answer























          • I see, the issue was in my role I had another "with_items" task so I had to restructure it so I could use the 'item.connection_name'

            – hotcheetos
            2 days ago













          1












          1








          1







          The loop with_items: " connection " creates the loop variable item. The included role can use



          item.connection_name
          item.connection_ip


          The loop variable can be renamed, if needed. See Loop control






          share|improve this answer













          The loop with_items: " connection " creates the loop variable item. The included role can use



          item.connection_name
          item.connection_ip


          The loop variable can be renamed, if needed. See Loop control







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 6 at 14:00









          Vladimir BotkaVladimir Botka

          1,7401410




          1,7401410












          • I see, the issue was in my role I had another "with_items" task so I had to restructure it so I could use the 'item.connection_name'

            – hotcheetos
            2 days ago

















          • I see, the issue was in my role I had another "with_items" task so I had to restructure it so I could use the 'item.connection_name'

            – hotcheetos
            2 days ago
















          I see, the issue was in my role I had another "with_items" task so I had to restructure it so I could use the 'item.connection_name'

          – hotcheetos
          2 days ago





          I see, the issue was in my role I had another "with_items" task so I had to restructure it so I could use the 'item.connection_name'

          – hotcheetos
          2 days ago



















          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%2f55024287%2fansible-with-items-doesnt-pass-over-to-ansible-role%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

          Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

          Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

          Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved