How do i store a variable value to a file in new lines on ansibleHow would I register a dynamically named...
How to determine what is the correct level of detail when modelling?
What do you call the action of someone tackling a stronger person?
What does 2>&1 | tee mean?
If my Scout rogue has used his full movement on his turn, can he later use the reaction from the Skirmisher feature to move again?
Why cruise at 7000' in an A319?
Is this the golf ball that Alan Shepard hit on the Moon?
One folder two different locations on ubuntu 18.04
Do we or do we not observe (measure) superpositions all the time?
What is the line crossing the Pacific Ocean that is shown on maps?
Zombie Diet, why humans
Is there any set of 2-6 notes that doesn't have a chord name?
Is there a short way to check uniqueness of values without using 'if' and multiple 'and's?
Symbol for "not absolutely continuous" in Latex
What are good ways to spray paint a QR code on a footpath?
Why is a blank required between "[[" and "-e xxx" in ksh?
Why does this fireplace work?
Sir Alex Ferguson advice OR Sir Alex Ferguson's advice
Wilcoxon signed rank test – critical value for n>50
How to convert object fill in to fine lines?
The difference between Rad1 and Rfd1
Is adding a new player (or players) a DM decision, or a group decision?
Could Sauron have read Tom Bombadil's mind if Tom had held the Palantir?
Alphabet completion rate
Should I report a leak of confidential HR information?
How do i store a variable value to a file in new lines on ansible
How would I register a dynamically named variable in an Ansible task?ansible pass shell command result to variableAnsible array variableseparator value from fact variable in ansibleansible variable as environment variableHow to pass prompt in ansible?replace specific line in file with ansibleAnsible Playbook: Get value from variableAnsible configuration filehow to run playbooks in ansible parallel
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I would like to store the variable value to a file in new lines format.
- set_fact:
linked_dirs: "{{ linked_dirs.stdout_lines | select('search',nfs_server) | list }}"
- debug: var=linked_dirs
- shell: echo -e "{{ linked_dirs }}n" >> /tmp/test
delegate_to: localhost
cat /tmp/test
[u'/net/rchserver01/data/share2 linked with /var/tmp/test2', u'/net/rchserver01/data/share2 linked with /var/tmp/share2', u'/net/rchserver01/data/share1 linked with /var/share1']
Required Result:
cat /tmp/test
/net/rchserver01/data/share2 linked with /var/tmp/test2
/net/rchserver01/data/share2 linked with /var/tmp/share2
/net/rchserver01/data/share1 linked with /var/share1
ansible
bumped to the homepage by Community♦ 43 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I would like to store the variable value to a file in new lines format.
- set_fact:
linked_dirs: "{{ linked_dirs.stdout_lines | select('search',nfs_server) | list }}"
- debug: var=linked_dirs
- shell: echo -e "{{ linked_dirs }}n" >> /tmp/test
delegate_to: localhost
cat /tmp/test
[u'/net/rchserver01/data/share2 linked with /var/tmp/test2', u'/net/rchserver01/data/share2 linked with /var/tmp/share2', u'/net/rchserver01/data/share1 linked with /var/share1']
Required Result:
cat /tmp/test
/net/rchserver01/data/share2 linked with /var/tmp/test2
/net/rchserver01/data/share2 linked with /var/tmp/share2
/net/rchserver01/data/share1 linked with /var/share1
ansible
bumped to the homepage by Community♦ 43 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I would like to store the variable value to a file in new lines format.
- set_fact:
linked_dirs: "{{ linked_dirs.stdout_lines | select('search',nfs_server) | list }}"
- debug: var=linked_dirs
- shell: echo -e "{{ linked_dirs }}n" >> /tmp/test
delegate_to: localhost
cat /tmp/test
[u'/net/rchserver01/data/share2 linked with /var/tmp/test2', u'/net/rchserver01/data/share2 linked with /var/tmp/share2', u'/net/rchserver01/data/share1 linked with /var/share1']
Required Result:
cat /tmp/test
/net/rchserver01/data/share2 linked with /var/tmp/test2
/net/rchserver01/data/share2 linked with /var/tmp/share2
/net/rchserver01/data/share1 linked with /var/share1
ansible
I would like to store the variable value to a file in new lines format.
- set_fact:
linked_dirs: "{{ linked_dirs.stdout_lines | select('search',nfs_server) | list }}"
- debug: var=linked_dirs
- shell: echo -e "{{ linked_dirs }}n" >> /tmp/test
delegate_to: localhost
cat /tmp/test
[u'/net/rchserver01/data/share2 linked with /var/tmp/test2', u'/net/rchserver01/data/share2 linked with /var/tmp/share2', u'/net/rchserver01/data/share1 linked with /var/share1']
Required Result:
cat /tmp/test
/net/rchserver01/data/share2 linked with /var/tmp/test2
/net/rchserver01/data/share2 linked with /var/tmp/share2
/net/rchserver01/data/share1 linked with /var/share1
ansible
ansible
edited Sep 21 '18 at 16:57
Pandu
asked Sep 21 '18 at 16:52
PanduPandu
311 silver badge10 bronze badges
311 silver badge10 bronze badges
bumped to the homepage by Community♦ 43 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 43 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You are getting a python style list with that echo. In case you need the values only, iterate over the elements using with_items and echo.
add a comment |
First, if you have a list, you have to join() the items together.
Second, to write a file, use the copy module.
Replace the last task with something like this:
- name: Write linked_dirs file
copy:
content: '{{ linked_dirs("n") }}'
dest: /tmp/test
delegate_to: localhost
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2funix.stackexchange.com%2fquestions%2f470582%2fhow-do-i-store-a-variable-value-to-a-file-in-new-lines-on-ansible%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You are getting a python style list with that echo. In case you need the values only, iterate over the elements using with_items and echo.
add a comment |
You are getting a python style list with that echo. In case you need the values only, iterate over the elements using with_items and echo.
add a comment |
You are getting a python style list with that echo. In case you need the values only, iterate over the elements using with_items and echo.
You are getting a python style list with that echo. In case you need the values only, iterate over the elements using with_items and echo.
answered Sep 21 '18 at 16:57
harguthargut
2738 bronze badges
2738 bronze badges
add a comment |
add a comment |
First, if you have a list, you have to join() the items together.
Second, to write a file, use the copy module.
Replace the last task with something like this:
- name: Write linked_dirs file
copy:
content: '{{ linked_dirs("n") }}'
dest: /tmp/test
delegate_to: localhost
add a comment |
First, if you have a list, you have to join() the items together.
Second, to write a file, use the copy module.
Replace the last task with something like this:
- name: Write linked_dirs file
copy:
content: '{{ linked_dirs("n") }}'
dest: /tmp/test
delegate_to: localhost
add a comment |
First, if you have a list, you have to join() the items together.
Second, to write a file, use the copy module.
Replace the last task with something like this:
- name: Write linked_dirs file
copy:
content: '{{ linked_dirs("n") }}'
dest: /tmp/test
delegate_to: localhost
First, if you have a list, you have to join() the items together.
Second, to write a file, use the copy module.
Replace the last task with something like this:
- name: Write linked_dirs file
copy:
content: '{{ linked_dirs("n") }}'
dest: /tmp/test
delegate_to: localhost
answered Oct 31 '18 at 15:06
mhuttermhutter
5562 silver badges12 bronze badges
5562 silver badges12 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- 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%2funix.stackexchange.com%2fquestions%2f470582%2fhow-do-i-store-a-variable-value-to-a-file-in-new-lines-on-ansible%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