solution
This commit is contained in:
49
Readme.md
49
Readme.md
@@ -1,46 +1,13 @@
|
|||||||
# ansible API
|
# ansible API
|
||||||
|
|
||||||
## Objectif
|
|
||||||
|
|
||||||
Utiliser ansible pour créer un container sur le cloud scaleway
|
|
||||||
|
|
||||||
## Documentation
|
|
||||||
|
|
||||||
https://docs.ansible.com/ansible/2.9/modules/scaleway_compute_module.html#scaleway-compute-module
|
|
||||||
|
|
||||||
## Informations utiles
|
|
||||||
|
|
||||||
* Id du projet: 8cf65c8f-64c0-47d3-9f50-fbe249b76aae
|
|
||||||
* Id de l'image ( Alma Linux 9 ) : 26e4c50e-91d6-41a5-8898-9e40920e819d
|
|
||||||
* Type commercial: DEV1-S
|
|
||||||
* Zone: par1
|
|
||||||
|
|
||||||
clé secrète: **CHANGEME**
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
access_key: SCWP03YRZY6G8WTRHY9Z
|
---
|
||||||
scw_api_secret_key: dc743230-9c09-43bc-bcca-7027a6d609e6
|
- hosts: localhost
|
||||||
default_organization_id: 6357800e-8b77-47a3-af7a-84ee93f019c2
|
vars:
|
||||||
scw_api_default_project_id: 8cf65c8f-64c0-47d3-9f50-fbe249b76aae
|
scw_api_secret_key: CHANGEME
|
||||||
```
|
scw_api_default_project_id: 8cf65c8f-64c0-47d3-9f50-fbe249b76aae
|
||||||
|
container_name: evivbulgroz
|
||||||
## Instructions:
|
roles:
|
||||||
|
- sib.scw_container
|
||||||
Écrire un rôle permettant de créer un container sur le cloud scaleway, en utilisant les informations ci-dessus.
|
|
||||||
|
|
||||||
Le rôle doit permettre de spécifier le nom du container que l'on souhaite créer
|
|
||||||
|
|
||||||
Les données sensibles doivent être stockées dans un vault.
|
|
||||||
|
|
||||||
Une fois créé, le container doit être lancé.
|
|
||||||
|
|
||||||
Le rôle doit ensuite générer un fichier contenant:
|
|
||||||
* le nom du container
|
|
||||||
* son adresse ip
|
|
||||||
|
|
||||||
Ex:
|
|
||||||
|
|
||||||
```text
|
|
||||||
- { record_name: mzaldjmaz00, record_value: 51.158.125.92 }
|
|
||||||
- { record_name: mzaldjmaz01, record_value: 51.158.118.75 }
|
|
||||||
```
|
```
|
||||||
45
sib.scw_container/README.md
Normal file
45
sib.scw_container/README.md
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
Role Name
|
||||||
|
=========
|
||||||
|
|
||||||
|
Create container on scaleaway cloud
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
------------
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
Role Variables
|
||||||
|
--------------
|
||||||
|
|
||||||
|
container_name:
|
||||||
|
scw_api_secret_key:
|
||||||
|
scw_api_default_project_id:
|
||||||
|
|
||||||
|
scw_type: DEV1-S
|
||||||
|
scw_image: 26e4c50e-91d6-41a5-8898-9e40920e819d
|
||||||
|
|
||||||
|
Dependencies
|
||||||
|
------------
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
Example Playbook
|
||||||
|
----------------
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
---
|
||||||
|
- hosts: localhost
|
||||||
|
roles:
|
||||||
|
- tco.scw_container
|
||||||
|
```
|
||||||
|
|
||||||
|
License
|
||||||
|
-------
|
||||||
|
|
||||||
|
BSD
|
||||||
|
|
||||||
|
Author Information
|
||||||
|
------------------
|
||||||
|
|
||||||
|
|
||||||
|
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
|
||||||
5
sib.scw_container/defaults/main.yml
Normal file
5
sib.scw_container/defaults/main.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
# defaults file for tco.scw_container
|
||||||
|
scw_type: DEV1-S
|
||||||
|
scw_image: 26e4c50e-91d6-41a5-8898-9e40920e819d
|
||||||
|
scw_region: par1
|
||||||
11
sib.scw_container/dns.yml
Normal file
11
sib.scw_container/dns.yml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# 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 }}'
|
||||||
2
sib.scw_container/handlers/main.yml
Normal file
2
sib.scw_container/handlers/main.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
# handlers file for tco.scw_container
|
||||||
52
sib.scw_container/meta/main.yml
Normal file
52
sib.scw_container/meta/main.yml
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
galaxy_info:
|
||||||
|
author: your name
|
||||||
|
description: your role description
|
||||||
|
company: your company (optional)
|
||||||
|
|
||||||
|
# If the issue tracker for your role is not on github, uncomment the
|
||||||
|
# next line and provide a value
|
||||||
|
# issue_tracker_url: http://example.com/issue/tracker
|
||||||
|
|
||||||
|
# Choose a valid license ID from https://spdx.org - some suggested licenses:
|
||||||
|
# - BSD-3-Clause (default)
|
||||||
|
# - MIT
|
||||||
|
# - GPL-2.0-or-later
|
||||||
|
# - GPL-3.0-only
|
||||||
|
# - Apache-2.0
|
||||||
|
# - CC-BY-4.0
|
||||||
|
license: license (GPL-2.0-or-later, MIT, etc)
|
||||||
|
|
||||||
|
min_ansible_version: 2.1
|
||||||
|
|
||||||
|
# If this a Container Enabled role, provide the minimum Ansible Container version.
|
||||||
|
# min_ansible_container_version:
|
||||||
|
|
||||||
|
#
|
||||||
|
# Provide a list of supported platforms, and for each platform a list of versions.
|
||||||
|
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
|
||||||
|
# To view available platforms and versions (or releases), visit:
|
||||||
|
# https://galaxy.ansible.com/api/v1/platforms/
|
||||||
|
#
|
||||||
|
# platforms:
|
||||||
|
# - name: Fedora
|
||||||
|
# versions:
|
||||||
|
# - all
|
||||||
|
# - 25
|
||||||
|
# - name: SomePlatform
|
||||||
|
# versions:
|
||||||
|
# - all
|
||||||
|
# - 1.0
|
||||||
|
# - 7
|
||||||
|
# - 99.99
|
||||||
|
|
||||||
|
galaxy_tags: []
|
||||||
|
# List tags for your role here, one per line. A tag is a keyword that describes
|
||||||
|
# and categorizes the role. Users find roles by searching for tags. Be sure to
|
||||||
|
# remove the '[]' above, if you add tags to this list.
|
||||||
|
#
|
||||||
|
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
|
||||||
|
# Maximum 20 tags per role.
|
||||||
|
|
||||||
|
dependencies: []
|
||||||
|
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
|
||||||
|
# if you add dependencies to this list.
|
||||||
22
sib.scw_container/tasks/main.yml
Normal file
22
sib.scw_container/tasks/main.yml
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
---
|
||||||
|
- name: create container
|
||||||
|
community.general.scaleway_compute:
|
||||||
|
commercial_type: "{{ scw_type }}"
|
||||||
|
name: "{{ container_name }}"
|
||||||
|
state: running
|
||||||
|
api_token: "{{ scw_api_secret_key }}"
|
||||||
|
image: "{{ scw_image}}"
|
||||||
|
project: "{{ scw_api_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 }}"
|
||||||
|
|
||||||
7
sib.scw_container/tests/hostlist.yml
Normal file
7
sib.scw_container/tests/hostlist.yml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
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 }
|
||||||
2
sib.scw_container/tests/inventory
Normal file
2
sib.scw_container/tests/inventory
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
localhost
|
||||||
|
|
||||||
7
sib.scw_container/tests/range.yml
Normal file
7
sib.scw_container/tests/range.yml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
- hosts: localhost
|
||||||
|
tasks:
|
||||||
|
- name: with_sequence -> loop
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: "{{ 'testuser%02x' | format(item) }}"
|
||||||
|
loop: "{{ range(0, 4 + 1, 2)|list }}"
|
||||||
12
sib.scw_container/tests/test.yml
Normal file
12
sib.scw_container/tests/test.yml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# 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
|
||||||
|
roles:
|
||||||
|
- tco.scw_container
|
||||||
|
- { role: tco.dns, dns_action: "add" }
|
||||||
2
sib.scw_container/vars/main.yml
Normal file
2
sib.scw_container/vars/main.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
# vars file for tco.scw_container
|
||||||
Reference in New Issue
Block a user