Added Docker Facts module: issue #57 #58

Open
wants to merge 1 commit into
from

Projects

None yet
@CaptTofu
Contributor
CaptTofu commented Oct 6, 2014

Added docker_facts (fixes #57)

@mpdehaan mpdehaan added the new_module label Dec 8, 2014
@daviddyball

I just wanted to add that I'm currently using @CaptTofu docker_facts module and really like the way it uses a dict for docker_containers. It makes it much easier to target specific information without having to resort to with_items loops in playbooks.

@bcoca
Member
bcoca commented Feb 9, 2015

doesn't this make more sense as part of the docker inventory script?

@daviddyball

I could be wrong, but my understanding was that inventory doesn't update after the play has started. What if task-1 launches 3 containers and task-5 needs to know about them? Knowing their state by adding a docker_facts task and registering the results seems logical to me.

@CaptTofu
Contributor
CaptTofu commented Feb 9, 2015

It’s good to have facts to be able to use in your playbooks. Also, we at HP ATG found that we prefer to use facts modules to write static inventory files (templates) so that we don’t have to rely on accessing the Docker daemon (or Nova API) every time we need to run a play against our instances or containers.

On Feb 8, 2015, at 11:32 PM, Brian Coca notifications@github.com wrote:

doesn't this make more sense as part of the docker inventory script?


Reply to this email directly or view it on GitHub #58 (comment).

@gregdek
Contributor
gregdek commented Jun 16, 2015

Thanks for submitting your module to Ansible Extras. Our policy is that each new module needs to be reviewed and approved by at least two official module reviewers, the list of whom can be found here: https://github.com/ansible/ansible-modules-extras/blob/devel/REVIEWERS.md

If you know someone on that list, please poke them and encourage them to review your module. :)

To ensure that your module has the best chance of being approved, please double-check that you adhere to the Ansible module guidelines: http://docs.ansible.com/developing_modules.html#module-checklist

@gregdek
Contributor
gregdek commented Sep 25, 2015

Adding new process. We will be evaluating all new module PRs according to this process, effective immediately.

Thanks for submitting this new module to Ansible Extras! This module is now in community review, a process that is open to all Ansible users. In order for this module to be approved, it must gain the following votes:

“works_for_me”: If you have tested the module thoroughly, including testing of all of the module’s options, and if the module works for you, please add “works_for_me” in the comments.

“passes_guidelines”: If you have gone through the module guidelines and the module meets all of the requirements, please add “passes_guidelines” in the comments. Guidelines are available here: http://docs.ansible.com/developing_modules.html#module-checklist

“needs_revision”: If the module fails to work for you, or if it doesn’t meet guidelines, please add “needs_revision” in the comments with details about what needs to be fixed.

When a module has both “works_for_me” and “passes_guidelines” tags, we will promote the module for inclusion in Ansible Extras. At this point, you will be expected to maintain the module by fixing bugs and evaluating pull requests in a timely manner.

Thanks again for submitting your Ansible module!

@gregdek
Contributor
gregdek commented Sep 25, 2015

ping to @daviddyball for potential review here under the new process

@robynbergeron robynbergeron removed the P3 label Sep 25, 2015
@daviddyball

@CaptTofu @gregdek

The script has been working for me in all but one case for about 6 months now. The case where it fails is if the container list (equivalent of docker ps -a) contains a container which is Dead. It seems to fail to pop the Name attribute and the script dies. I'm still trying to reproduce it reliably, but I see it frequent enough that I think it could be a problem.

I'll report back if I find anything.

@daviddyball daviddyball commented on the diff Sep 29, 2015
cloud/docker_facts.py
+ '%s' % id)
+
+ return search_list
+
+ def get_facts(self, entities, type='containers'):
+ facts = dict()
+ entity_dict = dict()
+ for entity in entities:
+ id = entity.get('Id')
+ short_id = id[:13]
+ name = short_id
+
+ if type == 'containers':
+ try:
+ name = entity.get('Names', list()).pop(0).lstrip('/')
+ except IndexError:
@daviddyball
daviddyball Sep 29, 2015

Just add AttributeError so that if the resulting list() object is defaulted to, then we catch .pop(0) correctly and then set name = short_name.

@CaptTofu
CaptTofu Oct 23, 2015 Contributor

Hi guys!

Very very sorry for being AWOL - I had my head deeply in getting a code contrib into Kubernetes, plus a back-injury that made it hard to think of anything.

I would LOVE to get docker_facts into Ansible modules extra.

I need to read through these mails— also, would you guys want to do a quick hangout to figure out what I need to do to get this in?

Regards,

Patrick

On Sep 29, 2015, at 10:28 AM, David Dyball notifications@github.com wrote:

