summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--roles/openshift_common/defaults/main.yml5
-rw-r--r--roles/openshift_common/tasks/main.yml1
-rw-r--r--roles/openshift_master/tasks/main.yml4
-rw-r--r--roles/openshift_node/library/openshift_register_node.py150
-rw-r--r--roles/openshift_node/tasks/main.yml6
-rw-r--r--roles/openshift_sdn_master/README.md38
-rw-r--r--roles/openshift_sdn_master/defaults/main.yml2
-rw-r--r--roles/openshift_sdn_master/handlers/main.yml3
-rw-r--r--roles/openshift_sdn_master/meta/main.yml14
-rw-r--r--roles/openshift_sdn_master/tasks/main.yml26
-rw-r--r--roles/openshift_sdn_node/README.md38
-rw-r--r--roles/openshift_sdn_node/defaults/main.yml2
-rw-r--r--roles/openshift_sdn_node/handlers/main.yml3
-rw-r--r--roles/openshift_sdn_node/meta/main.yml14
-rw-r--r--roles/openshift_sdn_node/tasks/main.yml41
15 files changed, 345 insertions, 2 deletions
diff --git a/roles/openshift_common/defaults/main.yml b/roles/openshift_common/defaults/main.yml
index 20b6f082c..a541591fb 100644
--- a/roles/openshift_common/defaults/main.yml
+++ b/roles/openshift_common/defaults/main.yml
@@ -1,3 +1,8 @@
---
openshift_bind_ip: "{{ ansible_default_ipv4.address }}"
openshift_debug_level: 0
+
+# TODO: Once openshift stops resolving hostnames for node queries remove
+# this...
+openshift_hostname_workaround: true
+openshift_hostname: "{{ openshift_public_ip if openshift_hostname_workaround else ansible_fqdn }}"
diff --git a/roles/openshift_common/tasks/main.yml b/roles/openshift_common/tasks/main.yml
index 988b36306..b94fca690 100644
--- a/roles/openshift_common/tasks/main.yml
+++ b/roles/openshift_common/tasks/main.yml
@@ -2,6 +2,7 @@
# fixme: Once openshift stops resolving hostnames for node queries remove this...
- name: Set hostname to IP Addr (WORKAROUND)
hostname: name={{ openshift_bind_ip }}
+ when: openshift_hostname_workaround
- name: Configure local facts file
file: path=/etc/ansible/facts.d/ state=directory mode=0750
diff --git a/roles/openshift_master/tasks/main.yml b/roles/openshift_master/tasks/main.yml
index 6c318efce..eb8c6a2bd 100644
--- a/roles/openshift_master/tasks/main.yml
+++ b/roles/openshift_master/tasks/main.yml
@@ -21,8 +21,8 @@
lineinfile:
dest: /etc/sysconfig/openshift-master
regexp: '^OPTIONS='
- line: "OPTIONS=\"--public-master={{ openshift_public_ip }} --nodes={{ openshift_node_ips
- | join(',') }} --loglevel={{ openshift_master_debug_level }}\""
+ line: "OPTIONS=\"--public-master={{ openshift_hostname }} --nodes={{ openshift_node_ips
+ | join(',') }} --loglevel={{ openshift_master_debug_level }}\""
notify:
- restart openshift-master
diff --git a/roles/openshift_node/library/openshift_register_node.py b/roles/openshift_node/library/openshift_register_node.py
new file mode 100644
index 000000000..87290c209
--- /dev/null
+++ b/roles/openshift_node/library/openshift_register_node.py
@@ -0,0 +1,150 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+import os
+import multiprocessing
+import socket
+from subprocess import check_output, Popen
+
+DOCUMENTATION = '''
+---
+module: openshift_register_node
+short_description: This module registers an openshift-node with an openshift-master
+author: Jason DeTiberus
+requirements: [ openshift-node ]
+notes: Node resources can be specified using either the resources option or the following options: cpu, memory
+options:
+ name:
+ description:
+ - id for this node (usually the node fqdn)
+ required: true
+ hostIP:
+ description:
+ - ip address for this node
+ required: false
+ cpu:
+ description:
+ - number of CPUs for this node
+ required: false
+ default: number of logical CPUs detected
+ memory:
+ description:
+ - Memory available for this node in bytes
+ required: false
+ default: 80% MemTotal
+ resources:
+ description:
+ - A json string representing Node resources
+ required: false
+'''
+EXAMPLES = '''
+# Minimal node registration
+- openshift_register_node: name=ose3.node.example.com
+
+# Node registration with all options (using cpu and memory options)
+- openshift_register_node:
+ name: ose3.node.example.com
+ hostIP: 192.168.1.1
+ apiVersion: v1beta1
+ cpu: 1
+ memory: 1073741824
+
+# Node registration with all options (using resources option)
+- openshift_register_node:
+ name: ose3.node.example.com
+ hostIP: 192.168.1.1
+ apiVersion: v1beta1
+ resources:
+ capacity:
+ cpu: 1
+ memory: 1073741824
+'''
+
+def main():
+ default_config='/var/lib/openshift/openshift.local.certificates/admin/.kubeconfig'
+
+ module = AnsibleModule(
+ argument_spec = dict(
+ name = dict(required = True),
+ hostIP = dict(),
+ apiVersion = dict(),
+ cpu = dict(),
+ memory = dict(),
+ resources = dict(),
+ client_config = dict(default = default_config)
+ ),
+ supports_check_mode=True
+ )
+
+ if module.params['resources'] and (module.params['cpu'] or module.params['memory']):
+ module.fail_json(msg="Error: argument resources cannot be specified with the following arguments: cpu, memory")
+
+ client_env = os.environ.copy()
+ client_env['KUBECONFIG'] = module.params['client_config']
+
+ node_def = dict(
+ metadata = dict(
+ name = module.params['name']
+ ),
+ kind = 'Node',
+ resources = dict(
+ capacity = dict()
+ )
+ )
+
+ for key, value in module.params.iteritems():
+ if key in ['cpu', 'memory']:
+ node_def['resources']['capacity'][key] = value
+ elif key == 'name':
+ node_def['id'] = value
+ elif key != 'client_config':
+ if value:
+ node_def[key] = value
+
+ if not node_def['resources']['capacity']['cpu']:
+ node_def['resources']['capacity']['cpu'] = multiprocessing.cpu_count()
+
+ if not node_def['resources']['capacity']['memory']:
+ with open('/proc/meminfo', 'r') as mem:
+ for line in mem:
+ entries = line.split()
+ if str(entries.pop(0)) == 'MemTotal:':
+ mem_free_kb = int(entries.pop(0))
+ mem_capacity = int(mem_free_kb * 1024 * .80)
+ node_def['resources']['capacity']['memory'] = mem_capacity
+ break
+
+ try:
+ output = check_output("osc get nodes", shell=True, env=client_env,
+ stderr=subprocess.STDOUT)
+ except subprocess.CalledProcessError as e:
+ module.fail_json(msg="Failed to get node list", command=e.cmd,
+ returncode=e.returncode, output=e.output)
+
+ if module.check_mode:
+ if re.search(module.params['name'], output, re.MULTILINE):
+ module.exit_json(changed=False, node_def=node_def)
+ else:
+ module.exit_json(changed=True, node_def=node_def)
+
+ p = Popen("osc create node -f -", shell=True, stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True,
+ env=client_env)
+ (out, err) = p.communicate(module.jsonify(node_def))
+ ret = p.returncode
+
+ if ret != 0:
+ if re.search("minion \"%s\" already exists" % module.params['name'],
+ err):
+ module.exit_json(changed=False,
+ msg="node definition already exists", node_def=node_def)
+ else:
+ module.fail_json(msg="Node creation failed.", ret=ret, out=out,
+ err=err, node_def=node_def)
+
+ module.exit_json(changed=True, out=out, err=err, ret=ret,
+ node_def=node_def)
+
+# import module snippets
+from ansible.module_utils.basic import *
+main()
diff --git a/roles/openshift_node/tasks/main.yml b/roles/openshift_node/tasks/main.yml
index e5bc175a2..de010bd0c 100644
--- a/roles/openshift_node/tasks/main.yml
+++ b/roles/openshift_node/tasks/main.yml
@@ -61,3 +61,9 @@
- name: Disable openshift-node if openshift-node is managed externally
service: name=openshift-node enabled=false
when: openshift_node_manage_service_externally
+
+# TODO: expose openshift_register_node options to allow for overriding the
+# defaults.
+- name: Register node (if not already registered)
+ openshift_register_node:
+ name: "{{ openshift_hostname }}"
diff --git a/roles/openshift_sdn_master/README.md b/roles/openshift_sdn_master/README.md
new file mode 100644
index 000000000..225dd44b9
--- /dev/null
+++ b/roles/openshift_sdn_master/README.md
@@ -0,0 +1,38 @@
+Role Name
+=========
+
+A brief description of the role goes here.
+
+Requirements
+------------
+
+Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
+
+Role Variables
+--------------
+
+A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
+
+Dependencies
+------------
+
+A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
+
+Example Playbook
+----------------
+
+Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
+
+ - hosts: servers
+ roles:
+ - { role: username.rolename, x: 42 }
+
+License
+-------
+
+BSD
+
+Author Information
+------------------
+
+An optional section for the role authors to include contact information, or a website (HTML is not allowed).
diff --git a/roles/openshift_sdn_master/defaults/main.yml b/roles/openshift_sdn_master/defaults/main.yml
new file mode 100644
index 000000000..da7655546
--- /dev/null
+++ b/roles/openshift_sdn_master/defaults/main.yml
@@ -0,0 +1,2 @@
+---
+openshift_sdn_master_debug_level: "{{ openshift_debug_level | default(0) }}"
diff --git a/roles/openshift_sdn_master/handlers/main.yml b/roles/openshift_sdn_master/handlers/main.yml
new file mode 100644
index 000000000..cd645f2c5
--- /dev/null
+++ b/roles/openshift_sdn_master/handlers/main.yml
@@ -0,0 +1,3 @@
+---
+- name: restart openshift-sdn-master
+ service: name=openshift-sdn-master state=restarted
diff --git a/roles/openshift_sdn_master/meta/main.yml b/roles/openshift_sdn_master/meta/main.yml
new file mode 100644
index 000000000..2fd6c64e0
--- /dev/null
+++ b/roles/openshift_sdn_master/meta/main.yml
@@ -0,0 +1,14 @@
+---
+galaxy_info:
+ author: Jason DeTiberus
+ description: OpenShift SDN Master
+ company: Red Hat, Inc.
+ license: ASL 2.0
+ min_ansible_version: 1.7
+ platforms:
+ - name: EL
+ versions:
+ - 7
+ categories:
+ - cloud
+dependencies: []
diff --git a/roles/openshift_sdn_master/tasks/main.yml b/roles/openshift_sdn_master/tasks/main.yml
new file mode 100644
index 000000000..e1761afdc
--- /dev/null
+++ b/roles/openshift_sdn_master/tasks/main.yml
@@ -0,0 +1,26 @@
+---
+- name: Install openshift-sdn-master
+ yum:
+ pkg: openshift-sdn-master
+ state: installed
+
+- name: Configure openshift-sdn-master settings
+ lineinfile:
+ dest: /etc/sysconfig/openshift-sdn-master
+ regexp: '^OPTIONS='
+ line: "OPTIONS=\"-v={{ openshift_sdn_master_debug_level }}\""
+ notify:
+ - restart openshift-sdn-master
+
+- name: Set openshift-sdn-master facts
+ include: "{{ role_path | dirname }}/openshift_common/tasks/set_facts.yml"
+ facts:
+ - section: sdn-master
+ option: debug_level
+ value: "{{ openshift_sdn_master_debug_level }}"
+
+- name: Enable openshift-sdn-master
+ service:
+ name: openshift-sdn-master
+ enabled: yes
+ state: started
diff --git a/roles/openshift_sdn_node/README.md b/roles/openshift_sdn_node/README.md
new file mode 100644
index 000000000..225dd44b9
--- /dev/null
+++ b/roles/openshift_sdn_node/README.md
@@ -0,0 +1,38 @@
+Role Name
+=========
+
+A brief description of the role goes here.
+
+Requirements
+------------
+
+Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
+
+Role Variables
+--------------
+
+A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
+
+Dependencies
+------------
+
+A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
+
+Example Playbook
+----------------
+
+Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
+
+ - hosts: servers
+ roles:
+ - { role: username.rolename, x: 42 }
+
+License
+-------
+
+BSD
+
+Author Information
+------------------
+
+An optional section for the role authors to include contact information, or a website (HTML is not allowed).
diff --git a/roles/openshift_sdn_node/defaults/main.yml b/roles/openshift_sdn_node/defaults/main.yml
new file mode 100644
index 000000000..9612d9d91
--- /dev/null
+++ b/roles/openshift_sdn_node/defaults/main.yml
@@ -0,0 +1,2 @@
+---
+openshift_sdn_node_debug_level: "{{ openshift_debug_level | default(0) }}"
diff --git a/roles/openshift_sdn_node/handlers/main.yml b/roles/openshift_sdn_node/handlers/main.yml
new file mode 100644
index 000000000..402d82149
--- /dev/null
+++ b/roles/openshift_sdn_node/handlers/main.yml
@@ -0,0 +1,3 @@
+---
+- name: restart openshift-sdn-node
+ service: name=openshift-sdn-node state=restarted
diff --git a/roles/openshift_sdn_node/meta/main.yml b/roles/openshift_sdn_node/meta/main.yml
new file mode 100644
index 000000000..a68ae8e54
--- /dev/null
+++ b/roles/openshift_sdn_node/meta/main.yml
@@ -0,0 +1,14 @@
+---
+galaxy_info:
+ author: Jason DeTiberus
+ description: OpenShift SDN Node
+ company: Red Hat, Inc.
+ license: ASL 2.0
+ min_ansible_version: 1.7
+ platforms:
+ - name: EL
+ versions:
+ - 7
+ categories:
+ - cloud
+dependencies: []
diff --git a/roles/openshift_sdn_node/tasks/main.yml b/roles/openshift_sdn_node/tasks/main.yml
new file mode 100644
index 000000000..71bba2f92
--- /dev/null
+++ b/roles/openshift_sdn_node/tasks/main.yml
@@ -0,0 +1,41 @@
+---
+- name: Install openshift-sdn-node
+ yum:
+ pkg: openshift-sdn-node
+ state: installed
+
+# TODO: we are specifying -hostname= for OPTIONS as a workaround for
+# openshift-sdn-node not properly detecting the hostname.
+- name: Configure openshift-sdn-node settings
+ lineinfile:
+ dest: /etc/sysconfig/openshift-sdn-node
+ regexp: "{{ item.regex }}"
+ line: "{{ item.line }}"
+ backrefs: yes
+ with_items:
+ - regex: '^(OPTIONS=)'
+ line: '\1"-v={{ openshift_sdn_node_debug_level }} -hostname={{ openshift_bind_ip if openshift_hostname_workaround else ansible_fqdn }}"'
+ - regex: '^(MASTER_URL=)'
+ line: '\1"http://{{ openshift_master_ips | first }}:4001"'
+ - regex: '^(MINION_IP=)'
+ line: '\1"{{ openshift_public_ip }}"'
+ # TODO lock down the insecure-registry config to a more sane value than
+ # 0.0.0.0/0
+ - regex: '^(DOCKER_OPTIONS=)'
+ line: '\1"--insecure-registry=0.0.0.0/0 -b=lbr0 --mtu=1450 --selinux-enabled"'
+ notify: restart openshift-sdn-node
+
+- name: Set openshift-sdn-master facts
+ include: "{{ role_path | dirname }}/openshift_common/tasks/set_facts.yml"
+ facts:
+ - section: sdn-master
+ option: debug_level
+ value: "{{ openshift_sdn_master_debug_level }}"
+
+# fixme: Once the openshift_cluster playbook is published state should be started
+# Always bounce service to pick up new credentials
+- name: Start and enable openshift-sdn-node
+ service:
+ name: openshift-sdn-node
+ enabled: yes
+ state: restarted