Ask Your Question
1

Trouble with ssh_authorized_key puppet resource type

asked 2014-05-22 15:16:01 -0500

Gigi Mathews gravatar image

updated 2014-05-22 20:38:27 -0500

I have an account with different SSH Key pair for different environments (Dev/QA/Staging/Production). My code looks like

    case $appenv {
      'dev': {
        $pubkey = file('/var/lib/puppet/modules/publickey/files/dev/public_key')
      }
      'qa'': {
        $pubkey = file('/var/lib/puppet/modules/publickey/files/qa/public_key')
      }
      'staging': {
        $pubkey = file('/var/lib/puppet/modules/publickey/files/staging/public_key')
      }
      'production': {
        $pubkey = file('/var/lib/puppet/modules/publickey/files/production/public_key'')
      }
    }
  ssh_authorized_key { "myapp":
    ensure    => present,
    key       => "$pubkey",
    user      => "myapp",
    type      => "ssh-rsa",
  }

While puppet agent runs withfollowing error

err: Failed to apply catalog: Parameter key failed: Key must not contain whitespace: AAAAB3N...<trucated>....==

I have checked and rechecked public_key file, it only contains public key (AAA....==) and no space , comment etc

What am i missing ?

edit retag flag offensive close merge delete

Comments

Why are you doing `key ="$pubkey"` and not just `key =$pubkey`? the quotes are not required.

zoredache gravatar imagezoredache ( 2014-05-22 17:44:51 -0500 )edit

I have tried without quotes and still same issue. Any more ideas?

Gigi Mathews gravatar imageGigi Mathews ( 2014-05-23 12:39:44 -0500 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2014-05-22 20:52:28 -0500

updated 2014-05-23 12:59:42 -0500

By the code , looks like you have extra quotes.

Try use this code:

    case $appenv {
      'dev': {
        $pubkey = file('/var/lib/puppet/modules/publickey/files/dev/public_key')
      }
      'qa': {
        $pubkey = file('/var/lib/puppet/modules/publickey/files/qa/public_key')
      }
      'staging': {
        $pubkey = file('/var/lib/puppet/modules/publickey/files/staging/public_key')
      }
      'production': {
        $pubkey = file('/var/lib/puppet/modules/publickey/files/production/public_key')
      }
    }
  ssh_authorized_key { 'myapp':
    ensure    => present,
    key       => "$pubkey",
    user      => 'myapp',
    type      => 'ssh-rsa',
  }

Another check that you may want to do is check if really has a whitespace on your keys , changing the whitespaces by other think easy to look like for a capital string WHITESPACEHERE

perl -lape 's/\s+/WHITESPACEHERE/sg' yourkeyfile > output
edit flag offensive delete link more

Comments

That extra quote over here was my typo. I have used your perl command and created a new file, didnt saw "WHITESPACEHERE" in the output file. Any more ideas ?

Gigi Mathews gravatar imageGigi Mathews ( 2014-05-23 12:44:07 -0500 )edit

Did you try my code instead yours? I fixed the problem with quotes

Renan Vicente gravatar imageRenan Vicente ( 2014-05-23 12:58:19 -0500 )edit

Just to be sure, you fixed extra quote on 'qa'': ... correct ? If yes, it was a typo and i have corrected it.

Gigi Mathews gravatar imageGigi Mathews ( 2014-05-23 14:48:05 -0500 )edit

qa'': { and the last one have an extra quote too file('/var/lib/puppet/modules/publickey/files/production/public_key'')

Renan Vicente gravatar imageRenan Vicente ( 2014-05-23 18:12:47 -0500 )edit
0

answered 2014-05-23 12:46:17 -0500

Gigi Mathews gravatar image

Could file() be adding a white space ?

Is there any other way to reference a file here ? I have tried to use template and also puppet url but i keep seeing same error.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-05-22 15:16:01 -0500

Seen: 762 times

Last updated: May 23 '14