In cloud/docker_facts.py #58 (comment):

  •                             '%s' % id)
    
  •    return search_list
    
  • def get_facts(self, entities, type='containers'):
  •    facts = dict()
    
  •    entity_dict = dict()
    
  •    for entity in entities:
    
  •        id = entity.get('Id')
    
  •        short_id = id[:13]
    
  •        name = short_id
    
  •        if type == 'containers':
    
  •            try:
    
  •                name = entity.get('Names', list()).pop(0).lstrip('/')
    
  •            except IndexError:
    
    Just add AttributeError so that if the resulting list() object is defaulted to, then we catch .pop(0) correctly and then set name = short_name.


Reply to this email directly or view it on GitHub https://github.com/ansible/ansible-modules-extras/pull/58/files#r40677962.

@chrismeyersfsu
Member

@daviddyball Does the argument of "inventory doesn't update after the play has started" still hold with the addition of refresh_inventory in Ansible 2.0 ?

@daviddyball

@chrismeyersfsu not 100% sure. I haven't been running develop or 2.0 branch so couldn't say. My production environment is still on 1.9.x

@chrismeyersfsu
Member

@CaptTofu With respect to @bcoca suggestion. Does this make more sense to be a docker inventory script with Ansible 2.0 refresh_inventory feature in mind?

@CaptTofu
Contributor
CaptTofu commented Nov 4, 2015

On Oct 26, 2015, at 11:00 AM, David Dyball notifications@github.com wrote:

@chrismeyersfsu https://github.com/chrismeyersfsu not 100% sure. I haven't been running develop or 2.0 branch so couldn't say. My production environment is still on 1.9.x


Reply to this email directly or view it on GitHub #58 (comment).

Mail app somehow lost the last email in this chain— the question about this being an inventory script, if I understand the question correctly — the reason I wrote this is for more than just needing inventory.

Here’s a use case— one that I showed a friend how to use recently: a setup where I was building out an IPtables setup to set up static IP addresses to map to the private IP addresses and forward ports. With facts, he was able loop through all the running containers, obtain the IP, and print out an “iptables restore” type file that allowed him to do this.

There are other cases as well— namely, those where I want to to be able to iterate and write files or do certain steps with that information where this is useful. Hence why I wrote it :)

@tima
Contributor
tima commented Nov 4, 2015

@CaptTofu Your use cases aren’t anything you couldn’t do thru an inventory script. Facts and inventory variables are folded together under "magic" hostlers variable[1]. Inventory variables have the benefit of inheritance that could come in handy depending on nature of the data you’re working with.

[1] http://docs.ansible.com/ansible/playbooks_variables.html#magic-variables-and-how-to-access-information-about-other-hosts

@jcassee
Contributor
jcassee commented Nov 15, 2015

A use-case that I intend to use this module for: stopping all containers that are not explicitly started from Ansible.

@tima
Contributor
tima commented Nov 15, 2015

@jcassee: What started a container won't matter to Ansible if the dynamic inventory script has been written properly.

@jcassee
Contributor
jcassee commented Nov 16, 2015

@tima Not completely sure what you mean. When I provision a host and Ansible has a list of all containers that should be running, how do I make sure that running containers that are not on that list are stopped? (It is not my intention to use thing issue as a discussion platform, so maybe we should move this to ansible-project.)

@CaptTofu
Contributor

That sounds intesting, though using docker_facts is incredibly simple for me and doesn’t require any invocation the an inventory plugin would. There were some other use-cases as well that I’d have to pull out. I wrote this module due to a suggest by Paul Durivage and Michael Dehaan originally and they had some ideas as well.

In any case, if you guys want it, I’ll be glad to clean it up, do whatever, to get it in and help. Otherwise, I’ll maintain it separately and make available to anyone to use it. That’s the beauty of Ansible— you can write whatever you need to in order to get something done.

Kind regards,

Patrick

On Nov 4, 2015, at 4:31 PM, Timothy Appnel notifications@github.com wrote:

@CaptTofu https://github.com/CaptTofu Your use cases aren’t anything you couldn’t do thru an inventory script. Facts and inventory variables are folded together under "magic" hostlers variable[1]. Inventory variables have the benefit of inheritance that could come in handy depending on nature of the data you’re working with.

[1] http://docs.ansible.com/ansible/playbooks_variables.html#magic-variables-and-how-to-access-information-about-other-hosts http://docs.ansible.com/ansible/playbooks_variables.html#magic-variables-and-how-to-access-information-about-other-hosts

Reply to this email directly or view it on GitHub #58 (comment).

@ansibot
ansibot commented Dec 6, 2016

This repository has been locked. All new issues and pullrequests should be filed in https://github.com/ansible/ansible

Please read through the repomerge page in the dev guide. The guide contains links to tools which automatically move your issue or pullrequest to the ansible/ansible repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment