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.
 
 
 
 
 

62 lines
2.9 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 }}"
hosts_orig: "{{ lookup('file', '../../hosts-base.yml') | from_yaml }}"
vars_files:
- ../../clouds.yml
- ../../private-key.yml
roles:
- { role: firewall, state: present, os_security_group_tcp_external: [ 22, 80, 443 ], os_security_group_icmp: true }
- { role: vm, state: present }
tasks:
- name: instance configuration for molecule
set_fact:
instance_conf: |
[
{% for s in server.results %}
{
'instance': '{{ s.openstack.name }}',
'address': '{{ s.openstack.accessIPv4 }}',
'identity_file': '{{ ssh_private_keyfile }}',
'port': '{% if s.openstack.name in hosts_orig.all.hosts and hosts_orig.all.hosts[s.openstack.name].ansible_port is defined %}{{ hosts_orig.all.hosts[s.openstack.name].ansible_port }}{% else %}22{% endif %}',
'user': '{% if s.openstack.name in hosts_orig.all.hosts and hosts_orig.all.hosts[s.openstack.name].ansible_user is defined %}{{ hosts_orig.all.hosts[s.openstack.name].ansible_user }}{% else %}debian{% endif %}',
},
{% endfor %}
]
- name: hosts updates for inventory
set_fact:
hosts_updates: |
{
'all': {
'hosts': {
{% for s in server.results %}
'{{ s.openstack.name }}':
{
'ansible_port': '{% if s.openstack.name in hosts_orig.all.hosts and hosts_orig.all.hosts[s.openstack.name].ansible_port is defined %}{{ hosts_orig.all.hosts[s.openstack.name].ansible_port }}{% else %}22{% endif %}',
'ansible_host': '{{ s.openstack.accessIPv4 }}',
'ansible_user': '{% if s.openstack.name in hosts_orig.all.hosts and hosts_orig.all.hosts[s.openstack.name].ansible_user is defined %}{{ hosts_orig.all.hosts[s.openstack.name].ansible_user }}{% else %}debian{% endif %}',
},
{% endfor %}
}
}
}
- 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 }}"
- name: Dump hosts_conf
copy:
content: "{{ hosts_orig | combine(hosts_updates, recursive=True) | to_yaml }}"
dest: "../../inventory/01-hosts.yml"