Skip to content

Commit

Permalink
Generate cloud config from template. #46
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Oct 21, 2014
1 parent 6548aad commit a93f499
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 1 deletion.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Imports:
assertthat,
jsonlite,
plyr,
magrittr
magrittr,
yaml
Suggests:
packrat,
testthat,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export(as.domain_record)
export(as.droplet)
export(as.image)
export(as.key)
export(cloud_config)
export(debian_add_swap)
export(debian_apt_get_install)
export(debian_apt_get_update)
Expand Down
26 changes: 26 additions & 0 deletions R/cloud_config.R
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
}
45 changes: 45 additions & 0 deletions inst/cloudconfig/ubuntu.yaml
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
22 changes: 22 additions & 0 deletions man/cloud_config.Rd
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}

0 comments on commit a93f499

Please sign in to comment.