| 1 |
--- |
| 2 |
|
| 3 |
- module_defaults: |
| 4 |
group/aws: |
| 5 |
access_key: '{{ aws_access_key }}' |
| 6 |
secret_key: '{{ aws_secret_key }}' |
| 7 |
session_token: '{{ security_token | default(omit) }}' |
| 8 |
region: '{{ aws_region }}' |
| 9 |
|
| 10 |
block: |
| 11 |
|
| 12 |
# ==== Tests =================================================== |
| 13 |
|
| 14 |
- name: Create a new instance |
| 15 |
lightsail: |
| 16 |
name: "{{ instance_name }}" |
| 17 |
zone: "{{ zone }}" |
| 18 |
blueprint_id: amazon_linux_2 |
| 19 |
bundle_id: nano_2_0 |
| 20 |
public_ports: |
| 21 |
- from_port: 50 |
| 22 |
to_port: 50 |
| 23 |
protocol: "tcp" |
| 24 |
cidrs: ["0.0.0.0/0"] |
| 25 |
ipv6_cidrs: ["::/0"] |
| 26 |
wait: yes |
| 27 |
register: result |
| 28 |
|
| 29 |
- assert: |
| 30 |
that: |
| 31 |
- result.changed == True |
| 32 |
- "'instance' in result and result.instance.name == instance_name" |
| 33 |
- "result.instance.state.name == 'running'" |
| 34 |
- "result.instance.networking.ports[0].from_port == 50" |
| 35 |
- result.instance.networking.ports|length == 1 |
| 36 |
|
| 37 |
- name: Check if it does not delete public ports config when no value is provided |
| 38 |
lightsail: |
| 39 |
name: "{{ instance_name }}" |
| 40 |
zone: "{{ zone }}" |
| 41 |
blueprint_id: amazon_linux |
| 42 |
bundle_id: nano_2_0 |
| 43 |
register: result |
| 44 |
|
| 45 |
- assert: |
| 46 |
that: |
| 47 |
- result.changed == False |
| 48 |
|
| 49 |
- name: Make sure create is idempotent |
| 50 |
lightsail: |
| 51 |
name: "{{ instance_name }}" |
| 52 |
zone: "{{ zone }}" |
| 53 |
blueprint_id: amazon_linux_2 |
| 54 |
bundle_id: nano_2_0 |
| 55 |
public_ports: |
| 56 |
- from_port: 50 |
| 57 |
to_port: 50 |
| 58 |
protocol: "tcp" |
| 59 |
cidrs: ["0.0.0.0/0"] |
| 60 |
ipv6_cidrs: ["::/0"] |
| 61 |
register: result |
| 62 |
|
| 63 |
- assert: |
| 64 |
that: |
| 65 |
- result.changed == False |
| 66 |
|
| 67 |
- name: Start the running instance |
| 68 |
lightsail: |
| 69 |
name: "{{ instance_name }}" |
| 70 |
state: running |
| 71 |
register: result |
| 72 |
|
| 73 |
- assert: |
| 74 |
that: |
| 75 |
- result.changed == False |
| 76 |
|
| 77 |
- name: Stop the instance |
| 78 |
lightsail: |
| 79 |
name: "{{ instance_name }}" |
| 80 |
state: stopped |
| 81 |
wait: yes |
| 82 |
register: result |
| 83 |
|
| 84 |
- assert: |
| 85 |
that: |
| 86 |
- result.changed == True |
| 87 |
- "result.instance.state.name == 'stopped'" |
| 88 |
|
| 89 |
- name: Stop the stopped instance |
| 90 |
lightsail: |
| 91 |
name: "{{ instance_name }}" |
| 92 |
state: stopped |
| 93 |
register: result |
| 94 |
|
| 95 |
- assert: |
| 96 |
that: |
| 97 |
- result.changed == False |
| 98 |
|
| 99 |
- name: Start the instance |
| 100 |
lightsail: |
| 101 |
name: "{{ instance_name }}" |
| 102 |
state: running |
| 103 |
register: result |
| 104 |
|
| 105 |
- assert: |
| 106 |
that: |
| 107 |
- result.changed == True |
| 108 |
- "result.instance.state.name == 'running'" |
| 109 |
|
| 110 |
- name: Restart the instance |
| 111 |
lightsail: |
| 112 |
name: "{{ instance_name }}" |
| 113 |
state: restarted |
| 114 |
register: result |
| 115 |
|
| 116 |
- assert: |
| 117 |
that: |
| 118 |
- result.changed == True |
| 119 |
|
| 120 |
- name: Delete the instance |
| 121 |
lightsail: |
| 122 |
name: "{{ instance_name }}" |
| 123 |
state: absent |
| 124 |
register: result |
| 125 |
|
| 126 |
- assert: |
| 127 |
that: |
| 128 |
- result.changed == True |
| 129 |
|
| 130 |
- name: Make sure instance deletion is idempotent |
| 131 |
lightsail: |
| 132 |
name: "{{ instance_name }}" |
| 133 |
state: absent |
| 134 |
register: result |
| 135 |
|
| 136 |
- assert: |
| 137 |
that: |
| 138 |
- result.changed == False |
| 139 |
|
| 140 |
# ==== Cleanup ==================================================== |
| 141 |
|
| 142 |
always: |
| 143 |
|
| 144 |
- name: Cleanup - delete instance |
| 145 |
lightsail: |
| 146 |
name: "{{ instance_name }}" |
| 147 |
state: absent |
| 148 |
ignore_errors: yes |