diff options
Diffstat (limited to 'deployment/noheat/infra-openstack/ansible/roles')
14 files changed, 175 insertions, 0 deletions
diff --git a/deployment/noheat/infra-openstack/ansible/roles/create_hosts/tasks/create_host.yml b/deployment/noheat/infra-openstack/ansible/roles/create_hosts/tasks/create_host.yml new file mode 100644 index 000000000..8fa4d0709 --- /dev/null +++ b/deployment/noheat/infra-openstack/ansible/roles/create_hosts/tasks/create_host.yml @@ -0,0 +1,33 @@ +--- +- name: Create host + os_server: + state: present + name: "{{ host.name }}" + image: "{{ host.image }}" + flavor: "{{ host.flavor }}" + key_name: "{{ host.keypair }}" + network: "{{ host.network }}" + security_groups: + - "{{ host.securitygroup }}" + auto_ip: "{{ host.auto_ip | default(true) }}" + boot_from_volume: "{{ host.boot_from_volume | default(true) }}" + terminate_volume: "{{ host.terminate_volume | default(true) }}" + volume_size: "{{ host.volume_size | default(10) }}" + userdata: | + #cloud-config + ssh_authorized_keys: + - "{{ operator_key }}" + register: new_host + +- name: Add host to inventory + add_host: + hostname: "{{ new_host.server.name }}" + groups: "{{ cluster.name }}" + ansible_ssh_host: "{{ new_host.server.public_v4 }}" + ansible_ssh_user: "{{ image.user }}" + ansible_ssh_extra_args: "-o StrictHostKeyChecking=no" + ansible_ssh_private_key_file: "~/.ssh/{{ keypair.key.name }}" + +- name: Add host to hosts dict + set_fact: + hosts_dict: "{{ hosts_dict|default({}) | combine( {new_host.server.name: new_host.server.private_v4} ) }}" diff --git a/deployment/noheat/infra-openstack/ansible/roles/create_hosts/tasks/main.yml b/deployment/noheat/infra-openstack/ansible/roles/create_hosts/tasks/main.yml new file mode 100644 index 000000000..933b2f526 --- /dev/null +++ b/deployment/noheat/infra-openstack/ansible/roles/create_hosts/tasks/main.yml @@ -0,0 +1,5 @@ +--- +- include_tasks: create_host.yml + loop: "{{ hosts }}" + loop_control: + loop_var: host diff --git a/deployment/noheat/infra-openstack/ansible/roles/create_keypair/tasks/main.yml b/deployment/noheat/infra-openstack/ansible/roles/create_keypair/tasks/main.yml new file mode 100644 index 000000000..8a7c72092 --- /dev/null +++ b/deployment/noheat/infra-openstack/ansible/roles/create_keypair/tasks/main.yml @@ -0,0 +1,25 @@ +- name: Create keypair + os_keypair: + state: present + name: "{{ keypair.name }}" + register: keypair + +- name: Create local public key + copy: + content: "{{ keypair.key.public_key }}" + dest: "~/.ssh/{{ keypair.key.name }}.pub" + mode: 0600 + delegate_to: localhost + +- name: Check if local private key exists + stat: + path: "~/.ssh/{{ keypair.key.name }}" + register: local_private_key + +- name: Create local private key + copy: + content: "{{ keypair.key.private_key }}" + dest: "~/.ssh/{{ keypair.key.name }}" + mode: 0600 + delegate_to: localhost + when: not local_private_key.stat.exists diff --git a/deployment/noheat/infra-openstack/ansible/roles/create_network/tasks/create_network.yml b/deployment/noheat/infra-openstack/ansible/roles/create_network/tasks/create_network.yml new file mode 100644 index 000000000..3e22ee6ce --- /dev/null +++ b/deployment/noheat/infra-openstack/ansible/roles/create_network/tasks/create_network.yml @@ -0,0 +1,28 @@ +--- +- name: "Create {{ net.name }} network" + os_network: + name: "{{ net.name }}" + state: present + +- name: Set nameservers list fact + set_fact: + dns_ips: "{{ network.dns_servers | list }}" + when: network.dns_servers[0] is defined + +- name: "Create {{ net.name }} subnet" + os_subnet: + name: "{{ net.name }}_subnet" + network_name: "{{ net.name }}" + cidr: "{{ net.cidr }}" + dns_nameservers: "{{ dns_ips if dns_ips is defined else omit }}" + allocation_pool_start: '{{ net.allocation_pool_start | default("") }}' + allocation_pool_end: '{{ net.allocation_pool_end | default ("") }}' + state: present + +- name: "Create {{ net.name }} router" + os_router: + name: "{{ net.name }}_router" + network: public + interfaces: + - "{{ net.name }}_subnet" + state: present diff --git a/deployment/noheat/infra-openstack/ansible/roles/create_network/tasks/main.yml b/deployment/noheat/infra-openstack/ansible/roles/create_network/tasks/main.yml new file mode 100644 index 000000000..cce6f790b --- /dev/null +++ b/deployment/noheat/infra-openstack/ansible/roles/create_network/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- include_tasks: create_network.yml + loop: + - "{{ network }}" + loop_control: + loop_var: net diff --git a/deployment/noheat/infra-openstack/ansible/roles/create_securitygroup/tasks/create_securitygroup.yml b/deployment/noheat/infra-openstack/ansible/roles/create_securitygroup/tasks/create_securitygroup.yml new file mode 100644 index 000000000..b9a3e2973 --- /dev/null +++ b/deployment/noheat/infra-openstack/ansible/roles/create_securitygroup/tasks/create_securitygroup.yml @@ -0,0 +1,23 @@ +--- +- name: "Create {{ secgrp.name }} security group" + os_security_group: + state: present + name: "{{ secgrp.name }}" + +- name: "Create {{ secgrp.name }} security group rule for ping" + os_security_group_rule: + security_group: "{{ secgrp.name }}" + protocol: icmp + remote_ip_prefix: "{{ item }}" + loop: "{{ secgrp.remote_ip_prefix }}" + +- name: "Create {{ secgrp.name }} security group rule for all TCP" + os_security_group_rule: + security_group: "{{ secgrp.name }}" + protocol: tcp + remote_ip_prefix: "0.0.0.0/0" + +- name: "Create {{ secgrp.name }} security group rule for all UDP" + os_security_group_rule: + security_group: "{{ secgrp.name }}" + protocol: udp diff --git a/deployment/noheat/infra-openstack/ansible/roles/create_securitygroup/tasks/main.yml b/deployment/noheat/infra-openstack/ansible/roles/create_securitygroup/tasks/main.yml new file mode 100644 index 000000000..872988032 --- /dev/null +++ b/deployment/noheat/infra-openstack/ansible/roles/create_securitygroup/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- include_tasks: create_securitygroup.yml + loop: + - "{{ securitygroup }}" + loop_control: + loop_var: secgrp diff --git a/deployment/noheat/infra-openstack/ansible/roles/destroy_hosts/tasks/destroy_host.yml b/deployment/noheat/infra-openstack/ansible/roles/destroy_hosts/tasks/destroy_host.yml new file mode 100644 index 000000000..e9cedce7a --- /dev/null +++ b/deployment/noheat/infra-openstack/ansible/roles/destroy_hosts/tasks/destroy_host.yml @@ -0,0 +1,5 @@ +--- +- name: Destroy host + os_server: + name: "{{ host.name }}" + state: absent diff --git a/deployment/noheat/infra-openstack/ansible/roles/destroy_hosts/tasks/main.yml b/deployment/noheat/infra-openstack/ansible/roles/destroy_hosts/tasks/main.yml new file mode 100644 index 000000000..1dd5c7224 --- /dev/null +++ b/deployment/noheat/infra-openstack/ansible/roles/destroy_hosts/tasks/main.yml @@ -0,0 +1,5 @@ +--- +- include_tasks: destroy_host.yml + loop: "{{ hosts }}" + loop_control: + loop_var: host diff --git a/deployment/noheat/infra-openstack/ansible/roles/destroy_keypair/tasks/main.yml b/deployment/noheat/infra-openstack/ansible/roles/destroy_keypair/tasks/main.yml new file mode 100644 index 000000000..6025b82b3 --- /dev/null +++ b/deployment/noheat/infra-openstack/ansible/roles/destroy_keypair/tasks/main.yml @@ -0,0 +1,12 @@ +- name: Destroy keypair + os_keypair: + state: absent + name: "{{ keypair.name }}" + +- name: Destroy local keypair + file: + state: absent + path: "{{ item }}" + loop: + - "~/.ssh/{{ keypair.name }}.pub" + - "~/.ssh/{{ keypair.name }}" diff --git a/deployment/noheat/infra-openstack/ansible/roles/destroy_network/tasks/destroy_network.yml b/deployment/noheat/infra-openstack/ansible/roles/destroy_network/tasks/destroy_network.yml new file mode 100644 index 000000000..8f97d9507 --- /dev/null +++ b/deployment/noheat/infra-openstack/ansible/roles/destroy_network/tasks/destroy_network.yml @@ -0,0 +1,10 @@ +--- +- name: "Destroy {{ net.name }} router" + os_router: + name: "{{ net.name }}_router" + state: absent + +- name: "Destroy {{ net.name }} network and its subnets" + os_network: + name: "{{ net.name }}" + state: absent diff --git a/deployment/noheat/infra-openstack/ansible/roles/destroy_network/tasks/main.yml b/deployment/noheat/infra-openstack/ansible/roles/destroy_network/tasks/main.yml new file mode 100644 index 000000000..1d84ab62a --- /dev/null +++ b/deployment/noheat/infra-openstack/ansible/roles/destroy_network/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- include_tasks: destroy_network.yml + loop: + - "{{ network }}" + loop_control: + loop_var: net diff --git a/deployment/noheat/infra-openstack/ansible/roles/destroy_securitygroup/tasks/destroy_securitygroup.yml b/deployment/noheat/infra-openstack/ansible/roles/destroy_securitygroup/tasks/destroy_securitygroup.yml new file mode 100644 index 000000000..eb86f9bc2 --- /dev/null +++ b/deployment/noheat/infra-openstack/ansible/roles/destroy_securitygroup/tasks/destroy_securitygroup.yml @@ -0,0 +1,5 @@ +--- +- name: "Destroy {{ secgrp.name }} security group" + os_security_group: + state: absent + name: "{{ secgrp.name }}" diff --git a/deployment/noheat/infra-openstack/ansible/roles/destroy_securitygroup/tasks/main.yml b/deployment/noheat/infra-openstack/ansible/roles/destroy_securitygroup/tasks/main.yml new file mode 100644 index 000000000..8142e8070 --- /dev/null +++ b/deployment/noheat/infra-openstack/ansible/roles/destroy_securitygroup/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- include_tasks: destroy_securitygroup.yml + loop: + - "{{ securitygroup }}" + loop_control: + loop_var: secgrp |