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

Setting consul::version in hiera does not change the download_url #129

Closed
centromere opened this issue May 29, 2015 · 17 comments
Closed

Setting consul::version in hiera does not change the download_url #129

centromere opened this issue May 29, 2015 · 17 comments

Comments

@centromere
Copy link

I attempted to set consul::version to 0.5.2 in hiera, but the zip file downloaded is for 0.5.0. I added the following to install.pp:

notify{"Download url: ${$consul::download_url}": }
notify{"Version: ${$consul::version}": }

And this is the output:

Notice: Download url: https://dl.bintray.com/mitchellh/consul/0.5.0_linux_amd64.zip
Notice: Version: 0.5.2
@solarkennedy
Copy link
Contributor

Gosh, that is pretty surprising, but not the first time I've heard of this.
We have a specific test for this?
https://github.com/solarkennedy/puppet-consul/blob/master/spec/classes/init_spec.rb#L78-L83

@EvanKrall
Copy link
Contributor

I think it's that staging::file won't re-download something if the file (zipfile, in our case) already exists; nor will staging::extract extract something if the target already exists.

@centromere
Copy link
Author

I am not certain it is with staging::file. I suspect it might have something to do with the variables getting substituted in an unexpected way (as demonstrated by the test I did).

@solarkennedy
Copy link
Contributor

Yea, it can't be the staging module, this is happening at catalog time.

@centromere can you give us more inputs to work with? Can you paste in more for your hiera and manifests to give us a better picture of how this module is invoked?

@centromere
Copy link
Author

Puppet 3.7.4

site.pp:

node /([a-z]+)\d+$/ {
  $node_role = $1
  hiera_include('classes')
}

hiera.yaml:

:hierarchy:
  - "roles/%{node_role}"
  - common

hiera/common.yaml:

---
classes:
  - myapp_discovery

consul::version: "0.5.2"

inhouse/myapp_discovery/manifests/init.pp:

class myapp_discovery {
  include consul
}

Setting consul::download_url instead of consul::version results in the desired behavior.

@EvanKrall
Copy link
Contributor

If instead of setting consul::version in hiera, you pass version => '0.5.2' when you include consul, does the same behavior happen?

You're right, this isn't staging. It might have to do with the ordering of when $download_url's default gets constructed versus when $version gets set.

@solarkennedy
Copy link
Contributor

I can confirm on a spec test that inserting the version works. It does have something to do with the version parameter being inherited early before the hiera lookup.

I'm trying to write an failing integration test to reproduce.

@potto007
Copy link
Contributor

potto007 commented Jun 4, 2015

I believe this is a side-effect of this 3+ year old issue, which has burned me a number of times in Puppet.

https://projects.puppetlabs.com/issues/9848

Anytime I assign a variable based on other variables inside the parameter definition of the class, it winds up yielding unpredictable results.

@solarkennedy
Copy link
Contributor

Ah! That explains it. I swear I've seen this work before, but I used another internal module today where I tried to do the same thing and it didn't work.

Well, I would accept a PR for something like this:

$version = 0.5.0
$download_url = undef,
) {
  $real_download_url = pick($download_url, 'http://..$version')

That way we don't bother composing the default url unless it wasn't provided, and we parse $version only when we are certain when it is set.

potto007 added a commit to potto007/puppet-consul that referenced this issue Jun 5, 2015
This fixes the ordering issue that can occur in the Puppet AST when class parameters are defined using other class parameters.
potto007 added a commit to potto007/puppet-consul that referenced this issue Jun 5, 2015
This fixes the ordering issue that can occur in the Puppet AST when class parameters are defined using other class parameters.
@potto007
Copy link
Contributor

potto007 commented Jun 5, 2015

I submitted PR 133 to address this. HTH

@solarkennedy
Copy link
Contributor

I've merged it in. Thank you @potto007 ! (especially considering you didn't open the original issue!)

I'm sad I couldn't come up with a test to verify this. I can't guarantee this particular functionality won't be broken in the future without a unit test to watch for it :(

@solarkennedy
Copy link
Contributor

@centromere can you pull master and confirm that this closes your issue?

@potto007
Copy link
Contributor

potto007 commented Jun 6, 2015

@solarkennedy I'll see if I can come up with a few tests to assert this works, and see if I can make at least one that breaks the old code.

Glad to help, I needed it anyway in my infrastructure. :) I'm actually adding something for managing a Docker container based Consul via Upstart ATM - I'll contribute that as a branch when it is clean and see if you want it.

@solarkennedy
Copy link
Contributor

Cool! @potto007 We do have a test on inserting the download_url already, but it doesn't work for this bug because this require more of a kind of "integration" between hiera and junk. A real test of this will require the hiera helper and using similar hiera that @centromere provided. Good luck!

Regarding docker/consul/upstart, that kinda sounds a bit out of scope maybe could be its own module, or an example? But yea I would be happy to see it!

@potto007
Copy link
Contributor

potto007 commented Jun 6, 2015

Yeah, I've done some tests with Hiera involved, I think it should be manageable.

WRT consul-docker: It does seem out of scope, I agree - but the way I am using it, your module actually is quite helpful. I am using host volume mapping against /etc/consul - and Puppet is being used to assign service definitions. Obviously, consul::install doesn't much matter for that case, and service management is not needed in the classical sense... but I still want something to prevent manual intervention, or one-off orchestration kick-off.

The whole reason I have to use Docker in the particular environment I'm now deploying to: it has no private IPs - and I have no control over how our datacenter implements things in that location. Consul doesn't like that type of setup, from what I've learned through my efforts and through reading of GitHub Issues. Consul-Docker gets around this obviously because the bridge network is the "private network" and a simple advertise_addr param with the host's public IP fixes any problems. (hashicorp/consul#725 - for the curious)

@hopperd
Copy link
Contributor

hopperd commented Mar 2, 2016

I believe this issue is now fixed are we ok to close this?

@hopperd
Copy link
Contributor

hopperd commented Mar 25, 2016

Closing as I believe this is fixed now, please re-open if that isn't the case.

@hopperd hopperd closed this as completed Mar 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants