Symlinking a vagrant shared folder with puppet - puppet

I'm needing to recreate a setup on an old server with vagrant where we served sites within the home directory. Its not possible to set a shared folder to /home in vagrant as this will remove the vagrant user. I therefore would like to create a shared folder that is actually a symlink to the home directory.
If I create a shared directory like this in my Vagrantfile:
config.vm.share_folder "v-www", "/webroot", "/Users/me/sites/vagrant"
and then try and create a symlink with puppet overwriting this directory like this:
class misc {
file { '/webroot':
ensure => 'link',
target => '/home',
force => true,
}
}
It throws an error:
Error: Could not remove existing file
Error: /Stage[main]/Misc/File[/webroot]/ensure: change from directory
to link failed: Could not remove existing file
When I log into the box and attempt this manually this also fails as i'm not actually able to remove the webroot - I assume this is because its created as some kind nfs share or something like that.
Any ideas how I can get around this?

Try adding a replace:
class misc {
file { '/webroot':
ensure => 'link',
target => '/home',
force => true,
replace => true,
}
}

Related

Nodejs fs.copyfile not allowed for copy a file to the destination folder

I am trying to copy a file from one location to another so I'm using this:
fs.copyFile('C:\\Users\\Me\\Documents\\myfile.zip', c:\\myfiles
console.log('file was copied successfully!');
});
I can see that the destination folder is readonly so that's why I'm getting this.
How can I change it's status on my windows pc.
I've tried this but nothing is happening and I still get the error:
fs.chmodSync('c:\\myfiles', 0o755);
How can I fix this issue?
You are using Windows, I guest C:\ is your system disk (where you install the Windows).
If you want to write a file to c:\myfiles , it require you Administrator permission (you can try by way: copy and paste a file to the folder, by hand).
Solution:
Option1: Change your folder, ex: D:\myfiles
Option2: Use windows file manager, change your folder permission (everyone read/write)

Puppet: how to use ignore globbing on file resources

Consider the following puppet config snippet:
file { "/opt/app/${name}/traces" :
ensure => directory,
owner => 'appuser',
group => 'appuser',
ignore => [ '*.tra' ],
backup => false,
recurse => false
}
The folder will contain "${name}..tra" files and I don't want puppet to take care of these files.
When calling strace or lsof against the puppet client, I can see it still tries to do something with these files (probably checksuming, according to the time spent on each file).
Thanks a lot,
Adam.

Puppet creates a broken symlink

For example I have a symlink /etc/foo/folder11/some/link.txt which points to etc/foo/folder12/some/file.txt.
And in puppet I have the following
ensure_resource('file', "/etc/bar/link.txt", {
owner => $someUser,
mode => '0444',
source => `/etc/foo/folder11/some/link.txt`,
})
After puppet run it creates a broken symlink /etc/bar/link.txt which points to ../../folder12/some/file.txt.
Why does it create so strange symlink? And how can I force puppet to create /etc/foo/link.txt symlink which should point to the same file to which /etc/foo/folder11/some/link.txt points to ?
Note that I don't use ensure => link because sometimes /etc/foo/folder11/some/link.txt may be a regular file and in this case /etc/bar/link.txt should be a copy of this file.
As it turned out the problem was in /etc/foo/folder11/some/link.txt which was a relative symlink. I changed it to be absolute and now it works fine.

Customize CFEngine3 temporary downloaded files location

