diff options
| author | Carlos Konstanski <ckonstanski@pippiandcarlos.com> | 2017-12-13 18:54:21 -0700 |
|---|---|---|
| committer | Carlos Konstanski <ckonstanski@pippiandcarlos.com> | 2017-12-13 18:54:21 -0700 |
| commit | 32086f62131e1b813e2f3d97bc2c78f66c6a3154 (patch) | |
| tree | 2005059011aea64121af64de5b3567fd0dcbca3b /files/cloud.sh | |
| parent | 21fa10807bb475bff42a997ac4add3cc7e6346f9 (diff) | |
adding files
Diffstat (limited to 'files/cloud.sh')
| -rwxr-xr-x | files/cloud.sh | 85 |
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 |
