You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

85 lines
3.1 KiB

# adapted from molecule/cookiecutter/scenario/driver/openstack/{{cookiecutter.molecule_directory}}/{{cookiecutter.scenario_name}}/create.yml
- name: Create
hosts: localhost
connection: local
gather_facts: False
vars:
molecule_file: "{{ lookup('env', 'MOLECULE_FILE') }}"
molecule_instance_config: "{{ lookup('env', 'MOLECULE_INSTANCE_CONFIG') }}"
molecule_yml: "{{ lookup('file', molecule_file) | from_yaml }}"
secrets: "{{ lookup('file', '../secrets.yml') | from_yaml }}"
user: debian
ssh_port: 22
tasks:
- name: key
os_keypair:
state: present
name: loic
public_key: >-
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEApKfP/I/WoSeX7MAFGpdntC56oHk0wJNn+qy0cud321yTaZRReJGQyqhoBk/sXsnqF4mOpXTf3+Ao1hQIiFazR5Fbmvk7DR0nKj8sGPV0iJB1F0+eyL+w7mgPyD8VDCw+ygCWG4ghMfeGKRAJQweO4v7rFx61UeYDxNk3roOgeuM= loic@inspiron.dachary.org
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: 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: server
- 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: "{{ server.results }}"
- name: Populate instance config dict
set_fact:
instance_conf_dict: {
'instance': "{{ item.openstack.name }}",
'address': "{{ item.openstack.accessIPv4 }}",
'user': "{{ user }}",
'port': "{{ ssh_port }}",
'identity_file': /home/loic/.ssh/id_rsa, }
with_items: "{{ server.results }}"
register: instance_config_dict
# when: server.changed | bool
- name: Convert instance config dict to a list
set_fact:
instance_conf: "{{ instance_config_dict.results | map(attribute='ansible_facts.instance_conf_dict') | list }}"
# when: server.changed | bool
- name: Dump instance config
copy:
# NOTE(retr0h): Workaround for Ansible 2.2.
# https://github.com/ansible/ansible/issues/20885
content: "{{ instance_conf | to_json | from_json | molecule_to_yaml | molecule_header }}"
dest: "{{ molecule_instance_config }}"
# when: server.changed | bool