---
- name: Create {{ ugstage.step }} base script
  copy:
      src: "{{ overcloud_deploy_script }}"
      dest: "{{ ugstage.script }}"
      mode: 0755
      remote_src: true

- name: Remove extra empty lines
  lineinfile:
      path: "{{ ugstage.script }}"
      state: absent
      regexp: '^$'

- name: Store last deploy command line
  command: "tail -1 {{ ugstage.script }}"
  register: deploy_lastline

- name: Append params to {{ ugstage.step }} script
  lineinfile:
      dest: "{{ ugstage.script }}"
      insertbefore: "{{ deploy_lastline.stdout }}"
      line: '-e {{ item }} \'
  with_items: "{{ ugstage.environment_file }}"
  when: item|length > 0

- name: Append options to {{ ugstage.step }} script
  lineinfile:
      dest: "{{ ugstage.script }}"
      insertbefore: "{{ deploy_lastline.stdout }}"
      line: '--{{ item }} \'
  with_items: "{{ ugstage.option|default('') }}"
  when: item|length > 0

- name: Change log file name of {{ ugstage.step }} script
  lineinfile:
      dest: "{{ ugstage.script }}"
      regexp: '^--log-file.*'
      state: absent

- name: Remove timeout from {{ ugstage.step }} script
  replace:
      dest: "{{ ugstage.script }}"
      regexp: 'timeout 100m '
      replace: ''
