chef-provisioning-docker icon indicating copy to clipboard operation
chef-provisioning-docker copied to clipboard

search(:node) does not contain the ipaddress

Open yazgoo opened this issue 9 years ago • 2 comments

Here are two scripts. One creates a machine:

require 'chef/provisioning/docker_driver'
machine "dummy" do
    tag "dummy"
    converge true
    machine_options({ docker_options: {
        base_image: { name: 'baseimage', repository: 'phusion/baseimage', tag: '0.9.17' },
        command: '/sbin/my_init'} })
end

The other searches for it:

require 'chef/provisioning/docker_driver'
search(:node, "tags:*dummy*").map do |node|
    p node.ipaddress
end

When I run these scripts with bundle and this Gemfile:

gem 'chef-provisioning-docker'

The second script works fine.

When I try and run against the master git HEAD version :

gem 'chef-provisioning-docker', :path => '../chef-provisioning-docker' 

I get the following error:

ERROR: Undefined method or attribute `ipaddress' on `node'

yazgoo avatar Sep 17 '15 12:09 yazgoo

Here is a bypass which uses docker inspect to get the ipaddress if it is not set:

class Chef::Resource::Machine
    def running_on? kind
        kind == ENV['CHEF_DRIVER'].sub(/::.*$/, "").to_sym
    end
    def get_docker_ip_address name
        JSON.parse(`docker inspect #{name}`).first["NetworkSettings"]["IPAddress"]
    end
    alias :old_search :search
    def search what, query
        result = old_search what, query
        if what == :node and running_on? :docker
            result.map! do |node|
                node.default["ipaddress"] = get_docker_ip_address(node.name) if node["ipaddress"] == nil
                node
            end
        end
        return result
    end
end

yazgoo avatar Sep 28 '15 09:09 yazgoo

Hm, there are no much changes between 0.7 and master. I personally have ipaddress among node attributes when running CPD. Though, I use forked version of my own without changes introduced by 07753c4520d3364124dbdca434cd102e471b8bb4 .

marc- avatar Sep 28 '15 10:09 marc-