---

- name: Confirm removal of the iSCSI gateway configuration
  hosts: localhost

  vars_prompt:
    - name: purge_config
      prompt: Which configuration elements should be purged? (all, lio or abort)
      default: 'abort'
      private: no

  tasks:
    - name: Exit playbook if user aborted the purge
      fail:
        msg: >
          "You have aborted the purge of the iSCSI gateway configuration"
      when: purge_config == 'abort'

    - set_fact:
        igw_purge_type: "{{ purge_config }}"

- name: Removing the gateway configuration
  hosts: iscsi-gws
  vars:
    - igw_purge_type: "{{hostvars['localhost']['igw_purge_type']}}"

  tasks:
    - name: igw_purge | purging the gateway configuration
      igw_purge: mode="gateway"

    - name: igw_purge | deleting configured rbd devices
      igw_purge: mode="disks"
      when: igw_purge_type == 'all'

    - name: restart rbd-target-gw daemons
      service: name=rbd-target-gw state=restarted


---

- name: Confirm removal of the iSCSI gateway configuration
  hosts: localhost

  vars_prompt:
    - name: purge_config
      prompt: Which configuration elements should be purged? (all, lio or abort)
      default: 'abort'
      private: no

  tasks:
    - name: Exit playbook if user aborted the purge
      fail:
        msg: >
          "You have aborted the purge of the iSCSI gateway configuration"
      when: purge_config == 'abort'

    - set_fact:
        igw_purge_type: "{{ purge_config }}"

- name: Removing the gateway configuration
  hosts: iscsi-gws
  become: yes
  vars:
    - igw_purge_type: "{{hostvars['localhost']['igw_purge_type']}}"

  tasks:
    - name: igw_purge | purging the gateway configuration
      igw_purge: mode="gateway"

    - name: igw_purge | deleting configured rbd devices
      igw_purge: mode="disks"
      when: igw_purge_type == 'all'

    - name: restart rbd-target-gw daemons
      service: name=rbd-target-gw state=restarted

Add privilege escalation to iscsi purge tasks
Add privilege escalation to iscsi purge tasks

Without the escalation, invocation from non-root
users with fail when accessing the rados config
object, or when attempting to log to /var/log

Closes: https://bugzilla.redhat.com/show_bug.cgi?id=1549004

Signed-off-by: Paul Cuzner <526e5967c1f778e480f386a4e768c83af6d400ed@redhat.com>
(cherry picked from commit 2890b57cfc2e1ef9897a791ce60f4a5545011907)
Signed-off-by: Sébastien Han <62d754cc350e84d3b1c32ae79f976f5348e74a40@redhat.com>
