simple role to create / delete container on scaleway cloud
This commit is contained in:
10
README.md
10
README.md
@@ -16,9 +16,7 @@ scw_api_default_project_id:
|
|||||||
|
|
||||||
scw_type: DEV1-S
|
scw_type: DEV1-S
|
||||||
container_action; delete or running
|
container_action; delete or running
|
||||||
container_number: number of container to create
|
container_name:
|
||||||
container_number_start: default 1 ( if container_number == container_number_start you'll create one container )
|
|
||||||
container_prefix: name of prefix to container #
|
|
||||||
container_domain: default formation.opendoor.fr
|
container_domain: default formation.opendoor.fr
|
||||||
scw_gen_hostlist: default true, wether we create a hostlist.yml file containing containers name and ip (to be fed to dns role to create records)
|
scw_gen_hostlist: default true, wether we create a hostlist.yml file containing containers name and ip (to be fed to dns role to create records)
|
||||||
container_image: id of image default alma9 26e4c50e-91d6-41a5-8898-9e40920e819d
|
container_image: id of image default alma9 26e4c50e-91d6-41a5-8898-9e40920e819d
|
||||||
@@ -36,14 +34,14 @@ Example Playbook
|
|||||||
- hosts: localhost
|
- hosts: localhost
|
||||||
vars:
|
vars:
|
||||||
container_action: running
|
container_action: running
|
||||||
container_number: 4
|
container_name: plope
|
||||||
container_prefix: plop
|
|
||||||
container_image: lezknfe2324
|
container_image: lezknfe2324
|
||||||
roles:
|
roles:
|
||||||
- tco.scw_container
|
- tco.scw_container
|
||||||
```
|
```
|
||||||
|
|
||||||
will create containers plop{1..4}.formation.opendoor.fr
|
will create containers plope.formation.opendoor.fr
|
||||||
|
|
||||||
License
|
License
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
|||||||
@@ -4,14 +4,13 @@
|
|||||||
community.general.scaleway_compute:
|
community.general.scaleway_compute:
|
||||||
commercial_type: "{{ item.host_type|default( scw_type )}}"
|
commercial_type: "{{ item.host_type|default( scw_type )}}"
|
||||||
region: par1
|
region: par1
|
||||||
name: "{{ container_prefix+'%d' | format(item) }}.{{container_domain }}"
|
name: "{{ container_name }}.{{container_domain }}"
|
||||||
state: "{{ (container_action == 'delete' ) | ternary( 'absent', 'running' ) }}"
|
state: "{{ (container_action == 'delete' ) | ternary( 'absent', 'running' ) }}"
|
||||||
api_token: "{{ scw_api_secret_key }}"
|
api_token: "{{ scw_api_secret_key }}"
|
||||||
image: "{{ container_image}}"
|
image: "{{ container_image}}"
|
||||||
project: "{{ scw_api_default_project_id }}"
|
project: "{{ scw_api_default_project_id }}"
|
||||||
public_ip: dynamic
|
public_ip: dynamic
|
||||||
wait: true
|
wait: true
|
||||||
loop: "{{ range( container_number_start, container_number +1, 1)|list }}"
|
|
||||||
register: "container_info"
|
register: "container_info"
|
||||||
|
|
||||||
- name: "generate host list"
|
- name: "generate host list"
|
||||||
@@ -25,8 +24,20 @@
|
|||||||
- ansible.builtin.lineinfile:
|
- ansible.builtin.lineinfile:
|
||||||
create: yes
|
create: yes
|
||||||
path: "hostlist.yml"
|
path: "hostlist.yml"
|
||||||
line: " - { record_name: {{ item.msg.name}}, record_type: A, record_value: {{ item.msg.public_ip.address }} }"
|
line: " - { record_name: {{ item.msg.name}}, record_type: A, record_value: {{ item.msg.public_ip.address }}, public_ip_id: {{ item.msg.public_ip.id }} }"
|
||||||
state: present
|
state: present
|
||||||
loop: "{{ container_info.results }}"
|
loop: "{{ container_info.results }}"
|
||||||
when: scw_gen_hostlist is true and container_action !='delete'
|
when: scw_gen_hostlist == 'true' and container_action !='delete'
|
||||||
|
|
||||||
|
- name: debug
|
||||||
|
debug:
|
||||||
|
msg: "ip id: {{ container_info.msg.public_ip.id }}"
|
||||||
|
|
||||||
|
- name: "delete ip "
|
||||||
|
community.general.scaleway_ip:
|
||||||
|
id: container_info.msg.public_ip.id
|
||||||
|
state: absent
|
||||||
|
api_token: "{{ scw_api_secret_key }}"
|
||||||
|
region: par1
|
||||||
|
organization: 6357800e-8b77-47a3-af7a-84ee93f019c2
|
||||||
|
when: container_action=='delete'
|
||||||
|
|||||||
Reference in New Issue
Block a user