-
Notifications
You must be signed in to change notification settings - Fork 23.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable docker connector command override. #16198
Conversation
There are no tests for this, but I would like to add some. The reason there's no tests is because:
|
If a hostvar 'docker_command' is present, it will be used in preference to the default. This enables, for example, the use of ssh to connect to a remote docker daemon instead of trying to connect to it directly, which is useful if you are using ssh jumphosts. Example config: - name: Add containers to inventory add_host: name: "foo-{{item}}" groups: mygroup ansible_connection: docker docker_command: "/usr/bin/ssh {{hostvars[item].ansible_ssh_host}} docker" with_items: groups.containerhosts This will iterate over all hosts in the 'containerhosts' group, add a previously-created container to the inventory, and make sure it's accessed via SSH through the original hosts.
4c6fd6d
to
eb838d0
Compare
This PR is now so old that it got conflicts. Is anyone interested in reviewing this? How do I get code to land in Ansible? |
@bigjools from a quick look at http://docs.ansible.com/ansible/latest/docker_module.html this looks to be implemented. Can you confirm? If this is not still of interest can you close please. |
@lathama It looks like that module is deprecated (and I didn't find any equivalent to my change anyway?). I looked at http://docs.ansible.com/ansible/latest/docker_container_module.html#docker-container as well and I didn't see anything there either, I think it assumes direct connectivity to the docker daemon. What next? |
@staticmethod | ||
def _sanitize_version(version): | ||
return re.sub('[^0-9a-zA-Z\.]', '', version) | ||
|
||
def _get_docker_version(self): | ||
|
||
cmd = [self.docker_cmd] | ||
# Force a quick copy, don't want to mutate base command. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain this a bit more? I don't think anything is wrong, I just don't understand :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the line would be cmd = self.docker_cmd
, the original value of self.docker_cmd
(which is a list) would be modified by the cmd += ...
's below. That's why a copy must be created.
@@ -120,8 +139,8 @@ def _get_docker_version(self): | |||
return self._sanitize_version(line.split()[2]) | |||
|
|||
# no result yet, must be newer Docker version | |||
new_docker_cmd = [ | |||
self.docker_cmd, | |||
# NOTE(bigjools): Is this missing docker_extra_args? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm? is what missing docker_extra_args?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is added in some other cases (but not all).
I think this is a pretty neat option to have. My only concern is that how will anyone know that this is available for them to use? Is it possible to add some documentation surrounding this? Also thoughts on an integration test to spin up and connect to a container using this method? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before it makes any sense to continue discussing this, you really need to rebase to current devel
. This PR is based on a pretty old version of the codebase. The current codebase for example has documentation in docker.py
, which doesn't even exist here.
(Also, note that the synchronize
action plugin has some docker connection plugin specific code, which probably has to be adjusted as well.)
@staticmethod | ||
def _sanitize_version(version): | ||
return re.sub('[^0-9a-zA-Z\.]', '', version) | ||
|
||
def _get_docker_version(self): | ||
|
||
cmd = [self.docker_cmd] | ||
# Force a quick copy, don't want to mutate base command. | ||
cmd = [] + self.docker_cmd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should either use
cmd = [] + self.docker_cmd | |
cmd = self.docker_cmd[:] |
or
cmd = [] + self.docker_cmd | |
cmd = list(self.docker_cmd) |
@@ -633,7 +633,8 @@ def _get_connection(self, variables, templar): | |||
except OSError: | |||
conn_type = "paramiko" | |||
|
|||
connection = self._shared_loader_obj.connection_loader.get(conn_type, self._play_context, self._new_stdin) | |||
connection = self._shared_loader_obj.connection_loader.get( | |||
conn_type, self._play_context, self._new_stdin, variables=variables) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably needs a core review.
else: | ||
self.docker_cmd = distutils.spawn.find_executable('docker') | ||
if not self.docker_cmd: | ||
raise AnsibleError("docker command not found in PATH") | ||
self.docker_cmd = self._split_cmd(self.docker_cmd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
@@ -150,7 +172,8 @@ def _build_exec_cmd(self, cmd): | |||
version we are using, it will be provided to docker exec. | |||
""" | |||
|
|||
local_cmd = [self.docker_cmd] | |||
# Force a quick copy, don't want to mutate base command. | |||
local_cmd = [] + self.docker_cmd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also change this one, please.
@@ -120,8 +139,8 @@ def _get_docker_version(self): | |||
return self._sanitize_version(line.split()[2]) | |||
|
|||
# no result yet, must be newer Docker version | |||
new_docker_cmd = [ | |||
self.docker_cmd, | |||
# NOTE(bigjools): Is this missing docker_extra_args? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is added in some other cases (but not all).
@bigjools are you still around? Can you rebase to remove the conflicts? |
Hi yes I am still around. Given that it's taken 2 years to get a review, I've long moved on to different projects and I have lost the context for this change. Sorry. If someone wants to take it over, that's fine. |
I'm sorry it took so long until you got a review! The docker modules have been looking for a maintainer for some time; and it looks like that the docker connection plugin never had someone looking after it. Anyway, thanks for your effort! I hope that someone will use it as a basis for a new PR for this feature. |
No problem, it happens sometimes on busy projects. And yes if someone needs
this in the future, hopefully this is of some use.
…On Fri, 30 Nov 2018 at 17:14, Felix Fontein ***@***.***> wrote:
I'm sorry it took so long until you got a review! The docker modules have
been looking for a maintainer for some time; and it looks like that the
docker connection plugin never had someone looking after it.
Anyway, thanks for your effort! I hope that someone will use it as a basis
for a new PR for this feature.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#16198 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ALHikdmmTcTL3C9S6K3G6mPut8vsIfJ_ks5u0NrkgaJpZM4IxijL>
.
|
@bigjools Yup, sorry that this didn't get the reviews it deserved at the time. Hi,
If you're the PR author, and you want to start the conversation back up, please:
If you're a community member, and you want to see this change merged, please:
If you've like to help with the Docker modules please comment on the Docker Agenda/Task List How to rebase a branch: https://docs.ansible.com/ansible/latest/dev_guide/developing_rebasing.html |
ISSUE TYPE
ANSIBLE VERSION
SUMMARY
If a hostvar 'docker_command' is present, it will be used in preference
to the default 'docker' command which runs locally. This enables, for
example, the use of ssh to connect to a remote docker daemon
instead of trying to connect to it directly, which is useful if you are using
ssh jumphosts.
Example config:
This will iterate over all hosts in the 'containerhosts' group, add
a previously-created container to the inventory, and make sure it's
accessed via SSH through the original hosts.