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
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
add a comment |
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
add a comment |
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
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
ansible
asked Mar 6 at 13:30
hotcheetoshotcheetos
153
153
add a comment |
add a comment |
 1 Answer
 1
 
active
oldest
votes
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
 
 
 
 
 
 
 
 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
 
 
 
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
 
 
 
 
 
 
 
 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
 
 
 
add a comment |
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
 
 
 
 
 
 
 
 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
 
 
 
add a comment |
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
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
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
 
 
 
add a comment |
 
 
 
 
 
 
 
 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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