0
votes

I used PuPHPet to create a Puppet config for a PHP project (https://puphpet.com/#create). I've read that it uses Hiera, but I'm really not too familiar with the Puppet/Hiera syntax.

I want to create a symlink from a synced folder to my web root. I found out how to do it with Puppet, but I don't know how that fits in with my config files:

file { '/tmp/link-to-motd':
   ensure => 'link',
   target => '/etc/motd',
}

http://puppetcookbook.com/posts/creating-a-symlink.html

Is there some trick to do this in Hiera? It seems like Hiera uses a YAML file to configure everything. Sorry if I'm completely missing something obvious here.

For example I have this in my config.yml

vagrantfile-local:
    vm:
    ...
        synced_folder:
            0H4IdhbRXpVN:
                source: .
                target: /var/project
                sync_type: default
                rsync:
                    args:
                        - '--verbose'
                        - '--archive'
                        - '-z'
                    exclude:
                        - .vagrant/
                    auto: 'false'
...
apache:
    install: '1'
    settings:
        user: www-data
        group: www-data
        default_vhost: true
        manage_user: false
        manage_group: false
        sendfile: 0
    modules:
        - rewrite
    vhosts:
        RXTueD2ha3Pa:
            servername: mysite.dev
            docroot: /var/www/mysite
            port: '443'
            override:
                - All
            options:
                - Indexes
                - FollowSymLinks
                - MultiViews
            engine: php
            custom_fragment: ''
            ssl: '1'
            ssl_cert: ''
            ssl_key: ''
            ssl_chain: ''
            ssl_certs_dir: ''

And I want /var/www/mysite to be a symlink to /var/project/web.

I guess I could always create an exec-once shell script to do this, but hoping for a way to put this in the config.

2
If I understand PuPHPet correctly, this YAML is a configuration basis to create Vagrant configuration and a Puppet manifest. Hiera comes into play later, when the generated Puppet manifest is used. - Felix Frank

2 Answers

3
votes

I realize that this is an old thread, but here's a better way of adding support for configurable symlinks in PuPHPet.

Append the code under config.yaml to the bottom of your config.yaml file and then do the same for puphpet/puppet/site.pp

Then you can add/modify the nodes under links: in config.yaml in the format 'source': 'target'. I've included an example that would place a symlink in Vagrant's home directory called public_html that points to /var/www/html/.

config.yaml

symlinks:
    install: '1'
    links:
        '/home/vagrant/public_html': '/var/www/html/'

puphpet/puppet/site.pp

if array_true($symlinks, 'install') {
  $symlinks['links'].each |$source, $target| {
    file { "$source":
      ensure => link,
      target => "$target",
    }
  }
}
1
votes

The easiest way for you to do this is to create a super simple bash script and throw it into the exec-once folder, which will run one time on the initial $ vagrant up.