Browse Source

infrastructure: create / destroy virtual machines

keep-around/441bb62798e1d13de9e6fa259e2b013ebcc09baf
Loïc Dachary 4 years ago
parent
commit
0e9caa2887
  1. 37
      molecule/infrastructure/create.yml
  2. 31
      molecule/infrastructure/destroy.yml
  3. 2
      requirements.in

37
molecule/infrastructure/create.yml

@ -5,7 +5,7 @@
vars:
molecule_file: "{{ lookup('env', 'MOLECULE_FILE') }}"
molecule_yml: "{{ lookup('file', molecule_file) | from_yaml }}"
secrets: "{{ lookup('file', '..', 'secrets.yml') | from_yaml }}"
secrets: "{{ lookup('file', '../secrets.yml') | from_yaml }}"
tasks:
- name: key
os_keypair:
@ -19,3 +19,38 @@
password: "{{ secrets.OS_PASSWORD }}"
project_name: "{{ secrets.OS_TENANT_NAME }}"
region_name: "{{ secrets.OS_REGION_NAME }}"
- name: launch instances
os_server:
state: present
auth:
auth_url: "{{ secrets.OS_AUTH_URL }}"
username: "{{ secrets.OS_USERNAME }}"
password: "{{ secrets.OS_PASSWORD }}"
project_name: "{{ secrets.OS_TENANT_NAME }}"
region_name: "{{ secrets.OS_REGION_NAME }}"
name: "{{ item.name }}"
image: Debian 9
key_name: loic
timeout: 200
flavor: "{{ item.flavor }}"
security_groups: default
auto_ip: yes
wait: true
userdata: |
#cloud-config
packages:
- python
package_upgrade: true
with_items: "{{ molecule_yml.platforms }}"
register: instances
- name: Wait for python on the instances
command: >
ssh -oBatchMode=yes -oStrictHostKeyChecking=no
debian@{{item.openstack.public_v4}} which python
register: result
until: result|success
retries: 30
delay: 10
with_items: "{{ instances.results }}"

31
molecule/infrastructure/destroy.yml

@ -0,0 +1,31 @@
- name: Destroy
hosts: localhost
connection: local
gather_facts: False
vars:
molecule_file: "{{ lookup('env', 'MOLECULE_FILE') }}"
molecule_yml: "{{ lookup('file', molecule_file) | from_yaml }}"
secrets: "{{ lookup('file', '../secrets.yml') | from_yaml }}"
tasks:
- name: key
os_keypair:
state: absent
name: loic
auth:
auth_url: "{{ secrets.OS_AUTH_URL }}"
username: "{{ secrets.OS_USERNAME }}"
password: "{{ secrets.OS_PASSWORD }}"
project_name: "{{ secrets.OS_TENANT_NAME }}"
region_name: "{{ secrets.OS_REGION_NAME }}"
- name: destroy instances
os_server:
state: absent
auth:
auth_url: "{{ secrets.OS_AUTH_URL }}"
username: "{{ secrets.OS_USERNAME }}"
password: "{{ secrets.OS_PASSWORD }}"
project_name: "{{ secrets.OS_TENANT_NAME }}"
region_name: "{{ secrets.OS_REGION_NAME }}"
name: "{{ item.name }}"
with_items: "{{ molecule_yml.platforms }}"

2
requirements.in

@ -1,2 +1,4 @@
ansible
pip-tools
molecule
shade

Loading…
Cancel
Save