How to get ansible to look in the container that it's running from instead of the servers provided in the...
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
Setup: Ansible initializes and runs from inside a docker container. A git repo which contains the playbooks and inventory files is loaded into this container.
What the playbook does: The specific playbook that I'm working on runs a simple findmnt on all of the hosts listed in the inventory, and writes the output to a flat txt file, which I'm then fetching.
Actual Issue: The ansible container isn't running in the detached mode and so when the run is done, there's no way to retrieve these result txt files. Since there is a git repo layered into the container, I tried stashing these into it, but the command again executes on the inventory-hosts instead of the container from where Ansible is running. I've tried multiple methods to do the same, but am unable to find a way to have ansible do a set of operations within the container that it is running from. How do I handle this situation.
Playbook:
---
- name: get the nfs mounts reports
hosts: 2017_CI
become: true
vars :
nfs_results: "/tmp/{{ host_name }}.txt"
host_name: "{{ inventory_hostname }}"
tasks:
- name: "get the list of nfs mounts on {{ host_name }} "
#shell: 'findmnt -lo source,target,fstype,label,options,used -t nfs'
#AIX nfsstat -m
shell: 'mount -l -t nfs'
register: nfs_output
failed_when: "'FAILED' in nfs_output.stderr"
- name: Store the nfs report ouput file
copy:
content: "{{ nfs_output.stdout }}n"
dest: "{{ nfs_results }}"
owner: root
group: root
mode: 0777
force: yes
register: nfs_results
- name: Fetching the output to ansible host
fetch:
src: "/tmp/{{ inventory_hostname }}.txt"
dest: "/tmp/"
flat: yes
- pause:
minutes: 2
- name: copying file with permissions
copy:
src: "/tmp/{{ inventory_hostname }}.txt"
dest: "/data/web/nfsmountInfo/"
owner: root
group: root
mode: 0777
# - name: Transfer file from ServerA to ServerB
# synchronize:
# src: "/tmp/{{ inventory_hostname }}.txt"
# dest: "/data/web/nfsmountInfo/"
# mode: push
# delegate_to: "localhost"
# become: yes
# become_user: root
# - pause:
# minutes: 1
# - name: git configuration fo email setup
# git_config:
# name: user.email
# scope: global
# value: 'xxxx@x.com'
# - name: git configuration fo email setup
# git_config:
# name: user.name
# scope: global
# value: 'myUser'
# - name: Add the files into staging workspace
# shell: git add .
# args:
# chdir: '/home/jenkins/workspace/TestPipelines/NFSTestAnsible/nfsmountInfo/'
# - name: Commit the changes
# shell: git commit -m "Update the nfsmount reports"
# args:
# chdir: '/home/jenkins/workspace/TestSaddamPipelines/NFSTestAnsible/nfsmountInfo/'
# - name: Set origin to include username and password.
# shell: "git remote set-url origin https://user@http://<gitServer>/inf-build-ansible.git"
# - name: Push to origin.
# shell: "git push origin nfs-mnt-testing"
docker rhel ansible-2.x
add a comment |
Setup: Ansible initializes and runs from inside a docker container. A git repo which contains the playbooks and inventory files is loaded into this container.
What the playbook does: The specific playbook that I'm working on runs a simple findmnt on all of the hosts listed in the inventory, and writes the output to a flat txt file, which I'm then fetching.
Actual Issue: The ansible container isn't running in the detached mode and so when the run is done, there's no way to retrieve these result txt files. Since there is a git repo layered into the container, I tried stashing these into it, but the command again executes on the inventory-hosts instead of the container from where Ansible is running. I've tried multiple methods to do the same, but am unable to find a way to have ansible do a set of operations within the container that it is running from. How do I handle this situation.
Playbook:
---
- name: get the nfs mounts reports
hosts: 2017_CI
become: true
vars :
nfs_results: "/tmp/{{ host_name }}.txt"
host_name: "{{ inventory_hostname }}"
tasks:
- name: "get the list of nfs mounts on {{ host_name }} "
#shell: 'findmnt -lo source,target,fstype,label,options,used -t nfs'
#AIX nfsstat -m
shell: 'mount -l -t nfs'
register: nfs_output
failed_when: "'FAILED' in nfs_output.stderr"
- name: Store the nfs report ouput file
copy:
content: "{{ nfs_output.stdout }}n"
dest: "{{ nfs_results }}"
owner: root
group: root
mode: 0777
force: yes
register: nfs_results
- name: Fetching the output to ansible host
fetch:
src: "/tmp/{{ inventory_hostname }}.txt"
dest: "/tmp/"
flat: yes
- pause:
minutes: 2
- name: copying file with permissions
copy:
src: "/tmp/{{ inventory_hostname }}.txt"
dest: "/data/web/nfsmountInfo/"
owner: root
group: root
mode: 0777
# - name: Transfer file from ServerA to ServerB
# synchronize:
# src: "/tmp/{{ inventory_hostname }}.txt"
# dest: "/data/web/nfsmountInfo/"
# mode: push
# delegate_to: "localhost"
# become: yes
# become_user: root
# - pause:
# minutes: 1
# - name: git configuration fo email setup
# git_config:
# name: user.email
# scope: global
# value: 'xxxx@x.com'
# - name: git configuration fo email setup
# git_config:
# name: user.name
# scope: global
# value: 'myUser'
# - name: Add the files into staging workspace
# shell: git add .
# args:
# chdir: '/home/jenkins/workspace/TestPipelines/NFSTestAnsible/nfsmountInfo/'
# - name: Commit the changes
# shell: git commit -m "Update the nfsmount reports"
# args:
# chdir: '/home/jenkins/workspace/TestSaddamPipelines/NFSTestAnsible/nfsmountInfo/'
# - name: Set origin to include username and password.
# shell: "git remote set-url origin https://user@http://<gitServer>/inf-build-ansible.git"
# - name: Push to origin.
# shell: "git push origin nfs-mnt-testing"
docker rhel ansible-2.x
You would really need to show us your playbooks (to start with) before we could begin to answer your question. Generally, if you have a play that targetslocalhost, that means "the place where Ansible is running".
– larsks
Jan 4 at 12:33
Sure, here is the playbook. I had to replace some values to avoid violations, editing the main question to add the playbook part:
– Funkfan82
Jan 4 at 12:48
add a comment |
Setup: Ansible initializes and runs from inside a docker container. A git repo which contains the playbooks and inventory files is loaded into this container.
What the playbook does: The specific playbook that I'm working on runs a simple findmnt on all of the hosts listed in the inventory, and writes the output to a flat txt file, which I'm then fetching.
Actual Issue: The ansible container isn't running in the detached mode and so when the run is done, there's no way to retrieve these result txt files. Since there is a git repo layered into the container, I tried stashing these into it, but the command again executes on the inventory-hosts instead of the container from where Ansible is running. I've tried multiple methods to do the same, but am unable to find a way to have ansible do a set of operations within the container that it is running from. How do I handle this situation.
Playbook:
---
- name: get the nfs mounts reports
hosts: 2017_CI
become: true
vars :
nfs_results: "/tmp/{{ host_name }}.txt"
host_name: "{{ inventory_hostname }}"
tasks:
- name: "get the list of nfs mounts on {{ host_name }} "
#shell: 'findmnt -lo source,target,fstype,label,options,used -t nfs'
#AIX nfsstat -m
shell: 'mount -l -t nfs'
register: nfs_output
failed_when: "'FAILED' in nfs_output.stderr"
- name: Store the nfs report ouput file
copy:
content: "{{ nfs_output.stdout }}n"
dest: "{{ nfs_results }}"
owner: root
group: root
mode: 0777
force: yes
register: nfs_results
- name: Fetching the output to ansible host
fetch:
src: "/tmp/{{ inventory_hostname }}.txt"
dest: "/tmp/"
flat: yes
- pause:
minutes: 2
- name: copying file with permissions
copy:
src: "/tmp/{{ inventory_hostname }}.txt"
dest: "/data/web/nfsmountInfo/"
owner: root
group: root
mode: 0777
# - name: Transfer file from ServerA to ServerB
# synchronize:
# src: "/tmp/{{ inventory_hostname }}.txt"
# dest: "/data/web/nfsmountInfo/"
# mode: push
# delegate_to: "localhost"
# become: yes
# become_user: root
# - pause:
# minutes: 1
# - name: git configuration fo email setup
# git_config:
# name: user.email
# scope: global
# value: 'xxxx@x.com'
# - name: git configuration fo email setup
# git_config:
# name: user.name
# scope: global
# value: 'myUser'
# - name: Add the files into staging workspace
# shell: git add .
# args:
# chdir: '/home/jenkins/workspace/TestPipelines/NFSTestAnsible/nfsmountInfo/'
# - name: Commit the changes
# shell: git commit -m "Update the nfsmount reports"
# args:
# chdir: '/home/jenkins/workspace/TestSaddamPipelines/NFSTestAnsible/nfsmountInfo/'
# - name: Set origin to include username and password.
# shell: "git remote set-url origin https://user@http://<gitServer>/inf-build-ansible.git"
# - name: Push to origin.
# shell: "git push origin nfs-mnt-testing"
docker rhel ansible-2.x
Setup: Ansible initializes and runs from inside a docker container. A git repo which contains the playbooks and inventory files is loaded into this container.
What the playbook does: The specific playbook that I'm working on runs a simple findmnt on all of the hosts listed in the inventory, and writes the output to a flat txt file, which I'm then fetching.
Actual Issue: The ansible container isn't running in the detached mode and so when the run is done, there's no way to retrieve these result txt files. Since there is a git repo layered into the container, I tried stashing these into it, but the command again executes on the inventory-hosts instead of the container from where Ansible is running. I've tried multiple methods to do the same, but am unable to find a way to have ansible do a set of operations within the container that it is running from. How do I handle this situation.
Playbook:
---
- name: get the nfs mounts reports
hosts: 2017_CI
become: true
vars :
nfs_results: "/tmp/{{ host_name }}.txt"
host_name: "{{ inventory_hostname }}"
tasks:
- name: "get the list of nfs mounts on {{ host_name }} "
#shell: 'findmnt -lo source,target,fstype,label,options,used -t nfs'
#AIX nfsstat -m
shell: 'mount -l -t nfs'
register: nfs_output
failed_when: "'FAILED' in nfs_output.stderr"
- name: Store the nfs report ouput file
copy:
content: "{{ nfs_output.stdout }}n"
dest: "{{ nfs_results }}"
owner: root
group: root
mode: 0777
force: yes
register: nfs_results
- name: Fetching the output to ansible host
fetch:
src: "/tmp/{{ inventory_hostname }}.txt"
dest: "/tmp/"
flat: yes
- pause:
minutes: 2
- name: copying file with permissions
copy:
src: "/tmp/{{ inventory_hostname }}.txt"
dest: "/data/web/nfsmountInfo/"
owner: root
group: root
mode: 0777
# - name: Transfer file from ServerA to ServerB
# synchronize:
# src: "/tmp/{{ inventory_hostname }}.txt"
# dest: "/data/web/nfsmountInfo/"
# mode: push
# delegate_to: "localhost"
# become: yes
# become_user: root
# - pause:
# minutes: 1
# - name: git configuration fo email setup
# git_config:
# name: user.email
# scope: global
# value: 'xxxx@x.com'
# - name: git configuration fo email setup
# git_config:
# name: user.name
# scope: global
# value: 'myUser'
# - name: Add the files into staging workspace
# shell: git add .
# args:
# chdir: '/home/jenkins/workspace/TestPipelines/NFSTestAnsible/nfsmountInfo/'
# - name: Commit the changes
# shell: git commit -m "Update the nfsmount reports"
# args:
# chdir: '/home/jenkins/workspace/TestSaddamPipelines/NFSTestAnsible/nfsmountInfo/'
# - name: Set origin to include username and password.
# shell: "git remote set-url origin https://user@http://<gitServer>/inf-build-ansible.git"
# - name: Push to origin.
# shell: "git push origin nfs-mnt-testing"
docker rhel ansible-2.x
docker rhel ansible-2.x
edited Jan 4 at 12:54
Funkfan82
asked Jan 4 at 11:58
Funkfan82Funkfan82
82
82
You would really need to show us your playbooks (to start with) before we could begin to answer your question. Generally, if you have a play that targetslocalhost, that means "the place where Ansible is running".
– larsks
Jan 4 at 12:33
Sure, here is the playbook. I had to replace some values to avoid violations, editing the main question to add the playbook part:
– Funkfan82
Jan 4 at 12:48
add a comment |
You would really need to show us your playbooks (to start with) before we could begin to answer your question. Generally, if you have a play that targetslocalhost, that means "the place where Ansible is running".
– larsks
Jan 4 at 12:33
Sure, here is the playbook. I had to replace some values to avoid violations, editing the main question to add the playbook part:
– Funkfan82
Jan 4 at 12:48
You would really need to show us your playbooks (to start with) before we could begin to answer your question. Generally, if you have a play that targets
localhost, that means "the place where Ansible is running".– larsks
Jan 4 at 12:33
You would really need to show us your playbooks (to start with) before we could begin to answer your question. Generally, if you have a play that targets
localhost, that means "the place where Ansible is running".– larsks
Jan 4 at 12:33
Sure, here is the playbook. I had to replace some values to avoid violations, editing the main question to add the playbook part:
– Funkfan82
Jan 4 at 12:48
Sure, here is the playbook. I had to replace some values to avoid violations, editing the main question to add the playbook part:
– Funkfan82
Jan 4 at 12:48
add a comment |
1 Answer
1
active
oldest
votes
You can delegate_to: 127.0.0.1 or use the shorthand local_action on a per task-basis (ref. https://docs.ansible.com/ansible/latest/user_guide/playbooks_delegation.html) for example:
---
- hosts: all
tasks:
- name: run task on inventory hosts
debug:
msg: 'this task will execute on all hosts'
- name: delegate task to 127.0.0.1
debug:
msg: 'this task is delegated to the ansible control server'
delegate_to: 127.0.0.1
- name: use the local_action syntax for delegation
local_action:
module: debug
msg: 'executing on the control server'
Thanks that's what solved the issue....
– Funkfan82
Jan 30 at 19:21
@Funkfan82 Great, don't hesitate to accept the answer if it helped and / or if you believe it could help others.
– masseyb
Jan 30 at 19:22
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%2f54038558%2fhow-to-get-ansible-to-look-in-the-container-that-its-running-from-instead-of-th%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 can delegate_to: 127.0.0.1 or use the shorthand local_action on a per task-basis (ref. https://docs.ansible.com/ansible/latest/user_guide/playbooks_delegation.html) for example:
---
- hosts: all
tasks:
- name: run task on inventory hosts
debug:
msg: 'this task will execute on all hosts'
- name: delegate task to 127.0.0.1
debug:
msg: 'this task is delegated to the ansible control server'
delegate_to: 127.0.0.1
- name: use the local_action syntax for delegation
local_action:
module: debug
msg: 'executing on the control server'
Thanks that's what solved the issue....
– Funkfan82
Jan 30 at 19:21
@Funkfan82 Great, don't hesitate to accept the answer if it helped and / or if you believe it could help others.
– masseyb
Jan 30 at 19:22
add a comment |
You can delegate_to: 127.0.0.1 or use the shorthand local_action on a per task-basis (ref. https://docs.ansible.com/ansible/latest/user_guide/playbooks_delegation.html) for example:
---
- hosts: all
tasks:
- name: run task on inventory hosts
debug:
msg: 'this task will execute on all hosts'
- name: delegate task to 127.0.0.1
debug:
msg: 'this task is delegated to the ansible control server'
delegate_to: 127.0.0.1
- name: use the local_action syntax for delegation
local_action:
module: debug
msg: 'executing on the control server'
Thanks that's what solved the issue....
– Funkfan82
Jan 30 at 19:21
@Funkfan82 Great, don't hesitate to accept the answer if it helped and / or if you believe it could help others.
– masseyb
Jan 30 at 19:22
add a comment |
You can delegate_to: 127.0.0.1 or use the shorthand local_action on a per task-basis (ref. https://docs.ansible.com/ansible/latest/user_guide/playbooks_delegation.html) for example:
---
- hosts: all
tasks:
- name: run task on inventory hosts
debug:
msg: 'this task will execute on all hosts'
- name: delegate task to 127.0.0.1
debug:
msg: 'this task is delegated to the ansible control server'
delegate_to: 127.0.0.1
- name: use the local_action syntax for delegation
local_action:
module: debug
msg: 'executing on the control server'
You can delegate_to: 127.0.0.1 or use the shorthand local_action on a per task-basis (ref. https://docs.ansible.com/ansible/latest/user_guide/playbooks_delegation.html) for example:
---
- hosts: all
tasks:
- name: run task on inventory hosts
debug:
msg: 'this task will execute on all hosts'
- name: delegate task to 127.0.0.1
debug:
msg: 'this task is delegated to the ansible control server'
delegate_to: 127.0.0.1
- name: use the local_action syntax for delegation
local_action:
module: debug
msg: 'executing on the control server'
answered Jan 30 at 19:11
masseybmasseyb
4321313
4321313
Thanks that's what solved the issue....
– Funkfan82
Jan 30 at 19:21
@Funkfan82 Great, don't hesitate to accept the answer if it helped and / or if you believe it could help others.
– masseyb
Jan 30 at 19:22
add a comment |
Thanks that's what solved the issue....
– Funkfan82
Jan 30 at 19:21
@Funkfan82 Great, don't hesitate to accept the answer if it helped and / or if you believe it could help others.
– masseyb
Jan 30 at 19:22
Thanks that's what solved the issue....
– Funkfan82
Jan 30 at 19:21
Thanks that's what solved the issue....
– Funkfan82
Jan 30 at 19:21
@Funkfan82 Great, don't hesitate to accept the answer if it helped and / or if you believe it could help others.
– masseyb
Jan 30 at 19:22
@Funkfan82 Great, don't hesitate to accept the answer if it helped and / or if you believe it could help others.
– masseyb
Jan 30 at 19:22
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%2f54038558%2fhow-to-get-ansible-to-look-in-the-container-that-its-running-from-instead-of-th%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
You would really need to show us your playbooks (to start with) before we could begin to answer your question. Generally, if you have a play that targets
localhost, that means "the place where Ansible is running".– larsks
Jan 4 at 12:33
Sure, here is the playbook. I had to replace some values to avoid violations, editing the main question to add the playbook part:
– Funkfan82
Jan 4 at 12:48