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

Docker inventory service/stack groups for docker swarm #48021

Merged
merged 3 commits into from
Dec 17, 2018

Conversation

sosheskaz
Copy link
Contributor

@sosheskaz sosheskaz commented Nov 3, 2018

SUMMARY

This adds host grouping based on "service" and "stack" to the docker.py inventory script.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

docker.py inventory

ANSIBLE VERSION
ansible 2.7.0
  config file = None
  configured module search path = [u'/home/eric/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.15rc1 (default, Apr 15 2018, 21:51:34) [GCC 7.3.0]
ADDITIONAL INFORMATION

This makes no change to existing functionality but extends the grouping of containers based on image to group on stack and service as well. This is done by conditionally keying the a host's groups off of the labels com.docker.stack.namespace and com.docker.swarm.service.name.

The derived groups are in the format service_<service_name> and stack_<stack_name>

You can find the docker-compose file I used to create these groups here.

Excerpt from "pretty" docker.py output:

$ contrib/inventory/docker.py | jq .service_ansible_mock_host
[
  "ansible_mock_host.2.qo2m6mrmtfy8f8zl64yogsyef",
  "ansible_mock_host.1.hxnrh84blwmscu2pmgl4p5ann",
  "ansible_mock_host.3.sn74oapkk5ay3la148js5z93n",
  "ansible_mock_host.4.zi8jyrocpts7hw8x0sba9k47b",
  "ansible_mock_host.5.i5t8il409jgua2olw1wfw5ucg",
  "ansible_mock_host.3.ly13cxwzvibmuf6volsr8t1z8",
  "ansible_mock_host.2.bkiiay0a48a3koxkgbvvte9me"
]

$ contrib/inventory/docker.py | jq .stack_ansible_mock
[
  "ansible_mock_host.2.qo2m6mrmtfy8f8zl64yogsyef",
  "ansible_mock_host.1.hxnrh84blwmscu2pmgl4p5ann",
  "ansible_mock_host.3.sn74oapkk5ay3la148js5z93n",
  "ansible_mock_host.4.zi8jyrocpts7hw8x0sba9k47b",
  "ansible_mock_host.5.i5t8il409jgua2olw1wfw5ucg",
  "ansible_mock_host.3.ly13cxwzvibmuf6volsr8t1z8",
  "ansible_mock_host.2.bkiiay0a48a3koxkgbvvte9me"
]

# warnings omitted from output for legibility
$ ansible -i contrib/inventory/docker.py 'stack_ansible_mock:&running' \
-m ping -e ansible_connection=docker -e ansible_python_interpreter=/usr/local/bin/python
ansible_mock_host.1.hxnrh84blwmscu2pmgl4p5ann | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
ansible_mock_host.5.i5t8il409jgua2olw1wfw5ucg | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
ansible_mock_host.3.sn74oapkk5ay3la148js5z93n | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
ansible_mock_host.4.zi8jyrocpts7hw8x0sba9k47b | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
ansible_mock_host.2.qo2m6mrmtfy8f8zl64yogsyef | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

@ansibot
Copy link
Contributor

ansibot commented Nov 3, 2018

Hi @sosheskaz, thank you for submitting this pull-request!

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Nov 3, 2018

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 c:inventory/contrib_script community_review In order to be merged, this PR must follow the community review workflow. docker feature This issue/PR relates to a feature request. inventory Inventory category needs_triage Needs a first human triage before being processed. new_contributor This PR is the first contribution by a new community member. support:community This issue/PR relates to code supported by the Ansible community. labels Nov 3, 2018
@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label Nov 5, 2018
@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 Nov 13, 2018
@ansibot ansibot removed 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 Nov 26, 2018
@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 Dec 4, 2018
Copy link
Contributor

@DBendit DBendit left a comment

Choose a reason for hiding this comment

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

This looks great, but you're missing a changelog fragment explaining the change in functionality. See https://docs.ansible.com/ansible/latest/reference_appendices/release_and_maintenance.html#creating-new-fragments. Once you get that added in (which should also trigger another CI run, clearing that label), I can come back and approve this.

@ansibot
Copy link
Contributor

ansibot commented Dec 11, 2018

cc @DBendit
click here for bot help

@sosheskaz
Copy link
Contributor Author

sosheskaz commented Dec 12, 2018

The documentation linked does not mention a type for inventory scripts or a sample format; I made the assumption of minor_changes and named the "module" inventory/docker.

@ansibot ansibot removed 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 Dec 12, 2018
Copy link
Contributor

@DBendit DBendit left a comment

Choose a reason for hiding this comment

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

LGTM

Whoever ends up reviewing this for merge: I know we're done with inventory scripts, but I figure that this modification to an existing one is alright. Let me know if that assumption is incorrect.

@DBendit
Copy link
Contributor

DBendit commented Dec 12, 2018

Also, thank you @sosheskaz for the detailed test instructions. It made it much easier to verify this change!

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.

The changes look good to me, though I cannot say anything specific about inventory scripts.

shipit

@felixfontein
Copy link
Contributor

bot_status

@ansibot
Copy link
Contributor

ansibot commented Dec 12, 2018

Components

changelogs/fragments/inventory-docker-service-stack-groups.yaml
support: community
maintainers:

contrib/inventory/docker.py
support: community
maintainers: DBendit akshay196 danihodovic dariko felixfontein jwitko kassiansun tbouvet

Metadata

waiting_on: maintainer
changes_requested_by: null
needs_info: False
needs_revision: False
needs_rebase: False
merge_commits: []
too many files or commits: False
mergeable_state: clean
shippable_status: success
maintainer_shipits (module maintainers): 1
community_shipits (namespace maintainers): 0
ansible_shipits (core team members): 1
shipit_actors (maintainers or core team members): DBendit felixfontein
shipit_actors_other: []
automerge: automerge is_module test failed

click here for bot help

@ansibot ansibot added shipit This PR is ready to be merged by Core and removed community_review In order to be merged, this PR must follow the community review workflow. labels Dec 12, 2018
@gundalow gundalow merged commit 4d0f2e6 into ansible:devel Dec 17, 2018
@gundalow
Copy link
Contributor

@sosheskaz Thank you, merged into devel for release in Ansible 2.8

@felixfontein
Copy link
Contributor

@sosheskaz thanks for your PR!
@DBendit thanks for reviewing and testing it!
@gundalow thanks for merging :)

kbreit pushed a commit to kbreit/ansible that referenced this pull request Jan 11, 2019
* Adding service and stack grouping to docker inventory

* Updating documentation

* Adding changelog fragment for docker.py inventory script
@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.8 This issue/PR affects Ansible v2.8 c:inventory/contrib_script docker feature This issue/PR relates to a feature request. inventory Inventory category new_contributor This PR is the first contribution by a new community member. shipit This PR is ready to be merged by Core support:community This issue/PR relates to code supported by the Ansible community.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants