Browse Source

infrastructure: persist the IP of the OpenStack instance

so it can be retrieved by molecule converge to ssh to the instance
keep-around/441bb62798e1d13de9e6fa259e2b013ebcc09baf
Loïc Dachary 4 years ago
parent
commit
5bc9c6e561
  1. 1
      .gitignore
  2. 33
      molecule/infrastructure/create.yml
  3. 12
      molecule/infrastructure/molecule.yml

1
.gitignore

@ -1,3 +1,4 @@
*~
.molecule
secrets.yml
*.retry

33
molecule/infrastructure/create.yml

@ -1,11 +1,15 @@
# 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:
@ -43,7 +47,7 @@
- python
package_upgrade: true
with_items: "{{ molecule_yml.platforms }}"
register: instances
register: server
- name: Wait for python on the instances
command: >
@ -53,4 +57,29 @@
until: result|success
retries: 30
delay: 10
with_items: "{{ instances.results }}"
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

12
molecule/infrastructure/molecule.yml

@ -4,18 +4,18 @@ driver:
lint:
name: yamllint
platforms:
- name: icinga
- name: icinga_host
flavor: "s1-2"
groups:
- icinga
- name: weblate
- icinga_group
- name: weblate_host
flavor: "s1-4"
groups:
- weblate
- name: ansible
- weblate_group
- name: ansible_host
flavor: "s1-2"
groups:
- ansible
- ansible_group
provisioner:
name: ansible
lint:

Loading…
Cancel
Save