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
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
add a comment |
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
add a comment |
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
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
ansible
asked Mar 21 at 16:21
codingcoding
4019
4019
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
you have to use:
- name: Run shell command
shell: someCommand nice_to_yaml:item
with_items: " item_output.stdout_lines "
1
This works. Thanks!
– coding
yesterday
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%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
you have to use:
- name: Run shell command
shell: someCommand nice_to_yaml:item
with_items: " item_output.stdout_lines "
1
This works. Thanks!
– coding
yesterday
add a comment |
you have to use:
- name: Run shell command
shell: someCommand nice_to_yaml:item
with_items: " item_output.stdout_lines "
1
This works. Thanks!
– coding
yesterday
add a comment |
you have to use:
- name: Run shell command
shell: someCommand nice_to_yaml:item
with_items: " item_output.stdout_lines "
you have to use:
- name: Run shell command
shell: someCommand nice_to_yaml:item
with_items: " item_output.stdout_lines "
answered Mar 21 at 19:22
ilias-spilias-sp
1,7662821
1,7662821
1
This works. Thanks!
– coding
yesterday
add a comment |
1
This works. Thanks!
– coding
yesterday
1
1
This works. Thanks!
– coding
yesterday
This works. Thanks!
– coding
yesterday
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%2f55284975%2fansible-looping-items-in-file%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