---
- name: Deprecation message for network isolation types
  debug:
    msg: >-
      Network isolation type 'bond_with_vlans' is deprecated in R release,
      please use 'bond-with-vlans'.
  when: network_isolation_type is defined and network_isolation_type == "bond_with_vlans"

- name: Add PublicVirtualFixedIPs Argument to network environment file
  set_fact:
    network_environment_args: >-
      {{ network_environment_args | combine(public_virtual_fixed_ips) }}
  when: ssl_overcloud|bool and undercloud_type != "baremetal"
  tags:
    - overcloud-scripts

- name: Create network environment file for network isolation
  template:
    src: "{{ network_environment_file }}"
    dest: "{{ working_dir }}/network-environment.yaml"
    mode: 0644
  when: network_isolation|bool and undercloud_type != "baremetal" or deployed_server|bool
  tags:
    - overcloud-scripts

- when: undercloud_type == "baremetal"
  block:

    - name: "Push baremetal instackenv.json"
      copy:
        src: "{{ baremetal_instackenv }}"
        dest: "{{ working_dir }}/instackenv.json"

    - name: "Push network-environment.yaml"
      copy:
        src: "{{ baremetal_network_environment }}"
        dest: "{{ working_dir }}/network-environment.yaml"

# NOTE: 'bond_with_vlans' is deprecated
- when: network_isolation_type is defined and network_isolation_type in ["bond-with-vlans", "bond_with_vlans"]
  block:

    - name: Create bond-with-vlans nic-configs script
      template:
        src: "{{ bond_with_vlans_copy_nic_configs_script }}"
        dest: "{{ working_dir }}/bond-with-vlans-copy-nic-configs.sh"
        mode: 0755

    - name: Modify the nic-configs file to use Linux bonds
      shell: >
        set -o pipefail &&
        {{ working_dir }}/bond-with-vlans-copy-nic-configs.sh 2>&1 {{ timestamper_cmd }} >
        {{ bond_with_vlans_nic_configs_log }}

- name: "Push baremetal nic-configs directory (if defined)"
  copy:
    src: "{{ baremetal_nic_configs }}"
    dest: "{{ working_dir }}"
  when: baremetal_nic_configs is defined

- name: Prepare custom t-h-t for overcloud deployment
  include_role:
    name: tht-prep-config
  vars:
    custom_tht_log: "{{ overcloud_custom_tht_log }}"
    custom_tht_script: "{{ overcloud_custom_tht_script }}"
    tht_templates_repo: "{{ overcloud_templates_repo|default('') }}"
    tht_templates_refspec: "{{ overcloud_templates_refspec|default('') }}"
    tht_templates_branch: "{{ overcloud_templates_branch|default('') }}"
    tht_templates_path: "{{ overcloud_templates_path }}"
    download_templates_rpm: "{{ download_overcloud_templates_rpm|default('') }}"
    prep_post_hook_script: "{{ overcloud_prep_post_hook_script|default('') }}"
  when:
    - overcloud_templates_refspec is defined or overcloud_templates_branch is defined
    - overcloud_templates_repo is defined

- name: Copy extra THT config files on the undercloud
  copy:
    src: "{{ item }}"
    dest: "{{ working_dir }}"
  with_items: "{{ extra_tht_configs|default([]) }}"

- name: Add extra THT config file to the deploy command
  set_fact:
    extra_tht_config_args: >-
      {{ extra_tht_config_args|default('') }}
      -e {{ working_dir }}/{{ item | basename }}
  with_items: "{{ extra_tht_configs|default([]) }}"
