ansible/test/integration/targets/lightsail/tasks/main.yml
Prasad Katti 37ce55fd79 lightsail - Use AnsibleAWSModule (#65275)
* lightsail - Use AnsibleAWSModule

- Use AnsibleAWSModule
- Refactor the logic for wait into a separate function (Fixes #63869)
- Handle exceptions in find_instance_info and add a fail_if_not_found parameter
- Add a new state `rebooted` as an alias for `restarted`. AWS calls the action Reboot.
- Add required_if clause for when state is present

* lightsail - Use the default keypair if one is not provided

* lightsail - add a required_if for when state=present

* Update short description for lightsail module
2019-12-02 13:12:44 -07:00

122 lines
2.7 KiB
YAML

---
- module_defaults:
group/aws:
aws_access_key: '{{ aws_access_key | default(omit) }}'
aws_secret_key: '{{ aws_secret_key | default(omit) }}'
security_token: '{{ security_token | default(omit) }}'
region: '{{ aws_region | default(omit) }}'
block:
# ==== Tests ===================================================
- name: Create a new instance
lightsail:
name: "{{ instance_name }}"
zone: "{{ zone }}"
blueprint_id: amazon_linux
bundle_id: nano_2_0
wait: yes
register: result
- assert:
that:
- result.changed == True
- "'instance' in result and result.instance.name == instance_name"
- "result.instance.state.name == 'running'"
- name: Make sure create is idempotent
lightsail:
name: "{{ instance_name }}"
zone: "{{ zone }}"
blueprint_id: amazon_linux
bundle_id: nano_2_0
register: result
- assert:
that:
- result.changed == False
- name: Start the running instance
lightsail:
name: "{{ instance_name }}"
state: running
register: result
- assert:
that:
- result.changed == False
- name: Stop the instance
lightsail:
name: "{{ instance_name }}"
state: stopped
wait: yes
register: result
- assert:
that:
- result.changed == True
- "result.instance.state.name == 'stopped'"
- name: Stop the stopped instance
lightsail:
name: "{{ instance_name }}"
state: stopped
register: result
- assert:
that:
- result.changed == False
- name: Start the instance
lightsail:
name: "{{ instance_name }}"
state: running
register: result
- assert:
that:
- result.changed == True
- "result.instance.state.name == 'running'"
- name: Restart the instance
lightsail:
name: "{{ instance_name }}"
state: restarted
register: result
- assert:
that:
- result.changed == True
- name: Delete the instance
lightsail:
name: "{{ instance_name }}"
state: absent
register: result
- assert:
that:
- result.changed == True
- name: Make sure instance deletion is idempotent
lightsail:
name: "{{ instance_name }}"
state: absent
register: result
- assert:
that:
- result.changed == False
# ==== Cleanup ====================================================
always:
- name: Cleanup - delete instance
lightsail:
name: "{{ instance_name }}"
state: absent
ignore_errors: yes