Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

bigjools
Copy link

@bigjools bigjools commented Jun 9, 2016

ISSUE TYPE
  • Feature Pull Request
ANSIBLE VERSION
2.2.0 0.0.devel from VERSION file
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:

- 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.

@bigjools
Copy link
Author

bigjools commented Jun 9, 2016

There are no tests for this, but I would like to add some. The reason there's no tests is because:

  • there are no existing tests that I can see at all for the docker connection
  • the _get_connection() method in the task exector has no unit tests itself, so I can't verify that the change is correctly passing the variables
    I would welcome some suggestions since I am new to the Ansible code.

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.
@bigjools
Copy link
Author

bigjools commented Sep 6, 2016

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?

@ansibot ansibot added affects_2.3 This issue/PR affects Ansible v2.3 cloud docker needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Dec 13, 2016
@ansibot ansibot added needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Jan 2, 2017
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Apr 11, 2017
@ansibot ansibot added the support:core This issue/PR relates to code supported by the Ansible Engineering Team. label Jun 29, 2017
@calfonso calfonso requested a review from ryansb August 2, 2017 18:12
@lathama
Copy link
Contributor

lathama commented Sep 23, 2017

@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.

@bigjools
Copy link
Author

@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?

@ansibot ansibot added the new_contributor This PR is the first contribution by a new community member. label Oct 18, 2017
@ansibot ansibot removed the new_contributor This PR is the first contribution by a new community member. label Nov 3, 2017
@ansibot ansibot added the new_contributor This PR is the first contribution by a new community member. label Jan 22, 2018
@ansibot ansibot added feature This issue/PR relates to a feature request. and removed feature_pull_request labels Mar 2, 2018
@ansibot
Copy link
Contributor

ansibot commented Sep 18, 2018

@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.
Copy link
Contributor

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 :)

Copy link
Contributor

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?
Copy link
Contributor

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?

Copy link
Contributor

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).

@jwitko
Copy link
Contributor

jwitko commented Oct 23, 2018

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?

Copy link
Contributor

@felixfontein felixfontein left a 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should either use

Suggested change
cmd = [] + self.docker_cmd
cmd = self.docker_cmd[:]

or

Suggested change
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)
Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

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?
Copy link
Contributor

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).

@ansibot
Copy link
Contributor

ansibot commented Oct 31, 2018

@ansibot ansibot added the support:community This issue/PR relates to code supported by the Ansible community. label Nov 26, 2018
@felixfontein
Copy link
Contributor

@bigjools are you still around? Can you rebase to remove the conflicts?

@bigjools
Copy link
Author

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.

@felixfontein
Copy link
Contributor

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.

@bigjools
Copy link
Author

bigjools commented Dec 2, 2018 via email

@gundalow
Copy link
Contributor

gundalow commented Dec 4, 2018

@bigjools Yup, sorry that this didn't get the reviews it deserved at the time.

Hi,
This PR seems to have gotten stuck, so we are going to close it. We like to include community contributions, so this is a difficult call for us. Here's why we're closing this one:

  • Given the discussion in Docker Agenda/Task list community#408 (comment)
  • It was created from an old version of the code
  • We want to clear out the backlog so it's easier to find bug fixes
  • There haven't been any comments or other activity in a long time

If you're the PR author, and you want to start the conversation back up, please:

  • reopen the PR and
  • rebase the branch

If you're a community member, and you want to see this change merged, please:

  • Create a new PR and
  • Reference this author in the git commit & PR and
  • Reference this PR in the new PR

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
How to communicate with the Ansible community: https://docs.ansible.com/ansible/devel/community/communication.html
How to contribute to Ansible: https://docs.ansible.com/ansible/devel/community/index.html

@gundalow gundalow closed this Dec 4, 2018
@ansible ansible locked and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.3 This issue/PR affects Ansible v2.3 c:executor/task_executor c:plugins/connection/docker c:plugins/connection cloud docker executor/task_executor feature This issue/PR relates to a feature request. needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. new_contributor This PR is the first contribution by a new community member. plugins/connection/docker stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants