role need a name prefix, a number of containers to create
This commit is contained in:
@@ -1,22 +1,30 @@
|
||||
---
|
||||
- community.general.scaleway_compute:
|
||||
commercial_type: DEV1-S
|
||||
commercial_type: "{{ item.host_type|default( scw_type )}}"
|
||||
region: par1
|
||||
name: "{{ item}}"
|
||||
name: "{{ container_prefix+'%02x' | format(item) }}"
|
||||
state: "{{ (container_action == 'delete' ) | ternary( 'absent', 'running' ) }}"
|
||||
api_token: "{{ scw_api_secret_key }}"
|
||||
image: 26e4c50e-91d6-41a5-8898-9e40920e819d
|
||||
image: "{{ container_image}}"
|
||||
project: "{{ scw_api_default_project_id }}"
|
||||
public_ip: dynamic
|
||||
loop: "{{ container_list }}"
|
||||
wait: true
|
||||
loop: "{{ range(0, container_number , 1)|list }}"
|
||||
register: "container_info"
|
||||
|
||||
- name: "generate host list"
|
||||
ansible.builtin.lineinfile:
|
||||
create: yes
|
||||
path: "hostlist.yml"
|
||||
line: "- { record_name: {{ item.msg.name}}, record_type: A, record_value: {{ item.msg.public_ip.address }} }"
|
||||
state: present
|
||||
loop: "{{ container_info.results }}"
|
||||
block:
|
||||
- ansible.builtin.lineinfile:
|
||||
create: yes
|
||||
path: "hostlist.yml"
|
||||
line: "dns_records:"
|
||||
insertbefore: BOF
|
||||
|
||||
- ansible.builtin.lineinfile:
|
||||
create: yes
|
||||
path: "hostlist.yml"
|
||||
line: " - { record_name: {{ item.msg.name}}, record_type: A, record_value: {{ item.msg.public_ip.address }} }"
|
||||
state: present
|
||||
loop: "{{ container_info.results }}"
|
||||
when: scw_gen_hostlist is true and container_action !='delete'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user