Advertisement
Guest User

Untitled

a guest
May 29th, 2015
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. def authorize_key_for_root(config, *key_paths)
  2. [*key_paths, nil].each do |key_path|
  3. if key_path.nil?
  4. fail "Public key not found at following paths: #{key_paths.join(', ')}"
  5. end
  6.  
  7. full_key_path = File.expand_path(key_path)
  8.  
  9. if File.exists?(full_key_path)
  10. config.vm.provision 'file',
  11. run: 'once',
  12. source: full_key_path,
  13. destination: '/home/vagrant/root_pubkey'
  14.  
  15. config.vm.provision 'shell',
  16. privileged: true,
  17. run: 'once',
  18. inline:
  19. "echo \"Creating /root/.ssh/authorized_keys with #{key_path}\" && " +
  20. 'mkdir -p /root/.ssh/ && ' +
  21. 'rm -f /root/.ssh/authorized_keys && ' +
  22. 'mv /home/vagrant/root_pubkey /root/.ssh/authorized_keys && ' +
  23. 'chown root:root /root/.ssh/authorized_keys && ' +
  24. 'chmod 600 /root/.ssh/authorized_keys && ' +
  25. 'rm -f /home/vagrant/root_pubkey && ' +
  26. 'echo "Done!"'
  27. break
  28. end
  29. end
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement