forked from rhtconsulting/rhc-ose
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor OpenStack security group creation
* Adds new openstack-security-groups role * Addresses Issue rhtconsulting#211 and adds all instances to default group * Defines default security group variable with all groups/rules * Sets security group variables per type (master,node,nfs,dns) * Supports specifying no security group for a type (e.g. nfs) * Uses new Ansible 2.x modules
- Loading branch information
Showing
7 changed files
with
216 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
rhc-ose-ansible/roles/openstack-security-groups/defaults/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
default_openshift_openstack_security_groups: | ||
- name: ose3_master | ||
type: master | ||
rules: | ||
- name: ssh | ||
from_port: 22 | ||
to_port: 22 | ||
protocol: tcp | ||
cidr: 0.0.0.0/0 | ||
- name: http | ||
from_port: 80 | ||
to_port: 80 | ||
protocol: tcp | ||
cidr: 0.0.0.0/0 | ||
- name: https | ||
from_port: 443 | ||
to_port: 443 | ||
protocol: tcp | ||
cidr: 0.0.0.0/0 | ||
- name: https-8443 | ||
from_port: 8443 | ||
to_port: 8443 | ||
protocol: tcp | ||
cidr: 0.0.0.0/0 | ||
- name: ose3_nodes | ||
type: node | ||
rules: | ||
- name: ssh | ||
from_port: 22 | ||
to_port: 22 | ||
protocol: tcp | ||
cidr: 0.0.0.0/0 | ||
- name: http | ||
from_port: 80 | ||
to_port: 80 | ||
protocol: tcp | ||
cidr: 0.0.0.0/0 | ||
- name: dns | ||
type: dns | ||
rules: | ||
- name: dns | ||
from_port: 53 | ||
to_port: 53 | ||
protocol: udp | ||
cidr: 0.0.0.0/0 |
106 changes: 106 additions & 0 deletions
106
rhc-ose-ansible/roles/openstack-security-groups/tasks/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
--- | ||
- name: "Set OpenStack Security Group Facts" | ||
set_fact: | ||
openshift_openstack_security_groups: "{{ openshift_openstack_security_groups | default(default_openshift_openstack_security_groups) }}" | ||
|
||
- name: "Determine security group for master" | ||
set_fact: | ||
security_groups_master: "{{ item.name }}" | ||
when: "'{{ item.type }}' == 'master'" | ||
with_items: "{{ security_groups }}" | ||
|
||
- name: "Set security groups for master if found" | ||
set_fact: | ||
security_groups_master: "{{ ['default',security_groups_master | default('')] | join(',') }}" | ||
when: | ||
- security_groups_master is defined | ||
- security_groups_master is not none | ||
- security_groups_master|trim != '' | ||
|
||
- name: "Set security groups for master not found" | ||
set_fact: | ||
security_groups_master: "default" | ||
when: security_groups_master is undefined | ||
|
||
- name: "Determine security group for node" | ||
set_fact: | ||
security_groups_node: "{{ item.name }}" | ||
when: "'{{ item.type }}' == 'node'" | ||
with_items: "{{ security_groups }}" | ||
|
||
- name: "Set security groups for node if found" | ||
set_fact: | ||
security_groups_node: "{{ ['default',security_groups_node | default('')] | join(',') }}" | ||
when: | ||
- security_groups_node is defined | ||
- security_groups_node is not none | ||
- security_groups_node|trim != '' | ||
|
||
- name: "Set security groups for node not found" | ||
set_fact: | ||
security_groups_node: "default" | ||
when: security_groups_node is undefined | ||
|
||
- name: "Determine security group for dns" | ||
set_fact: | ||
security_groups_dns: "{{ item.name }}" | ||
when: "'{{ item.type }}' == 'dns'" | ||
with_items: "{{ security_groups }}" | ||
|
||
- name: "Set security groups for dns if found" | ||
set_fact: | ||
security_groups_dns: "{{ ['default',security_groups_dns | default('')] | join(',') }}" | ||
when: | ||
- security_groups_dns is defined | ||
- security_groups_dns is not none | ||
- security_groups_dns|trim != '' | ||
|
||
- name: "Set security groups for dns not found" | ||
set_fact: | ||
security_groups_dns: "default" | ||
when: security_groups_dns is undefined | ||
|
||
- name: "Determine security group for nfs" | ||
set_fact: | ||
security_groups_nfs: "{{ item.name }}" | ||
when: "'{{ item.type }}' == 'nfs'" | ||
with_items: "{{ security_groups }}" | ||
|
||
- name: "Set security groups for nfs if found" | ||
set_fact: | ||
security_groups_nfs: "{{ ['default',security_groups_nfs | default('')] | join(',') }}" | ||
when: | ||
- security_groups_nfs is defined | ||
- security_groups_nfs is not none | ||
- security_groups_nfs|trim != '' | ||
|
||
- name: "Set security groups for nfs not found" | ||
set_fact: | ||
security_groups_nfs: "default" | ||
when: security_groups_nfs is undefined | ||
|
||
- debug: | ||
var: "{{ 'security_groups_' + item }}" | ||
with_items: | ||
- master | ||
- node | ||
- dns | ||
- nfs | ||
|
||
- name: "Create Security Groups if required" | ||
os_security_group: | ||
name: "{{ item.name }}" | ||
state: present | ||
with_items: "{{ security_groups }}" | ||
|
||
- name: "Create SSH Rule in matching Security Group if required" | ||
os_security_group_rule: | ||
security_group: "{{ item.0.name }}" | ||
protocol: "{{ item.1.protocol }}" | ||
port_range_min: "{{ item.1.from_port }}" | ||
port_range_max: "{{ item.1.to_port }}" | ||
remote_ip_prefix: "{{ item.1.cidr }}" | ||
when: item.1.name is defined | ||
with_subelements: | ||
- "{{ security_groups }}" | ||
- rules |