-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate cloud config from template. #46
- Loading branch information
Showing
5 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,8 @@ Imports: | |
assertthat, | ||
jsonlite, | ||
plyr, | ||
magrittr | ||
magrittr, | ||
yaml | ||
Suggests: | ||
packrat, | ||
testthat, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#' Generate cloud config file. | ||
#' | ||
#' This takes a template stored in \code{inst/cloudconfig} and inserts | ||
#' ssh_keys into the first user. | ||
#' | ||
#' @param name Name of template | ||
#' @inheritParams droplet_create | ||
#' @export | ||
#' @keywords internal | ||
cloud_config <- function(name, ssh_keys = NULL) { | ||
path <- system.file("cloudconfig", paste0(name, ".yaml"), | ||
package = "analogsea") | ||
if (identical(path, "")) { | ||
stop("Could not find config template for ", name, call. = FALSE) | ||
} | ||
|
||
config <- yaml::yaml.load_file(path) | ||
|
||
# Insert keys | ||
ssh_keys <- lapply(standardise_keys(ssh_keys), as.key) | ||
public <- pluck(ssh_keys, "public_key", "character") | ||
|
||
config$users[[1]]$`ssh-authorized-keys` <- public | ||
|
||
config | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#cloud-config | ||
users: | ||
- name: analogsea | ||
sudo: ['ALL=(ALL) NOPASSWD:ALL'] | ||
groups: sudo | ||
shell: /bin/bash | ||
write_files: | ||
- path: /etc/apt/apt.conf.d/20auto-upgrades | ||
content: | | ||
APT::Periodic::Update-Package-Lists "1"; | ||
APT::Periodic::Unattended-Upgrade "1"; | ||
- path: /etc/ssh/sshd_config | ||
content: | | ||
Port 22 | ||
Protocol 2 | ||
HostKey /etc/ssh/ssh_host_rsa_key | ||
HostKey /etc/ssh/ssh_host_dsa_key | ||
UsePrivilegeSeparation yes | ||
KeyRegenerationInterval 3600 | ||
ServerKeyBits 1024 | ||
SyslogFacility AUTH | ||
LogLevel INFO | ||
LoginGraceTime 120 | ||
PermitRootLogin no | ||
AllowUsers analogsea | ||
StrictModes yes | ||
PasswordAuthentication no | ||
ChallengeResponseAuthentication no | ||
RSAAuthentication yes | ||
PubkeyAuthentication yes | ||
IgnoreRhosts yes | ||
RhostsRSAAuthentication no | ||
HostbasedAuthentication no | ||
PermitEmptyPasswords no | ||
X11Forwarding yes | ||
X11DisplayOffset 10 | ||
PrintMotd no | ||
PrintLastLog yes | ||
TCPKeepAlive yes | ||
AcceptEnv LANG LC_* | ||
Subsystem sftp /usr/lib/openssh/sftp-server | ||
UsePAM yes | ||
runcmd: | ||
- apt-get update | ||
- apt-get install -y unattended-upgrades |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
% Generated by roxygen2 (4.0.2): do not edit by hand | ||
\name{cloud_config} | ||
\alias{cloud_config} | ||
\title{Generate cloud config file.} | ||
\usage{ | ||
cloud_config(name, ssh_keys = NULL) | ||
} | ||
\arguments{ | ||
\item{name}{Name of template} | ||
|
||
\item{ssh_keys}{(character) A character vector of key names, an integer | ||
vector of key ids, or NULL, to use all keys in your account. Accounts | ||
with the corresponding private key will be able to log in to the droplet. | ||
See \code{\link{keys}()} for a list of the keys that you've added. | ||
Default: NULL.} | ||
} | ||
\description{ | ||
This takes a template stored in \code{inst/cloudconfig} and inserts | ||
ssh_keys into the first user. | ||
} | ||
\keyword{internal} | ||