#cloud-config

coreos:
  update:
    reboot-strategy: 'off'
  etcd2:
    advertise-client-urls: http://$private_ipv4:2379
    listen-client-urls: http://0.0.0.0:2379
  fleet:
    public-ip: $public_ipv4
    etcd_servers: http://$private_ipv4:2379
  units:
  - name: etcd2.service
    command: start
  - name: fleet.service
    command: start
  - name: download-reqs.service
    command: start
    content: |-
      [Unit]
      Description=Download and unpack the prereqs
      Wants=network-online.target
      After=network-online.target

      [Service]
      RemainAfterExit=yes
      Type=oneshot
      ExecStart=/home/core/add_path.sh
      ExecStart=/home/core/get_calicoctl.sh
write_files:
- path: /home/core/add_path.sh
  permissions: 777
  owner: root
  content: |
    #!/usr/bin/bash -e
    # Add /opt/bin to the _front_ of the PATH.
    # Can't directly write to .profile since it's a symlink to a RO filesystem
    mkdir -p /opt/bin
    rm /home/core/.bashrc
    echo 'PATH=/opt/bin:$PATH' > /home/core/.bashrc
    echo 'export ETCD_AUTHORITY="$private_ipv4:2379"' >> /home/core/.bashrc
    echo 'Defaults env_keep +="ETCD_AUTHORITY"' >>/etc/sudoers.d/etcd
- path: /home/core/get_calicoctl.sh
  permissions: 777
  owner: root
  content: |
    #!/usr/bin/bash -e
    wget -O /opt/bin/calicoctl https://github.com/projectcalico/calico-containers/releases/download/v0.23.1/calicoctl
    chmod +x /opt/bin/calicoctl
