sshpuppetauthorized-keys

Puppet root authorized_key file


I've been messing around with puppet and i ran into an issue that has stumped me. maybe some one can shed some light. The idea is I have an rsync script that updates my authorized_keys file on my puppet master. Every 4 hours puppet agent grabs the new authorized_keys file.

here is a Master manifest

class policy1::sshkey {
  file { '/root/.ssh/':
    ensure  =>  directory,
    path    =>  '/root/.ssh/',
    owner   =>  'root',
    group   =>  'root',
    mode    =>   '0700',
  }

  file { '/root/.ssh/authorized_keys':
    require => File ["/root/.ssh/authorized_keys"],
    ensure  => file,
    owner   => 'root',
    group   => 'root',
    mode    => '0600',
    source  => "puppet:///modules/policy1/authorized_keys",
  }
}

my agent though gets this error

Error: Failed to apply catalog: Not a directory - /root/.ssh/authorized_keys


Solution

  • In your manifest, specifically the second resource definition you have it requiring itself. That said, you wanna do something like below:

    class policy1::sshkey {
      file { '/root/.ssh/':
        ensure =>  directory,
        path   =>  '/root/.ssh/',
        owner  =>  'root',
        group  =>  'root',
        mode   =>   '0700',
      }
    
      file { '/root/.ssh/authorized_keys':
        # Require the parent directory to be created beforehand.
        require => File['/root/.ssh/'],
        ensure  => file,
        owner   => 'root',
        group   => 'root',
        mode    => '0600',
        source  => "puppet:///modules/policy1/authorized_keys",
      }
    }
    

    ... or I personally prefer:

    class policy1::sshkey {
      file { '/root/.ssh':
        ensure => directory,
        path   => '/root/.ssh',
        owner  => 'root',
        group  => 'root',
        mode   => '0700',
      }->
      file { '/root/.ssh/authorized_keys':
        ensure => file,
        owner  => 'root',
        group  => 'root',
        mode   => '0600',
        source => 'puppet:///modules/policy1/authorized_keys',
      }
    }