DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Serving Files with Puppet Standalone in Vagrant From the puppet:// URIs

Jakub Holý user avatar by
Jakub Holý
·
Jun. 25, 12 · Interview
Like (0)
Save
Tweet
Share
11.73K Views

Join the DZone community and get the full member experience.

Join For Free

If you use Puppet in the client-server mode to configure your production environment then you might want to be able to copy & paste from the prod configuration into the Vagrant’s standalone puppet‘s configuration to test stuff. One of the key features necessary for that is enabling file serving via “source => ‘puppet:///path/to/file’”. In the client-server mode the files are served by the server, in the standalone mode you can configure puppet to read from a local (likely shared) folder. We will see how to do this.

Credits: This post is based heavily on Akumria’s answer at StackOverflow: how to source a file in puppet manifest from module.

Enabling Puppet Standalone in Vagrant to Resolve puppet:///…

Quick overview:

  1. Make the directory with the files to be served available to the Vagrant VM
  2. Create fileserver.conf to inform Puppet about the directory
  3. Tell puppet about the fileserver.conf
  4. Use it

1. Make the directory with the files to be served available to the Vagrant VM

For example as a shared folder:

# Snippet of <vagrant directory>/Vagrantfile
config.vm.share_folder "PuppetFiles", "/etc/puppet/files", "./puppet-files-symlink"

(In my case this is actually a symlink to the actual folder in our puppet git repository. Beware that symlinks inside shared folders often don’t work and thus it’s better to use the symlink as a standalone shared folder root.)

Notice you don’t need to declare a shared folder

2. Create fileserver.conf to inform Puppet about the directory

You need to tell to Puppet that the source”puppet:///files/” should be served from /etc/puppet/files/:

# <vagrant directory>/fileserver.conf
[files]
  path /etc/puppet/files
  allow *

3. Tell puppet about the fileserver.conf

Puppet needs to know that it should read the fileserver.conf file:

# Snippet of <vagrant directory>/Vagrantfile
config.vm.provision :puppet,
  :options => ["--fileserverconfig=/vagrant/fileserver.conf"],
  :facter => { "fqdn" => "vagrant.vagrantup.com" } do |puppet|
     ...
end

4. Use it

vagrant_dir$ echo "dummy content" > ./puppet-files-symlink/example-file.txt
# Snippet of <vagrant directory>/manifests/<my manifest>.pp
 ...
file{'/tmp/example-file.txt':
  ensure => file,
  source => 'puppet:///files/example-file.txt',
}
...

Caveats

URLs with server name (puppet://puppet/) don’t work

URLs like puppet://puppet/files/path/to/file don’t work, you must use puppet:///files/path/to/file instead (empty, i.e. implicit, server name => three slashes).

The reason is, I believe, that if you state the server name explicitely then Puppet will try to find the server and get the files from there (that might be a desirable behavior if you run Puppet Master locally or elsewhere; in that case just add the server name to /etc/hosts in the Vagrant VM or make sure the DNS server used can resolve it). On the other hand, if you leave the server name out and rely on the implicit value then Puppet in the standalone mode will consult its fileserver.conf and behave accordingly. (Notice that in the server-client mode the implicit server name equals the puppet master, i.e. puppet:/// works perfectly well there.)

If you use puppet://puppet/files/... then you’ll get an error like this:

err: /Stage[main]/My_example_class/File[fetch_cdn_logs.py]: Could not evaluate: 
getaddrinfo: Name or service not known Could not retrieve file metadata for puppet://puppet/files/analytics/fetch_cdn_logs.py: 
getaddrinfo: Name or service not known at /tmp/vagrant-puppet/manifests/analytics_dev.pp:283

Environment

Puppet: 2.7.14, Vagrant:1.0.2

 

 

 

 

 

 

 

Published at DZone with permission of Jakub Holý, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • A Gentle Introduction to Kubernetes
  • Journey to Event Driven, Part 1: Why Event-First Programming Changes Everything
  • What Are the Benefits of Java Module With Example
  • A Beginner's Guide to Infrastructure as Code

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: