# ============================================================
- name: Test rax_scaling_group with no args
  rax_scaling_group:
  ignore_errors: true
  register: rax_scaling_group

- name: Validate results of rax_scaling_group with no args
  assert:
    that:
      - rax_scaling_group is failed
      - "rax_scaling_group.msg == 'missing required arguments: image,min_entities,flavor,max_entities,name,server_name'"
# ============================================================



# ============================================================
- name: Test rax_scaling_group with image,min_entities,flavor,max_entities,name,server_name
  rax_scaling_group:
    name: "{{ resource_prefix }}-1"
    image: "{{ rackspace_image_id }}"
    min_entities: 1
    max_entities: 1
    flavor: "{{ rackspace_flavor }}"
    server_name: "{{ resource_prefix }}-1"
  ignore_errors: true
  register: rax_scaling_group

- name: Validate results of rax_scaling_group with image,min_entities,flavor,max_entities,name,server_name
  assert:
    that:
      - rax_scaling_group is failed
      - rax_scaling_group.msg == 'No credentials supplied!'
# ============================================================



# ============================================================
- name: Test rax_scaling_group with creds and required args
  rax_scaling_group:
    name: "{{ resource_prefix }}-1"
    image: "{{ rackspace_image_id }}"
    min_entities: 1
    max_entities: 1
    flavor: "{{ rackspace_flavor }}"
    server_name: "{{ resource_prefix }}-1"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
  ignore_errors: true
  register: rax_scaling_group

- name: Validate results of rax_scaling_group with creds and required args
  assert:
    that:
      - rax_scaling_group is failed
      - rax_scaling_group.msg.startswith('None is not a valid region')
# ============================================================



# ============================================================
- name: Test rax_scaling_group with creds, region and required args
  rax_scaling_group:
    name: "{{ resource_prefix }}-1"
    image: "{{ rackspace_image_id }}"
    min_entities: 1
    max_entities: 1
    flavor: "{{ rackspace_flavor }}"
    server_name: "{{ resource_prefix }}-1"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
  register: rax_scaling_group

- name: Validate results of rax_scaling_group with creds, region and required args
  assert:
    that:
      - rax_scaling_group is successful
      - rax_scaling_group.autoscale_group.name == "{{ resource_prefix }}-1"
      - rax_scaling_group.autoscale_group.min_entities == 1
      - rax_scaling_group.autoscale_group.max_entities == 1
      - rax_scaling_group.autoscale_group.launchConfiguration.args.server.flavorRef == "{{ rackspace_flavor }}"
      - rax_scaling_group.autoscale_group.launchConfiguration.args.server.imageRef == "{{ rackspace_image_id }}"
      - rax_scaling_group.autoscale_group.launchConfiguration.args.server.name == "{{ resource_prefix }}-1"
      - rax_scaling_group.autoscale_group.launchConfiguration.args.server.personality == []
      - rax_scaling_group.autoscale_group.launchConfiguration.args.loadBalancers == []
      - rax_scaling_group.autoscale_group.metadata == {}

- name: Test rax_scaling_group idempotency 1
  rax_scaling_group:
    name: "{{ resource_prefix }}-1"
    image: "{{ rackspace_image_id }}"
    min_entities: 1
    max_entities: 1
    flavor: "{{ rackspace_flavor }}"
    server_name: "{{ resource_prefix }}-1"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
  register: rax_scaling_group

- name: Validate idempotency 1
  assert:
    that:
      - rax_scaling_group is not changed

- name: Remove servers 1
  rax_scaling_group:
    name: "{{ resource_prefix }}-1"
    image: "{{ rackspace_image_id }}"
    min_entities: 0
    max_entities: 0
    flavor: "{{ rackspace_flavor }}"
    server_name: "{{ resource_prefix }}-1"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
  register: rax_scaling_group

- name: Validate remove servers 1
  assert:
    that:
      - rax_scaling_group is changed
      - rax_scaling_group.autoscale_group.min_entities == 0
      - rax_scaling_group.autoscale_group.max_entities == 0
      - rax_scaling_group.autoscale_group.state.desiredCapacity == 0

- name: Test delete integration 1
  rax_scaling_group:
    name: "{{ resource_prefix }}-1"
    image: "{{ rackspace_image_id }}"
    min_entities: 0
    max_entities: 0
    flavor: "{{ rackspace_flavor }}"
    server_name: "{{ resource_prefix }}-1"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
    state: absent
  register: rax_scaling_group

- name: Validate delete integration 1
  assert:
    that:
      - rax_scaling_group is changed
# ============================================================



# ============================================================
- name: Test rax_scaling_group server_name change 1
  rax_scaling_group:
    name: "{{ resource_prefix }}-2"
    image: "{{ rackspace_image_id }}"
    min_entities: 1
    max_entities: 1
    flavor: "{{ rackspace_flavor }}"
    server_name: "{{ resource_prefix }}-2"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
  register: rax_scaling_group

- name: Validate results of rax_scaling_group server_name change
  assert:
    that:
      - rax_scaling_group is successful
      - rax_scaling_group.autoscale_group.name == "{{ resource_prefix }}-2"
      - rax_scaling_group.autoscale_group.launchConfiguration.args.server.name == "{{ resource_prefix }}-2"

- name: Test rax_scaling_group server_name change 2
  rax_scaling_group:
    name: "{{ resource_prefix }}-2"
    image: "{{ rackspace_image_id }}"
    min_entities: 1
    max_entities: 1
    flavor: "{{ rackspace_flavor }}"
    server_name: "{{ resource_prefix }}-2a"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
  register: rax_scaling_group

- name: Validate results of rax_scaling_group server_name change 2
  assert:
    that:
      - rax_scaling_group is changed
      - rax_scaling_group.autoscale_group.name == "{{ resource_prefix }}-2"
      - rax_scaling_group.autoscale_group.launchConfiguration.args.server.name == "{{ resource_prefix }}-2a"

- name: Remove servers 2
  rax_scaling_group:
    name: "{{ resource_prefix }}-2"
    image: "{{ rackspace_image_id }}"
    min_entities: 0
    max_entities: 0
    flavor: "{{ rackspace_flavor }}"
    server_name: "{{ resource_prefix }}-2a"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
  register: rax_scaling_group

- name: Validate remove servers 2
  assert:
    that:
      - rax_scaling_group is changed
      - rax_scaling_group.autoscale_group.min_entities == 0
      - rax_scaling_group.autoscale_group.max_entities == 0
      - rax_scaling_group.autoscale_group.state.desiredCapacity == 0

- name: Test delete integration 2
  rax_scaling_group:
    name: "{{ resource_prefix }}-2"
    image: "{{ rackspace_image_id }}"
    min_entities: 0
    max_entities: 0
    flavor: "{{ rackspace_flavor }}"
    server_name: "{{ resource_prefix }}-2a"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
    state: absent
  register: rax_scaling_group

- name: Validate delete integration 2
  assert:
    that:
      - rax_scaling_group is changed
# ============================================================



# ============================================================
- name: Test rax_scaling_group with invalid load balancers
  rax_scaling_group:
    name: "{{ resource_prefix }}-3"
    image: "{{ rackspace_image_id }}"
    min_entities: 1
    max_entities: 1
    flavor: "{{ rackspace_flavor }}"
    server_name: "{{ resource_prefix }}-3"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
    loadbalancers:
      - id: "1234567890-0987654321"
        port: 80
  register: rax_scaling_group
  ignore_errors: true

- name: Validate results of rax_scaling_group with load balancers
  assert:
    that:
      - rax_scaling_group is failed
      - rax_scaling_group.msg.startswith('Load balancer ID is not an integer')
# ============================================================



# ============================================================
- name: Build a CLB to test rax_scaling_group with
  rax_clb:
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
    name: "{{ resource_prefix }}-clb"
    wait: true
    wait_timeout: "{{ rackspace_wait_timeout }}"
  register: rax_clb

- name: Validate rax_clb creation
  assert:
    that:
      - rax_clb is successful

- name: Set variable for CLB ID
  set_fact:
    rax_clb_id: "{{ rax_clb.balancer.id }}"
# ============================================================



# ============================================================
- name: Test rax_scaling_group with load balancers
  rax_scaling_group:
    name: "{{ resource_prefix }}-3"
    image: "{{ rackspace_image_id }}"
    min_entities: 1
    max_entities: 1
    flavor: "{{ rackspace_flavor }}"
    server_name: "{{ resource_prefix }}-3"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
    loadbalancers:
      - id: "{{ rax_clb_id }}"
        port: 80
  register: rax_scaling_group

- name: Validate results of rax_scaling_group with load balancers
  assert:
    that:
      - rax_scaling_group is successful
      - rax_scaling_group.autoscale_group.name == "{{ resource_prefix }}-3"
      - rax_scaling_group.autoscale_group.launchConfiguration.args.loadBalancers[0].loadBalancerId == rax_clb_id|int

- name: Remove servers 3
  rax_scaling_group:
    name: "{{ resource_prefix }}-3"
    image: "{{ rackspace_image_id }}"
    min_entities: 0
    max_entities: 0
    flavor: "{{ rackspace_flavor }}"
    server_name: "{{ resource_prefix }}-3"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
  register: rax_scaling_group

- name: Test delete integration 3
  rax_scaling_group:
    name: "{{ resource_prefix }}-3"
    image: "{{ rackspace_image_id }}"
    min_entities: 0
    max_entities: 0
    flavor: "{{ rackspace_flavor }}"
    server_name: "{{ resource_prefix }}-3"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
    state: absent
  register: rax_scaling_group
# ============================================================



# ============================================================
- name: Test rax_scaling_group files change 1
  rax_scaling_group:
    name: "{{ resource_prefix }}-4"
    image: "{{ rackspace_image_id }}"
    min_entities: 1
    max_entities: 1
    files:
      /tmp/test.txt: "{{ role_path }}/files/test.txt"
    flavor: "{{ rackspace_flavor }}"
    server_name: "{{ resource_prefix }}-4"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
  register: rax_scaling_group

- name: Validate results of rax_scaling_group files change 1
  assert:
    that:
      - rax_scaling_group is successful
      - rax_scaling_group.autoscale_group.name == "{{ resource_prefix }}-4"
      - rax_scaling_group.autoscale_group.launchConfiguration.args.server.personality|length == 1

- name: Test rax_scaling_group files change 2
  rax_scaling_group:
    name: "{{ resource_prefix }}-4"
    image: "{{ rackspace_image_id }}"
    min_entities: 1
    max_entities: 1
    flavor: "{{ rackspace_flavor }}"
    server_name: "{{ resource_prefix }}-4"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
  register: rax_scaling_group

- name: Validate results of rax_scaling_group files change 2
  assert:
    that:
      - rax_scaling_group is changed
      - rax_scaling_group.autoscale_group.name == "{{ resource_prefix }}-4"
      - rax_scaling_group.autoscale_group.launchConfiguration.args.server.personality is not defined

- name: Remove servers 4
  rax_scaling_group:
    name: "{{ resource_prefix }}-4"
    image: "{{ rackspace_image_id }}"
    min_entities: 0
    max_entities: 0
    flavor: "{{ rackspace_flavor }}"
    server_name: "{{ resource_prefix }}-4"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
  register: rax_scaling_group

- name: Test delete integration 4
  rax_scaling_group:
    name: "{{ resource_prefix }}-4"
    image: "{{ rackspace_image_id }}"
    min_entities: 0
    max_entities: 0
    flavor: "{{ rackspace_flavor }}"
    server_name: "{{ resource_prefix }}-4"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
    state: absent
  register: rax_scaling_group
# ============================================================



# ============================================================
- name: Build scaling group to test argument changes
  rax_scaling_group:
    name: "{{ resource_prefix }}-5"
    image: "{{ rackspace_image_id }}"
    min_entities: 1
    max_entities: 1
    flavor: "{{ rackspace_flavor }}"
    server_name: "{{ resource_prefix }}-5"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
  register: rax_scaling_group

- name: Validate default create
  assert:
    that:
      - rax_scaling_group is successful
      - rax_scaling_group is changed
      - rax_scaling_group.autoscale_group.name == "{{ resource_prefix }}-5"
      - rax_scaling_group.autoscale_group.min_entities == 1
      - rax_scaling_group.autoscale_group.max_entities == 1
      - rax_scaling_group.autoscale_group.launchConfiguration.args.server.flavorRef == "{{ rackspace_flavor }}"
      - rax_scaling_group.autoscale_group.launchConfiguration.args.server.imageRef == "{{ rackspace_image_id }}"
      - rax_scaling_group.autoscale_group.launchConfiguration.args.server.name == "{{ resource_prefix }}-5"
      - rax_scaling_group.autoscale_group.launchConfiguration.args.server.personality == []
      - rax_scaling_group.autoscale_group.launchConfiguration.args.loadBalancers == []
      - rax_scaling_group.autoscale_group.metadata == {}
# ============================================================



# ============================================================
- name: Change cooldown
  rax_scaling_group:
    name: "{{ resource_prefix }}-5"
    image: "{{ rackspace_image_id }}"
    min_entities: 1
    max_entities: 1
    flavor: "{{ rackspace_flavor }}"
    server_name: "{{ resource_prefix }}-5"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
    cooldown: 500
  register: rax_scaling_group

- name: Validate cooldown change
  assert:
    that:
      - rax_scaling_group is successful
      - rax_scaling_group is changed
      - rax_scaling_group.autoscale_group.cooldown == 500
# ============================================================



# ============================================================
- name: Change max_entities
  rax_scaling_group:
    name: "{{ resource_prefix }}-5"
    image: "{{ rackspace_image_id }}"
    min_entities: 1
    max_entities: 2
    flavor: "{{ rackspace_flavor }}"
    server_name: "{{ resource_prefix }}-5"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
    cooldown: 500
  register: rax_scaling_group

- name: Validate max_entities change
  assert:
    that:
      - rax_scaling_group is successful
      - rax_scaling_group is changed
      - rax_scaling_group.autoscale_group.max_entities == 2
# ============================================================



# ============================================================
- name: Change min_entities
  rax_scaling_group:
    name: "{{ resource_prefix }}-5"
    image: "{{ rackspace_image_id }}"
    min_entities: 2
    max_entities: 2
    flavor: "{{ rackspace_flavor }}"
    server_name: "{{ resource_prefix }}-5"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
    cooldown: 500
  register: rax_scaling_group

- name: Validate min_entities change
  assert:
    that:
      - rax_scaling_group is successful
      - rax_scaling_group is changed
      - rax_scaling_group.autoscale_group.min_entities == 2
# ============================================================



# ============================================================
- name: Change server_name
  rax_scaling_group:
    name: "{{ resource_prefix }}-5"
    image: "{{ rackspace_image_id }}"
    min_entities: 2
    max_entities: 2
    flavor: "{{ rackspace_flavor }}"
    server_name: "{{ resource_prefix }}-5-1"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
    cooldown: 500
  register: rax_scaling_group

- name: Validate server_name change
  assert:
    that:
      - rax_scaling_group is successful
      - rax_scaling_group is changed
      - rax_scaling_group.autoscale_group.launchConfiguration.args.server.name == "{{ resource_prefix }}-5-1"
# ============================================================



# ============================================================
- name: Change image
  rax_scaling_group:
    name: "{{ resource_prefix }}-5"
    image: "{{ rackspace_alt_image_id }}"
    min_entities: 2
    max_entities: 2
    flavor: "{{ rackspace_flavor }}"
    server_name: "{{ resource_prefix }}-5-1"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
    cooldown: 500
  register: rax_scaling_group

- name: Validate image change
  assert:
    that:
      - rax_scaling_group is successful
      - rax_scaling_group is changed
      - rax_scaling_group.autoscale_group.launchConfiguration.args.server.imageRef == "{{ rackspace_alt_image_id }}"
# ============================================================



# ============================================================
- name: Change flavor
  rax_scaling_group:
    name: "{{ resource_prefix }}-5"
    image: "{{ rackspace_alt_image_id }}"
    min_entities: 2
    max_entities: 2
    flavor: "{{ rackspace_alt_flavor }}"
    server_name: "{{ resource_prefix }}-5-1"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
    cooldown: 500
  register: rax_scaling_group

- name: Validate flavor change
  assert:
    that:
      - rax_scaling_group is successful
      - rax_scaling_group is changed
      - rax_scaling_group.autoscale_group.launchConfiguration.args.server.flavorRef == "{{ rackspace_alt_flavor }}"
# ============================================================



# ============================================================
- name: Change disk_config
  rax_scaling_group:
    name: "{{ resource_prefix }}-5"
    image: "{{ rackspace_alt_image_id }}"
    min_entities: 2
    max_entities: 2
    flavor: "{{ rackspace_alt_flavor }}"
    server_name: "{{ resource_prefix }}-5-1"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
    cooldown: 500
    disk_config: auto
  register: rax_scaling_group

- name: Validate flavor change
  assert:
    that:
      - rax_scaling_group is successful
      - rax_scaling_group is not changed
      - "rax_scaling_group.autoscale_group.launchConfiguration.args.server['OS-DCF:diskConfig'] == 'AUTO'"

- name: Change disk_config 2
  rax_scaling_group:
    name: "{{ resource_prefix }}-5"
    image: "{{ rackspace_alt_image_id }}"
    min_entities: 2
    max_entities: 2
    flavor: "{{ rackspace_alt_flavor }}"
    server_name: "{{ resource_prefix }}-5-1"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
    cooldown: 500
    disk_config: manual
  register: rax_scaling_group

- name: Validate flavor change 2
  assert:
    that:
      - rax_scaling_group is successful
      - rax_scaling_group is changed
      - "rax_scaling_group.autoscale_group.launchConfiguration.args.server['OS-DCF:diskConfig'] == 'MANUAL'"
# ============================================================



# ============================================================
- name: Change networks
  rax_scaling_group:
    name: "{{ resource_prefix }}-5"
    image: "{{ rackspace_alt_image_id }}"
    min_entities: 2
    max_entities: 2
    flavor: "{{ rackspace_alt_flavor }}"
    server_name: "{{ resource_prefix }}-5-1"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
    cooldown: 500
    disk_config: manual
    networks:
      - public
  register: rax_scaling_group

- name: Validate networks change
  assert:
    that:
      - rax_scaling_group is successful
      - rax_scaling_group is changed
      - rax_scaling_group.autoscale_group.launchConfiguration.args.server.networks.0.uuid == "00000000-0000-0000-0000-000000000000"
# ============================================================



# ============================================================
- name: Change load balancers
  rax_scaling_group:
    name: "{{ resource_prefix }}-5"
    image: "{{ rackspace_alt_image_id }}"
    min_entities: 2
    max_entities: 2
    flavor: "{{ rackspace_alt_flavor }}"
    server_name: "{{ resource_prefix }}-5-1"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
    cooldown: 500
    disk_config: manual
    networks:
      - public
      - private
    loadbalancers:
      - id: "{{ rax_clb_id }}"
        port: 80
  register: rax_scaling_group

- name: Validate networks change
  assert:
    that:
      - rax_scaling_group is successful
      - rax_scaling_group is changed
      - rax_scaling_group.autoscale_group.launchConfiguration.args.loadBalancers.0.loadBalancerId == rax_clb_id|int
# ============================================================



