0
votes

I am working a Puppet manifest that configures a router in the equipment that I support. The router runs pretty much plain vanilla Debian 8 or 9.

The problem is in the way the SSD on the router is partitioned.I am not able to change the partitioning, so have to work around the fact that the root file system is small. I have found a solution that I am trying to implement in Puppet but my first attempt doesn't feel right to me so I thought I would ask the community.

I have been and am reading the Puppet docs. Unfortunately I don't have my router hand to play with today so I am unable to test my current solution.

My issue is that by df -H the root file system is at 95% capacity and puppet is failing complaining about not enough space. Because of quirky decisions made a long time ago by others, the /opt/ file system is 5 times the size of / and is at 10% usage.

So my solution, tested manually, is to move /var/cache/apt/archives/ to /opt/apt-archives and then create a symlink using:

ln -s /opt/apt-archives /var/cache/apt/archives

That works and allows the puppet run to finish without errors.

My challenge is to implement this operation in a Puppet class

class bh::profiles::move_files {
  $source_dir = '/var/cache/apt/archives'
  $target_dir = '/opt/apt-cache'
  file { $targetDir :
    ensure => 'directory',
    source => "file://${source_dir}",
    recurse => true,
    before => File[$source_dir]
  }
  file { $source_dir :
    ensure => 'absent',
    purge => true,
    resurse => true,
    force => true,
    ensure => link,
    target => "file://${target_dir}"
  }
}

It just doesn't feel right to have ensure repeated in one file resource. And based on what I understand of creating links in puppet I would need the same name for the file resource that deletes the archives directory and the one that creates the link.

What am I missing?

1

1 Answers

1
votes

Use exec:

exec { 'Link /var/cache/apt/archives':
  command => 'mv /var/cache/apt/archives /opt/apt-archives
              ln -s /opt/apt-archives /var/cache/apt/archives',
  path    => '/bin',
  unless  => 'test -L /var/cache/apt/archives',
}

Note that Puppet was not really designed to solve automation problems like this one, although using Exec it is possible to do most things anyway.

Your solution sounds like a work-around and it is therefore totally ok to implement a work-around using Exec. I would say, just make sure you add some comments explaining why you had to do something like this.