I am facing a issue while trying configuring something with CFENGINE3.5, I have created a policy to install some package from source, which download tar balls from some url and then untar it and further digs it with make and make install, everything working fine except while it download tar balls it keeps at "/etc" location, I want cfengine to put this file at /tmp.
Is there any way to customize this default behavior of cfengine to keep all temporary downloaded files at "/tmp" instead of "/etc".
Here is the Policy snippet:
bundle agent install
{
vars:
"packages" slist => {
"Algorithm-Diff-1.1902",
"Apache-DB-0.13",
"Apache-DBI-1.06",
"Apache-Session-1.83",
"Apache-SessionX-2.01",
"AppConfig-1.65",
"Archive-Tar-1.32",
};
commands:
"/usr/bin/wget http://10.X.X.X/downloads/perl-modules/$(packages).tar.gz;
/usr/bin/gunzip $(packages).tar.gz;
tar -xf $(packages).tar;
cd $(packages);
/usr/bin/perl Makefile.PL;
/usr/bin/make;
/usr/bin/make install;"
contain => standard,
classes => satisfied(canonify("$(packages)-installed"));
}
body contain standard
{
useshell => "true";
exec_owner => "root";
}
Thanks in advance.
You can add the directory in which the commands should be executed to the contain body, like this:
body contain standard
{
useshell => "true";
exec_owner => "root";
chdir => "/tmp";
}
Please note there are already a few contain bodies in the standard library (lib/3.5/commands.cf), maybe one of those can be used so you don't have to write your own. Note that CFEngine already executes as root, so exec_owner => "root" is not strictly necessary.

Sourcing Puppet files from outside of modules

I'm installing a package from a module (Nginx in this specific case) and would like to include a configuration file from outside of the module, i.e. from a top level files directory parallel to the top level manifests directory. I don't see any way to source the file though without including it in a module or in my current Vagrant environment referring to the absolute local path.
Does Puppet allow for sourcing files from outside of modules as described in the documentation?
if I understand your question correctly, you can.
In your module a simple code like this
file { '/path/to/file':
ensure => present,
source => [
"puppet:///files/${fqdn}/path/to/file",
"puppet:///files/${hostgroup}/path/to/file",
"puppet:///files/${domain}/path/to/file",
"puppet:///files/global/path/to/file",
],
}
will do the job. The /path/to/file will be sourced using a file located in the "files" Puppet share.
(in the example above, it search in 4 different locations).
update maybe you're talking about a directory to store files which is not shared by Puppet fileserver (look at http://docs.puppetlabs.com/guides/file_serving.html), and in this case you can't i think, Vagrant or not, but you can add it to your Puppet fileserver to do it. I thinks it's the best (and maybe only) way to do it.
If you have a number of Vagrant VMs you can simply store files within your Vagrant project directory (containing your VagrantFile).
This directory is usually available to all VMs as /vagrant within the VM on creation.
If you want other directories on your computer to be available to your VMs just add the following to your VagrantFile
# see http://docs.vagrantup.com/v1/docs/config/vm/share_folder.html
config.vm.share_folder "v-packages", "/vagrant_packages", "../../dpkg"
Then to use the files within puppet you can simply treat them as local files to the VM
# bad example, bub basically use 'source => 'file:///vagrant/foo/bar'
file { '/opt/cassandra':
ensure => directory,
replace => true,
purge => true,
recurse => true,
source => 'file:///vagrant/conf/dist/apache-cassandra-1.2.0',
}
This is probably only wise to do if you only using local puppet manifests/modules.
Probably too late to help bennylope, but for others who happen across this question, as I did before figuring it out for myself ...
Include stuff like this in your Vagrantfile ...
GUEST_PROVISIONER_CONFDIR = "/example/destination/path"
HOST_PROVISIONER_CONFDIR = "/example/source/path"
config.vm.synced_folder HOST_PROVISIONER_CONFIDIR, GUEST_PROVISIONER_CONFDIR
puppet.options = "--fileserverconfig='#{GUEST_PROVISIONER_CONFDIR}/fileserver.conf'"
Then make sure /example/source/path contains the referenced fileserver.conf file. It should look something like ...
[foo]
path /example/destination/path
allow *
Now, assuming example-file.txt exists in /example/source/path, the following will work in your manifests:
source => "puppet:///foo/example-file.txt",
See:
Puppet configuration reference entry for fileserverconfig
Serving Files From Custom Mount Points

Resources