# ============================================================
- name: Create keypair to test with
  rax_keypair:
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
    name: "{{ resource_prefix }}-keypair"
    public_key: "{{ rackspace_keypair_pub }}"
  register: rax_keypair

- name: Validate rax_keypair creation
  assert:
    that:
      - rax_keypair is successful
      - rax_keypair is changed
      - rax_keypair.keypair.name == "{{ resource_prefix }}-keypair"
      - rax_keypair.keypair.public_key == "{{ rackspace_keypair_pub }}"
# ============================================================



# ============================================================
- name: Change key_name
  rax_scaling_group:
    name: "{{ resource_prefix }}-5"
    image: "{{ rackspace_alt_image_id }}"
    min_entities: 2
    max_entities: 2
    flavor: "{{ rackspace_alt_flavor }}"
    server_name: "{{ resource_prefix }}-5-1"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
    cooldown: 500
    disk_config: manual
    networks:
      - public
      - private
    loadbalancers:
      - id: "{{ rax_clb_id }}"
        port: 80
    key_name: "{{ resource_prefix }}-keypair"
  register: rax_scaling_group

- name: Validate key_name change
  assert:
    that:
      - rax_scaling_group is successful
      - rax_scaling_group is changed
      - rax_scaling_group.autoscale_group.launchConfiguration.args.server.key_name == "{{ resource_prefix }}-keypair"
# ============================================================



# ============================================================
- name: Change config_drive
  rax_scaling_group:
    name: "{{ resource_prefix }}-5"
    image: "{{ rackspace_alt_image_id }}"
    min_entities: 2
    max_entities: 2
    flavor: "{{ rackspace_alt_flavor }}"
    server_name: "{{ resource_prefix }}-5-1"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
    cooldown: 500
    disk_config: manual
    networks:
      - public
      - private
    loadbalancers:
      - id: "{{ rax_clb_id }}"
        port: 80
    key_name: "{{ resource_prefix }}-keypair"
    config_drive: true
  register: rax_scaling_group

- name: Validate config_drive change
  assert:
    that:
      - rax_scaling_group is successful
      - rax_scaling_group is changed
      - rax_scaling_group.autoscale_group.launchConfiguration.args.server.config_drive
# ============================================================



# ============================================================
- name: Change config_drive
  rax_scaling_group:
    name: "{{ resource_prefix }}-5"
    image: "{{ rackspace_alt_image_id }}"
    min_entities: 2
    max_entities: 2
    flavor: "{{ rackspace_alt_flavor }}"
    server_name: "{{ resource_prefix }}-5-1"
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
    cooldown: 500
    disk_config: manual
    networks:
      - public
      - private
    loadbalancers:
      - id: "{{ rax_clb_id }}"
        port: 80
    key_name: "{{ resource_prefix }}-keypair"
    config_drive: true
    user_data: "foo"
  register: rax_scaling_group

- name: Validate config_drive change
  assert:
    that:
      - rax_scaling_group is successful
      - rax_scaling_group is changed
      - rax_scaling_group.autoscale_group.launchConfiguration.args.server.user_data == '{{ "foo"|b64encode }}'
# ============================================================



# ============================================================
- name: Delete keypair
  rax_keypair:
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
    name: "{{ resource_prefix }}-keypair"
    public_key: "{{ rackspace_keypair_pub }}"
    state: absent
  register: rax_keypair

- name: Validate rax_keypair creation
  assert:
    that:
      - rax_keypair is successful
      - rax_keypair is changed
# ============================================================



# ============================================================
- name: Delete CLB
  rax_clb:
    username: "{{ rackspace_username }}"
    api_key: "{{ rackspace_api_key }}"
    region: "{{ rackspace_region }}"
    name: "{{ rax_clb.balancer.name }}"
    state: absent
    wait: true
    wait_timeout: "{{ rackspace_wait_timeout }}"
  register: rax_clb

- name: "Validate delete integration 3"
  assert:
    that:
      - rax_clb is changed
      - rax_clb.balancer.id == rax_clb_id|int
# ============================================================
