summaryrefslogtreecommitdiff
path: root/files/cloud.sh
diff options
context:
space:
mode:
Diffstat (limited to 'files/cloud.sh')
-rwxr-xr-xfiles/cloud.sh85
1 files changed, 85 insertions, 0 deletions
diff --git a/files/cloud.sh b/files/cloud.sh
new file mode 100755
index 0000000..a188204
--- /dev/null
+++ b/files/cloud.sh
@@ -0,0 +1,85 @@
+#!/bin/bash
+
+keypair_user="${1}"
+pubkey_path="${2}"
+dns_servers="${3}"
+
+if [ "${keypair_user}" == "" ]; then
+ echo "No keypair user was supplied." >&2
+ exit 1
+elif [ "${pubkey_path}" == "" ]; then
+ echo "No pubkey path was supplied." >&2
+ exit 1
+elif [ "${dns_servers}" == "" ]; then
+ echo "No dns servers supplied." >&2
+ exit 1
+fi
+
+nameservers=$(for i in ${dns_servers}; do echo -n "'${i}',"; done)
+nameservers="${nameservers::-1}"
+
+cat > "data/etc/cloud/cloud.cfg" <<EOF
+#cloud-config
+# vim: syntax=yaml
+
+users:
+ - name: default
+ - name: ${keypair_user}
+ groups: sudo
+ shell: /bin/bash
+ sudo: ['ALL=(ALL) NOPASSWD:ALL']
+ ssh-authorized-keys:
+ - $(cat ${pubkey_path})
+
+manage-resolv-conf: True
+
+resolv_conf:
+ nameservers: [${nameservers}]
+
+write_files:
+ - content: |
+ 127.0.0.1 localhost
+ 127.0.2.1 openbook-database
+
+ # The following lines are desirable for IPv6 capable hosts
+ ::1 localhost ip6-localhost ip6-loopback
+ ff02::1 ip6-allnodes
+ ff02::2 ip6-allrouters
+ path: /etc/hosts
+
+ - path: /root/cloudcfg.sh
+ permissions: "0755"
+ content: |
+ #!/bin/bash
+
+ # Prepare the instance for ansible. This amounts to installing python2.
+
+ python=$(which python || which python3 || which python2 || false)
+
+ case "$(${python} -m platform)" in
+ *Ubuntu*)
+ export DEBIAN_FRONTEND=noninteractive
+ apt-get update
+ apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade
+ apt-get -y install python python2.7 ntp ntpdate
+ ;;
+ *centos*|*redhat*)
+ # RHEL systems still use python2 by default; nothing to do
+ ;;
+ *gentoo*)
+ if [ ! -d /usr/portage/sys-devel/gcc ]; then
+ emerge-webrsync
+ fi
+ emerge --oneshot --update dev-lang/python:2.7 app-portage/gentoolkit net-misc/ntp
+ rc-update add ntp-client default
+ rc-update add ntpd default
+ ;;
+ esac
+
+ exit 0
+
+runcmd:
+ - /root/cloudcfg.sh
+EOF
+
+exit 0