- name: create consul_template templates for watching instance config updates
  template:
    src: "updates/{{ item }}.tmpl"
    dest: "{{ updates_template_path }}/{{ item }}.tmpl"
    variable_start_string: "€#"
    variable_end_string: "#€"
    block_start_string: "€%"
    block_end_string: "%€"
  with_items:
    - nomad-tags
    - instance-clean
    - image-version

- name: copy systemd consul_template updates script
  template:
    src: updates/consul-template-{{ item }}.service
    dest: "{{ updates_template_path }}/consul-template-{{ item }}.service"
    variable_start_string: "€#"
    variable_end_string: "#€"
    block_start_string: "€%"
    block_end_string: "%€"
  with_items:
    - nomad-tags
    - instance-clean
    - image-version

- name: Create reload scripts
  template:
    src: updates/{{ item }}.sh
    dest: "{{ layerops_bin_path }}/update-{{ item }}.sh"
    mode: 0755
  with_items:
    - nomad-tags
    - instance-config

- name: Create layerops clean script
  template:
    src: updates/instance-clean.sh
    dest: "{{ local_bin_path }}/layerops-clean.sh"
    mode: 0755

- name: create systemd timer for instance config updates
  template:
    src: "updates/{{ item }}"
    dest: "/etc/systemd/system/{{ item }}"
  with_items:
    - ly-update-instance-config.service
    - ly-update-instance-config.timer
