ansible: Looping over directory and referencing that file in another playbook
I am trying to make a playbook that loops over the number of files in a directory and then use those files in another playbook.
My playbook as it is now:
---
- name: Run playbooks for Raji's testing
register: scripts
roles:
- prepare_edge.yml
- prepare_iq.yml
- scriptor.yml
with_fileglob: ~/ansible/test_scripts/*
~
When I run this it doesn't work, I've tried "register: scripts" to make a variable to reference inside scriptor.yml but again the playbook fails. Any advice or help you can provide would be much appreciated.
Thanks!
P.S. I am super new to ansible
here is the scriptor.yml
---
- hosts: all
tasks:
- name: Create directory
command: mkdir /some/path/
- name: If file is a playbook
copy:
src: " scripts "
dest: /some/path/
when: " scripts " == "*.yml"
- name: if file is a script
shell: . $ scripts
when: " scripts " == "*.sh"
P.S.S prepare_edge.yml and prepare_iq.yml don't reference anything and just need to be called in the loop before scriptor.yml
here is the error:
ERROR! 'register' is not a valid attribute for a Play
The error appears to have been in '/Users/JGrow33/ansible/raji_magic_playbook.yml': line 3, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Run playbooks for Raji's testing
^ here
ansible
add a comment |
I am trying to make a playbook that loops over the number of files in a directory and then use those files in another playbook.
My playbook as it is now:
---
- name: Run playbooks for Raji's testing
register: scripts
roles:
- prepare_edge.yml
- prepare_iq.yml
- scriptor.yml
with_fileglob: ~/ansible/test_scripts/*
~
When I run this it doesn't work, I've tried "register: scripts" to make a variable to reference inside scriptor.yml but again the playbook fails. Any advice or help you can provide would be much appreciated.
Thanks!
P.S. I am super new to ansible
here is the scriptor.yml
---
- hosts: all
tasks:
- name: Create directory
command: mkdir /some/path/
- name: If file is a playbook
copy:
src: " scripts "
dest: /some/path/
when: " scripts " == "*.yml"
- name: if file is a script
shell: . $ scripts
when: " scripts " == "*.sh"
P.S.S prepare_edge.yml and prepare_iq.yml don't reference anything and just need to be called in the loop before scriptor.yml
here is the error:
ERROR! 'register' is not a valid attribute for a Play
The error appears to have been in '/Users/JGrow33/ansible/raji_magic_playbook.yml': line 3, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Run playbooks for Raji's testing
^ here
ansible
I don't see where you're trying to useregister
or where you're trying to access the reigstered variable. If your playbook is failing with an error, please include that error in your question.
– larsks
Nov 14 '18 at 16:38
I've updated it to the original playbook and added the error i've been getting. If i take register: scripts out, I get the same error but with "with_fileglob is not a valid attribute...."
– James Grow
Nov 14 '18 at 16:51
add a comment |
I am trying to make a playbook that loops over the number of files in a directory and then use those files in another playbook.
My playbook as it is now:
---
- name: Run playbooks for Raji's testing
register: scripts
roles:
- prepare_edge.yml
- prepare_iq.yml
- scriptor.yml
with_fileglob: ~/ansible/test_scripts/*
~
When I run this it doesn't work, I've tried "register: scripts" to make a variable to reference inside scriptor.yml but again the playbook fails. Any advice or help you can provide would be much appreciated.
Thanks!
P.S. I am super new to ansible
here is the scriptor.yml
---
- hosts: all
tasks:
- name: Create directory
command: mkdir /some/path/
- name: If file is a playbook
copy:
src: " scripts "
dest: /some/path/
when: " scripts " == "*.yml"
- name: if file is a script
shell: . $ scripts
when: " scripts " == "*.sh"
P.S.S prepare_edge.yml and prepare_iq.yml don't reference anything and just need to be called in the loop before scriptor.yml
here is the error:
ERROR! 'register' is not a valid attribute for a Play
The error appears to have been in '/Users/JGrow33/ansible/raji_magic_playbook.yml': line 3, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Run playbooks for Raji's testing
^ here
ansible
I am trying to make a playbook that loops over the number of files in a directory and then use those files in another playbook.
My playbook as it is now:
---
- name: Run playbooks for Raji's testing
register: scripts
roles:
- prepare_edge.yml
- prepare_iq.yml
- scriptor.yml
with_fileglob: ~/ansible/test_scripts/*
~
When I run this it doesn't work, I've tried "register: scripts" to make a variable to reference inside scriptor.yml but again the playbook fails. Any advice or help you can provide would be much appreciated.
Thanks!
P.S. I am super new to ansible
here is the scriptor.yml
---
- hosts: all
tasks:
- name: Create directory
command: mkdir /some/path/
- name: If file is a playbook
copy:
src: " scripts "
dest: /some/path/
when: " scripts " == "*.yml"
- name: if file is a script
shell: . $ scripts
when: " scripts " == "*.sh"
P.S.S prepare_edge.yml and prepare_iq.yml don't reference anything and just need to be called in the loop before scriptor.yml
here is the error:
ERROR! 'register' is not a valid attribute for a Play
The error appears to have been in '/Users/JGrow33/ansible/raji_magic_playbook.yml': line 3, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Run playbooks for Raji's testing
^ here
ansible
ansible
edited Nov 14 '18 at 16:50
James Grow
asked Nov 14 '18 at 16:33
James GrowJames Grow
63
63
I don't see where you're trying to useregister
or where you're trying to access the reigstered variable. If your playbook is failing with an error, please include that error in your question.
– larsks
Nov 14 '18 at 16:38
I've updated it to the original playbook and added the error i've been getting. If i take register: scripts out, I get the same error but with "with_fileglob is not a valid attribute...."
– James Grow
Nov 14 '18 at 16:51
add a comment |
I don't see where you're trying to useregister
or where you're trying to access the reigstered variable. If your playbook is failing with an error, please include that error in your question.
– larsks
Nov 14 '18 at 16:38
I've updated it to the original playbook and added the error i've been getting. If i take register: scripts out, I get the same error but with "with_fileglob is not a valid attribute...."
– James Grow
Nov 14 '18 at 16:51
I don't see where you're trying to use
register
or where you're trying to access the reigstered variable. If your playbook is failing with an error, please include that error in your question.– larsks
Nov 14 '18 at 16:38
I don't see where you're trying to use
register
or where you're trying to access the reigstered variable. If your playbook is failing with an error, please include that error in your question.– larsks
Nov 14 '18 at 16:38
I've updated it to the original playbook and added the error i've been getting. If i take register: scripts out, I get the same error but with "with_fileglob is not a valid attribute...."
– James Grow
Nov 14 '18 at 16:51
I've updated it to the original playbook and added the error i've been getting. If i take register: scripts out, I get the same error but with "with_fileglob is not a valid attribute...."
– James Grow
Nov 14 '18 at 16:51
add a comment |
1 Answer
1
active
oldest
votes
There error message you're getting is telling you that you can't run register
in a Playbook.
You can accomplish what you're looking for by doing something like the following in your scriptor.yml file:
- hosts: all
tasks:
- name: Create directory
command: mkdir /some/path/
- name: If file is a playbook
copy:
src: " item "
dest: /some/path/
with_fileglob: ~/ansible/test_scripts/*.yml
- name: if file is a script
shell: . $ item
with_fileglob: copy:
src: " item "
dest: /some/path/
with_fileglobe: ~/ansible/test_scripts/*.sh
References
How can Ansible "register" in a variable the result of including a playbook?
If I do it this way, wouldn't the main playbook not loop?
– James Grow
Nov 14 '18 at 17:59
you didn't include your other roles, do they need to be called before every file?
– kenlukas
Nov 14 '18 at 18:06
yeah, prepare_edge.yml and prepare_iq.yml need to be called before scriptor.yml every time scriptor.yml either runs a script or copies a playbook. That was why i was trying to make the loop in the main playbook so everything got called at every step of the loop
– James Grow
Nov 14 '18 at 18:16
Is there a reason they need to be in separate roles? You could consolidate the three.
– kenlukas
Nov 14 '18 at 18:26
I was asked to make it so that there were 3 different playbooks. I am an intern and I was asked to automate some scripts used for testing as a project. The different playbooks makes it easier to edit later on if more stuff needs to be added.
– James Grow
Nov 14 '18 at 19:02
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%2f53304836%2fansible-looping-over-directory-and-referencing-that-file-in-another-playbook%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
There error message you're getting is telling you that you can't run register
in a Playbook.
You can accomplish what you're looking for by doing something like the following in your scriptor.yml file:
- hosts: all
tasks:
- name: Create directory
command: mkdir /some/path/
- name: If file is a playbook
copy:
src: " item "
dest: /some/path/
with_fileglob: ~/ansible/test_scripts/*.yml
- name: if file is a script
shell: . $ item
with_fileglob: copy:
src: " item "
dest: /some/path/
with_fileglobe: ~/ansible/test_scripts/*.sh
References
How can Ansible "register" in a variable the result of including a playbook?
If I do it this way, wouldn't the main playbook not loop?
– James Grow
Nov 14 '18 at 17:59
you didn't include your other roles, do they need to be called before every file?
– kenlukas
Nov 14 '18 at 18:06
yeah, prepare_edge.yml and prepare_iq.yml need to be called before scriptor.yml every time scriptor.yml either runs a script or copies a playbook. That was why i was trying to make the loop in the main playbook so everything got called at every step of the loop
– James Grow
Nov 14 '18 at 18:16
Is there a reason they need to be in separate roles? You could consolidate the three.
– kenlukas
Nov 14 '18 at 18:26
I was asked to make it so that there were 3 different playbooks. I am an intern and I was asked to automate some scripts used for testing as a project. The different playbooks makes it easier to edit later on if more stuff needs to be added.
– James Grow
Nov 14 '18 at 19:02
add a comment |
There error message you're getting is telling you that you can't run register
in a Playbook.
You can accomplish what you're looking for by doing something like the following in your scriptor.yml file:
- hosts: all
tasks:
- name: Create directory
command: mkdir /some/path/
- name: If file is a playbook
copy:
src: " item "
dest: /some/path/
with_fileglob: ~/ansible/test_scripts/*.yml
- name: if file is a script
shell: . $ item
with_fileglob: copy:
src: " item "
dest: /some/path/
with_fileglobe: ~/ansible/test_scripts/*.sh
References
How can Ansible "register" in a variable the result of including a playbook?
If I do it this way, wouldn't the main playbook not loop?
– James Grow
Nov 14 '18 at 17:59
you didn't include your other roles, do they need to be called before every file?
– kenlukas
Nov 14 '18 at 18:06
yeah, prepare_edge.yml and prepare_iq.yml need to be called before scriptor.yml every time scriptor.yml either runs a script or copies a playbook. That was why i was trying to make the loop in the main playbook so everything got called at every step of the loop
– James Grow
Nov 14 '18 at 18:16
Is there a reason they need to be in separate roles? You could consolidate the three.
– kenlukas
Nov 14 '18 at 18:26
I was asked to make it so that there were 3 different playbooks. I am an intern and I was asked to automate some scripts used for testing as a project. The different playbooks makes it easier to edit later on if more stuff needs to be added.
– James Grow
Nov 14 '18 at 19:02
add a comment |
There error message you're getting is telling you that you can't run register
in a Playbook.
You can accomplish what you're looking for by doing something like the following in your scriptor.yml file:
- hosts: all
tasks:
- name: Create directory
command: mkdir /some/path/
- name: If file is a playbook
copy:
src: " item "
dest: /some/path/
with_fileglob: ~/ansible/test_scripts/*.yml
- name: if file is a script
shell: . $ item
with_fileglob: copy:
src: " item "
dest: /some/path/
with_fileglobe: ~/ansible/test_scripts/*.sh
References
How can Ansible "register" in a variable the result of including a playbook?
There error message you're getting is telling you that you can't run register
in a Playbook.
You can accomplish what you're looking for by doing something like the following in your scriptor.yml file:
- hosts: all
tasks:
- name: Create directory
command: mkdir /some/path/
- name: If file is a playbook
copy:
src: " item "
dest: /some/path/
with_fileglob: ~/ansible/test_scripts/*.yml
- name: if file is a script
shell: . $ item
with_fileglob: copy:
src: " item "
dest: /some/path/
with_fileglobe: ~/ansible/test_scripts/*.sh
References
How can Ansible "register" in a variable the result of including a playbook?
answered Nov 14 '18 at 17:54
kenlukaskenlukas
1,51641318
1,51641318
If I do it this way, wouldn't the main playbook not loop?
– James Grow
Nov 14 '18 at 17:59
you didn't include your other roles, do they need to be called before every file?
– kenlukas
Nov 14 '18 at 18:06
yeah, prepare_edge.yml and prepare_iq.yml need to be called before scriptor.yml every time scriptor.yml either runs a script or copies a playbook. That was why i was trying to make the loop in the main playbook so everything got called at every step of the loop
– James Grow
Nov 14 '18 at 18:16
Is there a reason they need to be in separate roles? You could consolidate the three.
– kenlukas
Nov 14 '18 at 18:26
I was asked to make it so that there were 3 different playbooks. I am an intern and I was asked to automate some scripts used for testing as a project. The different playbooks makes it easier to edit later on if more stuff needs to be added.
– James Grow
Nov 14 '18 at 19:02
add a comment |
If I do it this way, wouldn't the main playbook not loop?
– James Grow
Nov 14 '18 at 17:59
you didn't include your other roles, do they need to be called before every file?
– kenlukas
Nov 14 '18 at 18:06
yeah, prepare_edge.yml and prepare_iq.yml need to be called before scriptor.yml every time scriptor.yml either runs a script or copies a playbook. That was why i was trying to make the loop in the main playbook so everything got called at every step of the loop
– James Grow
Nov 14 '18 at 18:16
Is there a reason they need to be in separate roles? You could consolidate the three.
– kenlukas
Nov 14 '18 at 18:26
I was asked to make it so that there were 3 different playbooks. I am an intern and I was asked to automate some scripts used for testing as a project. The different playbooks makes it easier to edit later on if more stuff needs to be added.
– James Grow
Nov 14 '18 at 19:02
If I do it this way, wouldn't the main playbook not loop?
– James Grow
Nov 14 '18 at 17:59
If I do it this way, wouldn't the main playbook not loop?
– James Grow
Nov 14 '18 at 17:59
you didn't include your other roles, do they need to be called before every file?
– kenlukas
Nov 14 '18 at 18:06
you didn't include your other roles, do they need to be called before every file?
– kenlukas
Nov 14 '18 at 18:06
yeah, prepare_edge.yml and prepare_iq.yml need to be called before scriptor.yml every time scriptor.yml either runs a script or copies a playbook. That was why i was trying to make the loop in the main playbook so everything got called at every step of the loop
– James Grow
Nov 14 '18 at 18:16
yeah, prepare_edge.yml and prepare_iq.yml need to be called before scriptor.yml every time scriptor.yml either runs a script or copies a playbook. That was why i was trying to make the loop in the main playbook so everything got called at every step of the loop
– James Grow
Nov 14 '18 at 18:16
Is there a reason they need to be in separate roles? You could consolidate the three.
– kenlukas
Nov 14 '18 at 18:26
Is there a reason they need to be in separate roles? You could consolidate the three.
– kenlukas
Nov 14 '18 at 18:26
I was asked to make it so that there were 3 different playbooks. I am an intern and I was asked to automate some scripts used for testing as a project. The different playbooks makes it easier to edit later on if more stuff needs to be added.
– James Grow
Nov 14 '18 at 19:02
I was asked to make it so that there were 3 different playbooks. I am an intern and I was asked to automate some scripts used for testing as a project. The different playbooks makes it easier to edit later on if more stuff needs to be added.
– James Grow
Nov 14 '18 at 19:02
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%2f53304836%2fansible-looping-over-directory-and-referencing-that-file-in-another-playbook%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
I don't see where you're trying to use
register
or where you're trying to access the reigstered variable. If your playbook is failing with an error, please include that error in your question.– larsks
Nov 14 '18 at 16:38
I've updated it to the original playbook and added the error i've been getting. If i take register: scripts out, I get the same error but with "with_fileglob is not a valid attribute...."
– James Grow
Nov 14 '18 at 16:51