<commit_before>---

#Copyright 2016 ShapeBlue
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.

####################################################################
# Set delete / expunge for VMs. Can not be accomplished with
# the CloudStack Ansible modules hence using cs commands.
#

- name: allow env to be removed purely from env_name
  set_fact: force=no
  when: force is undefined

####################################################################
# Remove servers
#
- name: Set remove action
  set_fact: vm_state="expunged"
  when: expunge is defined

- name: remove  hosts
  local_action:
    module: cs_instance
    name: "{{ item }}"
    project: "{{ build_project }}"
    state: "{{ vm_state | default( 'absent' ) }}"
    force: true
  with_items:
    - "{{ groups['vc_hosts'] }}"
    - "{{ groups['hypervisor_hosts'] }}"
    - "{{ groups['mysql_hosts'] }}"
    - "{{ groups['cloudstack_manager_hosts'] }}"
  register: remove_retval
  when: force = no

- name: Update inventory file - remove server IP addresses
  replace:
    dest="hosts_{{ env_name_clean }}"
    regexp='{{ item.default_ip }}'
    replace='{{ item.name }}-ip'
    backup=no
  with_items: "{{remove_retval.results}}"
  when: force = no

- name: Remove HV IP list from group vars
  lineinfile:
    dest="group_vars/{{ env_name_clean }}"
    regexp="^env_hviplist.*$"
    state=absent
  when: force = no

####################################################################
# Remove environment files
#
- name: Delete inventory files
  file:
    path="{{ item }}"
    state="absent"
  with_items:
    - "hosts_{{ env_name_clean }}"
    - "group_vars/{{ env_name_clean }}"
  when: removeconfig is defined

####################################################################
# Remove project
#
- name: Delete project
  local_action:
    module: cs_project
    name: "{{ build_project }}"
    state: absent
  when: removeproject is defined or when force

####################################################################
# Remove Environment IP range
#
- name: copy the environment delete script first
  copy: src=templates/enviroment_remove.sh.j2 dest=/tmp/{{ env_name_clean }}_enviroment_remove.sh mode=0744

- name: Environment remove script
  shell: "/tmp/{{ env_name_clean }}_enviroment_remove.sh -e {{ env_name_clean }} -n {{ hostvars[groups['primary_storage_hosts'][0]]['ansible_ssh_host'] }} -m {{ hostvars[groups['secondary_storage_hosts'][0]]['ansible_ssh_host'] }} -r '{{ env_pripath }}' -s '{{ env_secpath }}'"
  when:<commit_msg>start adding forced arg support<commit_after>---

#Copyright 2016 ShapeBlue
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.

####################################################################
# Set delete / expunge for VMs. Can not be accomplished with
# the CloudStack Ansible modules hence using cs commands.
#

- name: allow env to be removed purely from env_name
  set_fact: forced=no
  when: forced is undefined

####################################################################
# Remove servers
#
- name: Set remove action
  set_fact: vm_state="expunged"
  when: expunge is defined or force

- name: remove  hosts
  local_action:
    module: cs_instance
    name: "{{ item }}"
    project: "{{ build_project }}"
    state: "{{ vm_state | default( 'absent' ) }}"
    force: true
  with_items:
    - "{{ groups['vc_hosts'] }}"
    - "{{ groups['hypervisor_hosts'] }}"
    - "{{ groups['mysql_hosts'] }}"
    - "{{ groups['cloudstack_manager_hosts'] }}"
  register: remove_retval
  when: forced

- name: Update inventory file - remove server IP addresses
  replace:
    dest="hosts_{{ env_name_clean }}"
    regexp='{{ item.default_ip }}'
    replace='{{ item.name }}-ip'
    backup=no
  with_items: "{{remove_retval.results}}"
  when: forced

- name: Remove HV IP list from group vars
  lineinfile:
    dest="group_vars/{{ env_name_clean }}"
    regexp="^env_hviplist.*$"
    state=absent
  when: forced == 'no'

####################################################################
# Remove environment files
#
- name: Delete inventory files
  file:
    path="{{ item }}"
    state="absent"
  with_items:
    - "hosts_{{ env_name_clean }}"
    - "group_vars/{{ env_name_clean }}"
  when: removeconfig is defined

####################################################################
# Remove project
#
- name: Delete project
  local_action:
    module: cs_project
    name: "{{ build_project }}"
    state: absent
  when: removeproject is defined or forced

####################################################################
# Remove Environment IP range
#

- name: Environment remove script
  shell: "/tmp/{{ env_name_clean }}_enviroment_remove.sh -e {{ env_name_clean }} -n {{ hostvars[groups['primary_storage_hosts'][0]]['ansible_ssh_host'] }} -m {{ hostvars[groups['secondary_storage_hosts'][0]]['ansible_ssh_host'] }} -r '{{ env_pripath }}' -s '{{ env_secpath }}'"

- name: copy the environment delete script first
  copy: src=templates/enviroment_remove.sh.j2 dest=/tmp/{{ env_name_clean }}_enviroment_remove.sh mode=0744
{'fraction_non_alphanumeric': 0.2229214971844982, 'fraction_numerical': 0.004968532626697582, 'mean_word_length': 4.560773480662983, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '490371', 'n_tokens_mistral': 1791, 'n_tokens_neox': 1720, 'n_words': 533}