---
- name: register control-scale opts
  shell: |
    grep -oP "control-scale\ \d+"  {{ overcloud_deploy_script }}
  register: control_scale
  ignore_errors: true

- name: remove control-scale opts from deploy command
  lineinfile:
    path: "{{ overcloud_deploy_script }}"
    regexp: "{{ control_scale.stdout }}"
    state: absent
  when: control_scale is succeeded

- name: register compute-scale opts
  shell: |
    grep -oP "compute-scale\ \d+"  {{ overcloud_deploy_script }}
  register: compute_scale
  ignore_errors: true

- name: remove compute-scale opts from deploy command
  lineinfile:
    path: "{{ overcloud_deploy_script }}"
    regexp: "{{ compute_scale.stdout }}"
    state: absent
  when: compute_scale is succeeded

- name: register ceph-storage-scale opts
  shell: |
    grep -oP "ceph-storage-scale\ \d+"  {{ overcloud_deploy_script }}
  register: ceph_scale
  ignore_errors: true

- name: remove ceph-storage-scale opts from deploy command
  lineinfile:
    path: "{{ overcloud_deploy_script }}"
    regexp: "{{ ceph_scale.stdout }}"
    state: absent
  when: ceph_scale is succeeded

- name: register control-flavor opts
  shell: |
    grep -oP "control-flavor\ .*\ "  {{ overcloud_deploy_script }}
  register: control_flavor
  ignore_errors: true

- name: remove control-flavor opts from deploy command
  lineinfile:
    path: "{{ overcloud_deploy_script }}"
    regexp: "{{ control_flavor.stdout }}"
    state: absent
  when: control_flavor is succeeded

- name: register compute-flavor opts
  shell: |
    grep -oP "compute-flavor\ .*\ "  {{ overcloud_deploy_script }}
  register: compute_flavor
  ignore_errors: true

- name: remove compute-flavor opts from deploy command
  lineinfile:
    path: "{{ overcloud_deploy_script }}"
    regexp: "{{ compute_flavor.stdout }}"
    state: absent
  when: compute_flavor is succeeded

- name: register ceph-flavor opts
  shell: |
    grep -oP "ceph-storage-flavor\ .*\ "  {{ overcloud_deploy_script }}
  register: ceph_flavor
  ignore_errors: true

- name: remove ceph-flavor opts from deploy command
  lineinfile:
    path: "{{ overcloud_deploy_script }}"
    regexp: "{{ ceph_flavor.stdout }}"
    state: absent
  when: ceph_flavor is succeeded

- name: register ntp-server opts
  shell: |
    grep -oP "ntp-server\ .*\ "  {{ overcloud_deploy_script }}
  register: ntp_server
  ignore_errors: true

- name: remove ntp-server opts from deploy command
  lineinfile:
    path: "{{ overcloud_deploy_script }}"
    regexp: "{{ ntp_server.stdout }}"
    state: absent
  when: ntp_server is succeeded

- name: convert cli options into parameters
  template:
    src: fast-forward-upgrade/cli_opts_params.yaml.j2
    dest: "{{ working_dir }}/cli_opts_params.yaml"
    force: false
  when:
    - >
      control_scale is succeeded or
      compute_scale is succeeded or
      ceph_scale is succeeded or
      control_flavor is succeeded or
      compute_flavor is succeeded or
      ceph_flavor is succeeded or
      ntp_server is succeeded

- name: check "{{ working_dir }}/cli_opts_params.yaml" exists
  stat:
    path: "{{ working_dir }}/cli_opts_params.yaml"
  register: cli_opts_param_file

- name: set cli_converted_options fact
  set_fact:
    cli_converted_options: true
  when: cli_opts_param_file.stat.exists|bool
