issue creating symlink

400 views
Skip to first unread message

Nathan Crews

unread,
May 6, 2016, 9:49:15 AM5/6/16
to Puppet Users
Currently i'm using Vagrant and bash scripts to provision a local dev environment. I'm working on moving this to Puppet and running into an issue with creating a symlink to my apache document root that I cant seem to sort out.

These are the commands in the bash script i'm trying replace/replicate

    sudo rm -rf /var/www/html
    sudo ln
-s /vagrant/public /var/www/html



in my puppet manifest I have the following 

file{ 'docroot':
 path
=> '/var/www/html',
 
ensure => absent,
 purge
=> true,
 recurse
=> true,
 force
=> true,
}


file
{ '/vagrant/public':
 
ensure => link,
 force
=> true,
 target
=> '/var/www/html',
 
require => File['docroot'],
}





The output when the manifist runs is 
==> default: Debug: /Stage[main]/Main/File[docroot]: Removing existing directory for replacement with absent
==> default: Notice: /Stage[main]/Main/File[docroot]/ensure: removed
==> default: Debug: /Stage[main]/Main/File[docroot]: The container docroot will propagate my refresh event
==> default: Debug: /Stage[main]/Main/File[/var/www/html/index.html]: Nothing to manage: no ensure and the resource doesn't exist
==> default: Debug: docroot: The container Class[Main] will propagate my refresh event
==> default: Info: /Stage[main]/Main/File[/vagrant/public]: Recursively backing up to filebucket
==> default: Debug: /Stage[main]/Main/File[/vagrant/public]: Removing existing directory for replacement with link
==> default: Info: /Stage[main]/Main/File[/vagrant/public]: Recursively backing up to filebucket
==> default: Debug: /Stage[main]/Main/File[/vagrant/public]: Removing existing directory for replacement with /var/www/html
==> default: Error: Could not remove existing file
==> default: Error: /Stage[main]/Main/File[/vagrant/public]/ensure: change from directory to link failed: Could not remove existing file


Which seems to indicate it couldn't remove a file... /var/www/html did have an index.html file in it. With Purge => true and ensure => absent the index.html and the html folder its self are both gone as expected.  Yet I still get the could not remove existing file message while trying to create the link.  

I have tried setting ensure=> directory in File[ 'docroot' ] to leave an empty html directory and still get the same error.  So clearly i'm doing something wrong...  any help would be apprichated.  Thanks.

Peter Faller

unread,
May 9, 2016, 5:03:38 AM5/9/16
to Puppet Users
Maybe all you need is:

file { 'docroot':
  path      => '/var/www/html',
  ensure    => link,
  force     => true,
  target    => '/vagrant/public',
}

jcbollinger

unread,
May 9, 2016, 8:50:09 AM5/9/16
to Puppet Users


Right.  If you want /var/www/html to be a symlink then that's the resource you are trying to manage.  Puppet will ordinarily refuse to replace a directory with a symlink via a File resource, but you can overcome that by turning on the 'force' parameter.  If you do so, then Puppet will handle recursively deleting the existing directory before creating the link.  Be sure that you really mean it.


John

Nathan Crews

unread,
May 9, 2016, 10:14:17 AM5/9/16
to Puppet Users
Worked Perfectly, Thank you
Reply all
Reply to author
Forward
0 new messages