From 117f388db7ebb8442ade6cfbc81c1aad948a14c6 Mon Sep 17 00:00:00 2001 From: Thomas Constans Date: Wed, 19 Jun 2024 17:56:11 +0200 Subject: [PATCH] =?UTF-8?q?solution=20de=20base,=20sans=20g=C3=A9n=C3=A9ra?= =?UTF-8?q?tion=20du=20fichier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- add_container.yml | 10 ++++++++++ sib.scw_container/README.md | 19 ++++++++++++++----- sib.scw_container/defaults/main.yml | 6 ++++-- sib.scw_container/dns.yml | 11 ----------- sib.scw_container/tasks/main.yml | 23 +++++++---------------- sib.scw_container/tests/hostlist.yml | 7 ------- sib.scw_container/tests/range.yml | 7 ------- sib.scw_container/tests/test.yml | 9 +++------ 8 files changed, 38 insertions(+), 54 deletions(-) create mode 100644 add_container.yml delete mode 100644 sib.scw_container/dns.yml delete mode 100644 sib.scw_container/tests/hostlist.yml delete mode 100644 sib.scw_container/tests/range.yml diff --git a/add_container.yml b/add_container.yml new file mode 100644 index 0000000..db4df3a --- /dev/null +++ b/add_container.yml @@ -0,0 +1,10 @@ +--- +- hosts: localhost + vars: + access_key: SCWR6N2K4C6HYH89H5GR + secret_key: 33c114f3-b49a-4bcc-8ef0-38eb84f10612 + default_organization_id: 6357800e-8b77-47a3-af7a-84ee93f019c2 + default_project_id: 8cf65c8f-64c0-47d3-9f50-fbe249b76aae + container_image: 26e4c50e-91d6-41a5-8898-9e40920e819d + roles: + - sib.scw_container diff --git a/sib.scw_container/README.md b/sib.scw_container/README.md index 293c98b..9074e90 100644 --- a/sib.scw_container/README.md +++ b/sib.scw_container/README.md @@ -1,7 +1,7 @@ Role Name ========= -Create container on scaleaway cloud +Create or delete container on scaleaway cloud Requirements ------------ @@ -11,12 +11,15 @@ None Role Variables -------------- -container_name: -scw_api_secret_key: -scw_api_default_project_id: +secret_key: +default_project_id: scw_type: DEV1-S -scw_image: 26e4c50e-91d6-41a5-8898-9e40920e819d +container_action; delete or running +container_name: +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) +container_image: id of image default alma9 26e4c50e-91d6-41a5-8898-9e40920e819d Dependencies ------------ @@ -29,10 +32,16 @@ Example Playbook ```yaml --- - hosts: localhost + vars: + container_action: running + container_name: plope + container_image: lezknfe2324 roles: - tco.scw_container ``` +will create containers plope.formation.opendoor.fr + License ------- diff --git a/sib.scw_container/defaults/main.yml b/sib.scw_container/defaults/main.yml index 0376500..4a779ba 100644 --- a/sib.scw_container/defaults/main.yml +++ b/sib.scw_container/defaults/main.yml @@ -1,5 +1,7 @@ --- # defaults file for tco.scw_container +scw_gen_hostlist: true scw_type: DEV1-S -scw_image: 26e4c50e-91d6-41a5-8898-9e40920e819d -scw_region: par1 +container_domain: formation.opendoor.fr +container_image: 26e4c50e-91d6-41a5-8898-9e40920e819d +container_number_start: 1 diff --git a/sib.scw_container/dns.yml b/sib.scw_container/dns.yml deleted file mode 100644 index 192e761..0000000 --- a/sib.scw_container/dns.yml +++ /dev/null @@ -1,11 +0,0 @@ -# remove opendoor.fr[.] d'un ndm si besoin -# ---- -- hosts: localhost - vars: - zone: "opendoor.fr" - tasks: - - debug: - msg: "{{ item.record_name | ansible.builtin.regex_replace( '.'+zone, '' ) }}" - #msg: "{{ item.record_name | ansible.builtin.regex_replace( '.'+zone+'.?', '' ) }}" - loop: '{{ dns_records }}' \ No newline at end of file diff --git a/sib.scw_container/tasks/main.yml b/sib.scw_container/tasks/main.yml index 0ebd901..33734cc 100644 --- a/sib.scw_container/tasks/main.yml +++ b/sib.scw_container/tasks/main.yml @@ -1,22 +1,13 @@ --- - - name: create container + + - name: "{{ container_prefix }} : Add" community.general.scaleway_compute: commercial_type: "{{ scw_type }}" + region: par1 name: "{{ container_name }}" - state: running - api_token: "{{ scw_api_secret_key }}" - image: "{{ scw_image}}" - project: "{{ scw_api_default_project_id }}" + state: "running" + api_token: "{{ secret_key }}" + image: "{{ container_image}}" + project: "{{ default_project_id }}" public_ip: dynamic wait: true - region: "{{ scw_region }}" - register: "container_info" - - - name: "generate host list" - ansible.builtin.lineinfile: - create: yes - path: "hostlist.yml" - line: " - { record_name: {{ item.msg.name}}, record_value: {{ item.msg.public_ip.address }} }" - state: present - loop: "{{ container_info.results }}" - diff --git a/sib.scw_container/tests/hostlist.yml b/sib.scw_container/tests/hostlist.yml deleted file mode 100644 index 6ea7a03..0000000 --- a/sib.scw_container/tests/hostlist.yml +++ /dev/null @@ -1,7 +0,0 @@ -dns_records: - - { record_name: test3.formation.opendoor.fr., record_type: A, record_value: 51.15.243.244 } - - { record_name: test4.formation.opendoor.fr., record_type: A, record_value: 212.47.251.35 } - - { record_name: test5.formation.opendoor.fr., record_type: A, record_value: 51.15.142.152 } - - { record_name: test3.formation.opendoor.fr, record_type: A, record_value: 51.15.243.244 } - - { record_name: test4.formation.opendoor.fr, record_type: A, record_value: 212.47.251.35 } - - { record_name: test5.formation.opendoor.fr, record_type: A, record_value: 51.15.142.152 } diff --git a/sib.scw_container/tests/range.yml b/sib.scw_container/tests/range.yml deleted file mode 100644 index c1f4c71..0000000 --- a/sib.scw_container/tests/range.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- -- hosts: localhost - tasks: - - name: with_sequence -> loop - ansible.builtin.debug: - msg: "{{ 'testuser%02x' | format(item) }}" - loop: "{{ range(0, 4 + 1, 2)|list }}" diff --git a/sib.scw_container/tests/test.yml b/sib.scw_container/tests/test.yml index e07e099..ee59d61 100644 --- a/sib.scw_container/tests/test.yml +++ b/sib.scw_container/tests/test.yml @@ -1,12 +1,9 @@ -# call me with --extra-vars=@hostlist.yml --- - hosts: localhost vars: - container_list: - - { host_name: test3.formation.opendoor.fr, host_type: DEV1-S, host_image: 26e4c50e-91d6-41a5-8898-9e40920e819d } - - { host_name: test4.formation.opendoor.fr, host_type: DEV1-S, host_image: 26e4c50e-91d6-41a5-8898-9e40920e819d } - - { host_name: test5.formation.opendoor.fr, host_type: DEV1-S, host_image: 26e4c50e-91d6-41a5-8898-9e40920e819d } container_action: running + container_number: 4 + container_prefix: plop + container_image: lezknfe2324 roles: - tco.scw_container - - { role: tco.dns, dns_action: "add" }