<%
cloud_config = node['dcos-grid']['cloud-config']
dcos_config = node['dcos-grid']['bootstrap']['config']
-%>
#cloud-config

hostname: <%= cloud_config['hostname'] %>

# include one or more SSH public keys for the core user
ssh_authorized_keys:
<%
cloud_config['ssh_authorized_keys'].each {|key|
-%>
  - "<%= key %>"
<%
}
-%>

<%
case cloud_config['target_platform']
when 'coreos' then
-%> 
coreos:
  units:
    - name: systemd-networkd.service
      command: stop
    - name: 10-static.network
      runtime: true
      content: |
        [Match]
        Name=enp0s8

        [Network]
        Address=<ip_address>/24
        #Gateway=192.168.56.1
    - name: 20-dhcp.network
      runtime: true
      content: |
        [Match]
        Name=en*

        [Network]
        DHCP=yes
    - name: down-interfaces.service
      command: start
      content: |
        [Service]
        Type=oneshot
        ExecStart=/usr/bin/ip link set enp0s8 down
        ExecStart=/usr/bin/ip addr flush dev enp0s8
    - name: systemd-networkd.service
      command: restart
<%
end
-%>

write_files:
  - path: "/etc/resolv.conf"
    permissions: "0644"
    owner: "root"
    content: |
<%
dcos_config['resolvers'].each {|resolv|
-%>
      nameserver <%= resolv %>
<%
}
-%>
<%
indent_space = ' ' * 6
-%>
  - path: "<%= cloud_config['target_dir'] %>/genconf/config.yaml"
    permissions: "0644"
    owner: "<%= cloud_config['target_owner'] %>"
    content: |
<%= render('opt/dcos-grid/genconf/config.yaml').gsub!(/^/, indent_space) -%>
  - path: "<%= cloud_config['target_dir'] %>/genconf/ip-detect"
    permissions: "0755"
    owner: "<%= cloud_config['target_owner'] %>"
    content: |
<%= render('opt/dcos-grid/genconf/ip-detect').gsub!(/^/, indent_space) -%>
  - path: "<%= cloud_config['target_dir'] %>/bootstrap_setup.sh"
    permissions: "0755"
    owner: "<%= cloud_config['target_owner'] %>"
    content: |
<%= render('opt/dcos-grid/bootstrap_setup.sh').gsub!(/^/, indent_space) -%>
  - path: "<%= cloud_config['target_dir'] %>/node_setup.sh"
    permissions: "0755"
    owner: "<%= cloud_config['target_owner'] %>"
    content: |
<%= render('opt/dcos-grid/node_setup.sh').gsub!(/^/, indent_space) -%>
  - path: "<%= cloud_config['target_dir'] %>/uninstall.sh"
    permissions: "0755"
    owner: "<%= cloud_config['target_owner'] %>"
    content: |
<%= render('opt/dcos-grid/uninstall.sh').gsub!(/^/, indent_space) -%>
