Puppet provisioner in Vagrant expects site.pp to be US-ASCII, fails with "invalid byte sequence"

StackOverflow https://stackoverflow.com/questions/23201366

  •  07-07-2023
  •  | 
  •  

Question

I have a Vagrant box (Ubuntu 14.04 beta) that configures itself using the Puppet provisioner. After "vagrant up", the shell provisioner runs, installs updates (including language-pack-en), and sets the locale to en_US.UTF-8, e.g.:

export DEBIAN_FRONTEND=noninteractive
echo "LC_ALL=en_US.UTF-8" >> /etc/environment
apt-get update
apt-get -y install language-pack-en
export LC_ALL=en_US.UTF-8
wget https://apt.puppetlabs.com/puppetlabs-release-trusty.deb 2>&1
dpkg -i puppetlabs-release-trusty.deb
apt-get update
apt-get -y upgrade 
apt-get -y -f remove puppet hiera ruby-hiera ruby-safe-yaml
apt-get -y autoremove
apt-get -y install puppet=3.4.3-1

The shell provisioner completes without an issue, however the puppet provisioner fails with this:

Error: Could not parse for environment production: invalid byte sequence in US-ASCII at /tmp/vagrant-puppet-1/manifests/site.pp:1

If I immediately run vagrant provision, the Puppet provisioner runs then without an issue, which makes me suspect it's not respecting the locale I'm setting in both /etc/environment, and exporting as an environment variable for good measure (which may not be necessary, this was a troubleshooting step).

I ran into this first with Ubuntu 13.10, but setting the environment variables resolved the issue - not so with 14.04.

Has anyone run into this before?

Thanks for any advice.

Was it helpful?

Solution

This is caused by the Puppet daemon not reading the correct locale, even though it's previously set by the shell provisioner.

While this could be mitigated by setting LANG=en_US.UTF-8 when the Puppet daemon runs, Vagrant currently doesn't support passing environment variables to Puppet at runtime. The issue is described here: https://github.com/mitchellh/vagrant/issues/2270.

The link above also provides a workaround. The workaround in the issue thread has to do with setting proxy servers as env. variables, but I modified it to set the LANG in a similar way:

Vagrantfile:

config.vm.provision :puppet do |puppet|
  puppet.facter = {
    # Specifying the LANG environment variable this way is a work around.  
    # The work around can be removed when this issue is fixed https://github.com/mitchellh/vagrant/issues/2270
    "hack=hack LANG=en_US.UTF-8 hack" => "hack"
  }

Adding this to Vagrantfile's Puppet provisioner sets the LANG correctly, and Puppet runs as expected on first boot.

OTHER TIPS

When I remember correctly I faced this problem with puppet and the wrong format. It could be stored as dos format.

Else there something within you site.pp that seem wrong. Recreate this file via vim from the vagrant VM.

I hope this can help you.

Best regards.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top