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

Add pre-apply option so we can set Puppet facts #753

Closed
wants to merge 1 commit into from
Closed

Add pre-apply option so we can set Puppet facts #753

wants to merge 1 commit into from

Conversation

ergonlogic
Copy link

@ergonlogic ergonlogic commented Feb 21, 2012

Hi,

There's this great, little known ability in Puppet (well, Facter actually) whereby you can set facts prior to running 'puppet apply' in a fashion similar to altering environment variables using ENV:

# override $operatingsystem for testing purposes
$ FACTER_operatingsystem=Debian puppet -e 'notify { "We are running on $operatingsystem": }'
notice: We are running on Debian

(ref.: Puppet Cookbook)

I modeled 'pre_apply' directly on the 'option' setting for puppet, so that single facts, such as:

config.vm.provision :puppet, :pre_apply   = "FACTER_fqdn='www.ergonlogic.com'"

or an array of facts work equally well:

config.vm.provision :puppet, :pre_apply   = [ "FACTER_domain='ergonlogic.com'", "FACTER_hostname='www'" ]

Let me know if you like the idea and I'll write up some tests to go along with it.

By the way, my hope is to use this for a Vagrant-based project I started called Aegir-up. The itch that led to this little patch is that there's a bug in Puppet that results in incorrect FQDNs on Debian systems when using an internal DNS server.

@ergonlogic
Copy link
Author

ergonlogic commented Feb 21, 2012

BTW, in case anyone reviewing this isn't aware, Puppet's declarative nature makes it impossible (by design) to re-assign variables. Facter-generated facts include information about the server's architecture, kernel, OS, network addresses, timezone, &c., and is commonly extended to pull in any data relevant to the proper installation and setup of applications and services.

Obviously, in production environments, you won't want to use the FACTER_foo = 'bar', but it can be tremendously useful in development and testing of Puppet manifests and modules.

@mitchellh
Copy link
Member

mitchellh commented Feb 24, 2012

Looks almost right. There is a tiny bug in there but I'll fix it and link to the commit here. Since Puppet is supported as a first class guy, I think I'd almost rather do this:

config.vm.provision :puppet, :facter => { "fqdn" => "www.ergonlogic.com", "hostname" => "www" } 

And automatically generate the FACTER business. What do you think of this?

@ergonlogic
Copy link
Author

ergonlogic commented Feb 24, 2012

Thanks for looking at this. I considered something like your suggested :facter => ... and I agree that it's a better solution for assigning FACTER_ facts in Vagrant.

My suggested solution is really more of a hook that would allow arbitrary commands or scripts to be run. Except for also perhaps setting ENV vars prior to a puppet run, I don't have a particular use-case in mind. I've started to read up on Vagrant's plug-in architecture, but to my knowledge, there aren't any other such light-weight hooks in Vagrant, so introducing one here probably isn't the way to go. FWIW, I would love to see pre and post hooks sprinkled throughout Vagrant, as it seem to me that it would make it much easier to extend in all kinds of ways.

@mitchellh
Copy link
Member

mitchellh commented Feb 25, 2012

@ergonlogic I like the idea of light-weight hooks. I probably won't be able to do that before 1.0 but I'll keep that in mind. I strongly agree :)

In the mean time, I think I will use the :facter option. I'll hack on this :)

@mitchellh
Copy link
Member

mitchellh commented Feb 25, 2012

Done, can you pull master and give it a shot?

@mitchellh mitchellh closed this Feb 25, 2012
@ergonlogic
Copy link
Author

ergonlogic commented Feb 27, 2012

Works like a charm. Thanks!

@hashicorp hashicorp locked and limited conversation to collaborators Apr 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants