Browse Source

Add FreeBSD support (#13)

FreeBSD support by @smuth4! :smiley:
Stephen Muth 9 years ago
parent
commit
b27fc8f977

+ 23 - 6
README.md

@@ -25,11 +25,11 @@ This role requires Ansible 2.0
 - [CentOS - 7](https://wiki.centos.org/Manuals/ReleaseNotes/CentOS7)
 - [Debian - 8 (Jessie)](https://wiki.debian.org/DebianJessie)
 - [Ubuntu - 15.04 (Vivid Vervet)](http://releases.ubuntu.com/15.04/)
+- [FreeBSD - 10.2](https://www.freebsd.org/releases/10.2R/relnotes.html)
 
 ### Future Releases
 
 - OpenBSD
-- FreeBSD
 - NetBSD
 
 ## Role Variables
@@ -94,11 +94,13 @@ _Note: The above options are intended to provide users with flexibility. This al
 ### Sensu/RabbitMQ SSL certificate properties
 ``` yaml
 sensu_ssl_gen_certs: true
-sensu_ssl_client_cert: "{{ dynamic_data_store }}/{{ groups['sensu_masters'][0] }}/{{ sensu_config_path }}/ssl_generation/sensu_ssl_tool/client/cert.pem"
-sensu_ssl_client_key: "{{ dynamic_data_store }}/{{ groups['sensu_masters'][0] }}/{{ sensu_config_path }}/ssl_generation/sensu_ssl_tool/client/key.pem"
-sensu_ssl_server_cacert: "{{ dynamic_data_store }}/{{ groups['sensu_masters'][0] }}/{{ sensu_config_path }}/ssl_generation/sensu_ssl_tool/sensu_ca/cacert.pem"
-sensu_ssl_server_cert: "{{ dynamic_data_store }}/{{ groups['sensu_masters'][0] }}/{{ sensu_config_path }}/ssl_generation/sensu_ssl_tool/server/cert.pem"
-sensu_ssl_server_key: "{{ dynamic_data_store }}/{{ groups['sensu_masters'][0] }}/{{ sensu_config_path }}/ssl_generation/sensu_ssl_tool/server/key.pem"
+sensu_master_config_path: "{{ hostvars[groups['sensu_masters'][0]]['sensu_config_path'] | default('/etc/sensu') }}"
+sensu_ssl_tool_base_path: "{{ dynamic_data_store }}/{{ groups['sensu_masters'][0] }}{{ sensu_master_config_path }}/ssl_generation/sensu_ssl_tool"
+sensu_ssl_client_cert: "{{ sensu_ssl_tool_base_path }}/client/cert.pem"
+sensu_ssl_client_key: "{{ sensu_ssl_tool_base_path }}/client/key.pem"
+sensu_ssl_server_cacert: "{{ sensu_ssl_tool_base_path }}/sensu_ca/cacert.pem"
+sensu_ssl_server_cert: "{{ sensu_ssl_tool_base_path }}/server/cert.pem"
+sensu_ssl_server_key: "{{ sensu_ssl_tool_base_path }}/server/key.pem"
 ```
 
 ### [Uchiwa Properties](http://docs.uchiwa.io/en/latest/)
@@ -170,6 +172,21 @@ sensu_ssl_server_key: "{{ dynamic_data_store }}/{{ groups['sensu_masters'][0] }}
 |--------------------|---------------|------------------------------|
 | `sensu_config_path` | `/opt/local/etc/sensu` | Path to the Sensu configuration directory |
 
+## FreeBSD
+### [Sensu Properties](https://sensuapp.org/docs/0.21/install-sensu)
+| Name               | Default Value | Description                  |
+|--------------------|---------------|------------------------------|
+| `sensu_config_path` | `/usr/local/etc/sensu` | Path to the Sensu configuration directory |
+| `sensu_pkg_version` | `0.23.0_1` | Version of Sensu to download and install |
+| `sensu_pkg_download_url` | `http://core.sensuapp.com/freebsd-unstable/10.0/amd64/sensu-{{ sensu_pkg_version }}.txz` | URL to download Sensu from |
+| `sensu_pkg_download_path` | `/root/sensu_latest.txz` | Path to store package file to |
+
+### [RabbitMQ Server Properties](https://sensuapp.org/docs/0.21/rabbitmq)
+| Name               | Default Value | Description                  |
+|--------------------|---------------|------------------------------|
+| `rabbitmq_service_name` | `rabbitmq` | The name of the RabbitMQ service |
+| `rabbitmq_config_path` | `/usr/local/etc/rabbitmq` | Path to the RabbitMQ configuration directory |
+
 ## Example Playbook
 
 ``` yaml

+ 11 - 5
defaults/main.yml

@@ -46,11 +46,13 @@ sensu_remote_plugins: ~
 
 # Sensu/RabbitMQ SSL certificate properties
 sensu_ssl_gen_certs: true
-sensu_ssl_client_cert: "{{ dynamic_data_store }}/{{ groups['sensu_masters'][0] }}/{{ sensu_config_path }}/ssl_generation/sensu_ssl_tool/client/cert.pem"
-sensu_ssl_client_key: "{{ dynamic_data_store }}/{{ groups['sensu_masters'][0] }}/{{ sensu_config_path }}/ssl_generation/sensu_ssl_tool/client/key.pem"
-sensu_ssl_server_cacert: "{{ dynamic_data_store }}/{{ groups['sensu_masters'][0] }}/{{ sensu_config_path }}/ssl_generation/sensu_ssl_tool/sensu_ca/cacert.pem"
-sensu_ssl_server_cert: "{{ dynamic_data_store }}/{{ groups['sensu_masters'][0] }}/{{ sensu_config_path }}/ssl_generation/sensu_ssl_tool/server/cert.pem"
-sensu_ssl_server_key: "{{ dynamic_data_store }}/{{ groups['sensu_masters'][0] }}/{{ sensu_config_path }}/ssl_generation/sensu_ssl_tool/server/key.pem"
+sensu_master_config_path: "{{ hostvars[groups['sensu_masters'][0]]['sensu_config_path'] | default('/etc/sensu') }}"
+sensu_ssl_tool_base_path: "{{ dynamic_data_store }}/{{ groups['sensu_masters'][0] }}{{ sensu_master_config_path }}/ssl_generation/sensu_ssl_tool"
+sensu_ssl_client_cert: "{{ sensu_ssl_tool_base_path }}/client/cert.pem"
+sensu_ssl_client_key: "{{ sensu_ssl_tool_base_path }}/client/key.pem"
+sensu_ssl_server_cacert: "{{ sensu_ssl_tool_base_path }}/sensu_ca/cacert.pem"
+sensu_ssl_server_cert: "{{ sensu_ssl_tool_base_path }}/server/cert.pem"
+sensu_ssl_server_key: "{{ sensu_ssl_tool_base_path }}/server/key.pem"
   
 # Uchiwa properties
 uchiwa_dc_name: ~
@@ -64,3 +66,7 @@ uchiwa_pkg_download_sha256sum: ~
 uchiwa_pkg_download_path: ~
 uchiwa_pkg_version: ~
 uchiwa_pkg_download_url: ~
+
+# Internal settings
+__bash_path: /bin/bash
+__root_group: root

+ 0 - 1
docs/afewwords.md

@@ -17,7 +17,6 @@ It's planned!
 Coming in the near future:
 
 - OpenBSD
-- FreeBSD
 - NetBSD
 
 I'd be happy to add any others to the list if high demand shows.

+ 1 - 1
docs/index.md

@@ -21,11 +21,11 @@ This role requires Ansible 2.0
 - [CentOS - 7](https://wiki.centos.org/Manuals/ReleaseNotes/CentOS7)
 - [Debian - 8 (Jessie)](https://wiki.debian.org/DebianJessie)
 - [Ubuntu - 15.04 (Vivid Vervet)](http://releases.ubuntu.com/15.04/)
+- [FreeBSD - 10.2](https://www.freebsd.org/releases/10.2R/relnotes.html)
 
 ### Future Releases
 
 - OpenBSD
-- FreeBSD
 - NetBSD
 
 ## Role Variables

+ 15 - 0
docs/role_variables.md

@@ -134,3 +134,18 @@ sensu_ssl_server_key: "{{ dynamic_data_store }}/{{ groups['sensu_masters'][0] }}
 | Name               | Default Value | Description                  |
 |--------------------|---------------|------------------------------|
 | `sensu_config_path` | `/opt/local/etc/sensu` | Path to the Sensu configuration directory |
+
+## FreeBSD
+### [Sensu Properties](https://sensuapp.org/docs/0.21/install-sensu)
+| Name               | Default Value | Description                  |
+|--------------------|---------------|------------------------------|
+| `sensu_config_path` | `/usr/local/etc/sensu` | Path to the Sensu configuration directory |
+| `sensu_pkg_version` | `0.23.0_1` | Version of Sensu to download and install |
+| `sensu_pkg_download_url` | `http://core.sensuapp.com/freebsd-unstable/10.0/amd64/sensu-{{ sensu_pkg_version }}.txz` | URL to download Sensu from |
+| `sensu_pkg_download_path` | `/root/sensu_latest.txz` | Path to store package file to |
+
+### [RabbitMQ Server Properties](https://sensuapp.org/docs/0.21/rabbitmq)
+| Name               | Default Value | Description                  |
+|--------------------|---------------|------------------------------|
+| `rabbitmq_service_name` | `rabbitmq` | The name of the RabbitMQ service |
+| `rabbitmq_config_path` | `/usr/local/etc/rabbitmq` | Path to the RabbitMQ configuration directory |

+ 3 - 3
meta/main.yml

@@ -58,12 +58,12 @@ galaxy_info:
   #  versions:
   #  - all
   #  - any
-  #- name: FreeBSD
-  #  versions:
+  - name: FreeBSD
+    versions:
   #  - all
   #  - 10.0
   #  - 10.1
-  #  - 10.2
+    - 10.2
   #  - 8.0
   #  - 8.1
   #  - 8.2

+ 74 - 0
tasks/FreeBSD/dashboard.yml

@@ -0,0 +1,74 @@
+---
+# tasks/FreeBSD/dashboard.yml: Deployment of the Uchiwa dashboard
+# Specific to FreeBSD
+
+  - include_vars: "{{ ansible_distribution }}.yml"
+
+  - name: Ensure Uchiwa (dashboard) dependencies are installed
+    pkgng:
+      name: "{{ item }}"
+      state: present
+    with_items:
+      - go
+      - git
+      - npm
+
+  - name: Ensure Uchiwa directory exists
+    file:
+      dest: "{{ uchiwa_path }}"
+      state: directory
+      owner: "{{ sensu_user_name }}"
+      group: "{{ sensu_group_name }}"
+      recurse: true
+
+  - name: Ensure Uchiwa Go/config directory exists
+    file:
+      dest: "{{ uchiwa_path }}/{{ item }}"
+      state: directory
+      owner: "{{ sensu_user_name }}"
+      group: "{{ sensu_group_name }}"
+      recurse: true
+    with_items:
+      - etc
+      - go
+
+  - name: Ensure Uchiwa GOPATH exists
+    file:
+      dest: "{{ uchiwa_path }}/go/{{ item }}"
+      owner: "{{ sensu_user_name }}"
+      group: "{{ sensu_group_name }}"
+      state: directory
+      recurse: true
+    with_items:
+      - bin
+      - pkg
+      - src
+
+  - name: Fetch Uchiwa from GitHub
+    command: go get github.com/sensu/uchiwa
+    environment:
+      GOPATH: "{{ uchiwa_path }}/go"
+    args:
+      creates: "{{ uchiwa_path }}/go/src/github.com/sensu/uchiwa"
+    notify: Build and deploy Uchiwa
+    become: true
+    become_user: "{{ sensu_user_name }}"
+
+  - meta: flush_handlers
+
+  - name: Deploy Uchiwa config
+    template:
+      src: uchiwa_config.json.j2
+      dest: "{{ uchiwa_path }}/etc/config.json"
+      owner: "{{ sensu_user_name }}"
+      group: "{{ sensu_group_name }}"
+    notify: restart uchiwa service
+
+  - name: Deploy Uchiwa service file
+    template:
+      src: uchiwa_freebsd.j2
+      dest: "/usr/local/etc/rc.d/uchiwa"
+      mode: "0755"
+
+  - name: Ensure Uchiwa server service is running
+    service: name=uchiwa state=started enabled=yes

+ 43 - 0
tasks/FreeBSD/main.yml

@@ -0,0 +1,43 @@
+---
+# tasks/FreeBSD/main.yml: FreeBSD specific set-up
+# This takes care of base prerequisites for FreeBSD
+
+  - include_vars: "{{ ansible_distribution }}.yml"
+
+  - name: Ensure the Sensu group is present
+    group: name={{ sensu_group_name }} state=present
+
+  - name: Ensure the Sensu user is present
+    user:
+      name: "{{ sensu_user_name }}"
+      group: "{{ sensu_group_name }}"
+      shell: /bin/false
+      home: "{{ sensu_config_path }}"
+      createhome: true
+      state: present
+
+  - name: Install prerequisite packages
+    pkgng:
+      name: "{{ item }}"
+      state: present
+    with_items:
+      - bash
+      - ca_root_nss
+
+  - name: Retrieve the sensu txz package
+    get_url:
+      url: "{{ sensu_pkg_download_url }}"
+      dest: "{{ sensu_pkg_download_path }}"
+    register: sensu_txz
+
+  - name: Install sensu from the retrieved txz package
+    command: "pkg add {{ sensu_pkg_download_path }}"
+    when: sensu_txz|changed
+
+  - name: Ensure the Sensu config directory is present
+    file:
+      dest: "{{ sensu_config_path }}/conf.d"
+      state: directory
+      recurse: true
+      owner: "{{ sensu_user_name }}"
+      group: "{{ sensu_group_name }}"

+ 10 - 0
tasks/FreeBSD/rabbit.yml

@@ -0,0 +1,10 @@
+---
+# tasks/FreeBSD/rabbit.yml: Deploy RabbitMQ
+# Specific to FreeBSD
+
+  - include_vars: "{{ ansible_distribution }}.yml"
+
+  - name: Ensure RabbitMQ is installed
+    pkgng:
+      name: rabbitmq
+      state: "{{ rabbitmq_pkg_state }}"

+ 19 - 0
tasks/FreeBSD/redis.yml

@@ -0,0 +1,19 @@
+---
+# tasks/FreeBSD/redis.yml: Deploy Redis
+# Specific to FreeBSD
+
+  - include_vars: "{{ ansible_distribution }}.yml"
+
+  - name: Ensure Redis is installed
+    pkgng:
+      name: "{{ redis_pkg_name }}"
+      state: "{{ redis_pkg_state }}"
+
+  - name: Ensure Redis binds to accessible IP
+    lineinfile:
+      dest: /usr/local/etc/redis.conf
+      regexp: '^bind'
+      line: 'bind 0.0.0.0'
+    notify: restart redis service
+
+  - meta: flush_handlers

+ 1 - 1
tasks/rabbit.yml

@@ -24,7 +24,7 @@
       dest: "{{ rabbitmq_config_path }}/rabbitmq.config"
       src: "{{ rabbitmq_config_template }}"
       owner: root
-      group: root
+      group: "{{ __root_group }}"
       mode: 644
     notify: restart rabbitmq service
 

+ 2 - 1
tasks/ssl_generate.yml

@@ -33,10 +33,11 @@
         creates: "{{ sensu_config_path }}/ssl_generation/sensu_ssl_tool"
   
     - name: Generate SSL certs
-      shell: ./ssl_certs.sh generate
+      command: "_ {{ sensu_config_path }}/ssl_generation/sensu_ssl_tool/ssl_certs.sh generate"
       args:
         chdir: "{{ sensu_config_path }}/ssl_generation/sensu_ssl_tool"
         creates: "{{ sensu_config_path }}/ssl_generation/sensu_ssl_tool/server"
+        executable: "{{ __bash_path }}"
 
     when: sensu_master|bool
     become: true

+ 27 - 0
templates/uchiwa_freebsd.j2

@@ -0,0 +1,27 @@
+#!/bin/sh
+
+. /etc/rc.subr
+
+name=uchiwa
+rcvar=uchiwa_enable
+
+command="{{ uchiwa_path }}/go/bin/${name}"
+uchiwa_flags="-d {{ uchiwa_path }} -c {{ uchiwa_path }}/etc/config.json -p {{ uchiwa_path }}/go/src/github.com/sensu/uchiwa/public"
+
+load_rc_config $name
+
+pidfile=/var/run/${name}.pid
+start_cmd=uchiwa_start
+stop_postcmd=uchiwa_cleanup
+
+uchiwa_start() {
+  echo "Starting uchiwa."
+  /usr/bin/touch ${pidfile}
+  /usr/sbin/daemon -cf -p ${pidfile} ${command} ${uchiwa_flags}
+}
+
+uchiwa_cleanup() {
+  [ -f ${pidfile} ] && /bin/rm ${pidfile}
+}
+
+run_rc_command "$1"

+ 1 - 1
tests/Vagrantfile

@@ -1,4 +1,4 @@
-vagrantfiles = %w[vms/Vagrantfile.centos7 vms/Vagrantfile.debian8 vms/Vagrantfile.ubuntu15]
+vagrantfiles = %w[vms/Vagrantfile.centos7 vms/Vagrantfile.debian8 vms/Vagrantfile.ubuntu15 vms/Vagrantfile.freebsd10]
 vagrantfiles.each do |vagrantfile|
   load File.expand_path(vagrantfile) if File.exists?(vagrantfile)
 end

+ 53 - 0
tests/vms/Vagrantfile.freebsd10

@@ -0,0 +1,53 @@
+##############
+# FreeBSD 10 #
+##############
+Vagrant.configure(2) do | config |
+  config.ssh.insert_key = false
+  config.ssh.username = 'vagrant'
+  config.ssh.shell = '/bin/sh'
+  config.vm.provider :virtualbox do |vb|
+    vb.customize ["modifyvm", :id, "--memory", "2048"]
+  end
+
+  # Use rsync for shared folder
+  config.vm.synced_folder ".", "/vagrant", type: "rsync", id: "vagrant-root",
+                          rsync__args: ["--verbose", "--rsync-path='sudo rsync'", "--archive", "--delete", "-z"]
+
+  config.vm.define "freebsd10" do |freebsd10|
+    freebsd10.vm.hostname = "freebsd10.dev"
+    freebsd10.vm.box = "freebsd/FreeBSD-10.2-STABLE"
+    freebsd10.vm.base_mac = "72f28c4782fd"
+    freebsd10.vm.network :private_network, ip: "192.168.40.7"
+    freebsd10.vm.network "forwarded_port", guest: 3000, host: 3004
+  end
+
+  # Ansible
+  config.vm.provision "ansible" do |ansible|
+    ansible.groups = {
+      "sensu_masters" => ["freebsd10"],
+      "rabbitmq_servers" => ["freebsd10"],
+      "redis_servers" => ["freebsd10"],
+    }
+
+    ansible.extra_vars = {
+      ansible_python_interpreter: "/usr/local/bin/python2.7",
+      dynamic_data_store: "data/dynamic",
+      rabbitmq_host: "192.168.40.7",
+      rabbitmq_server: true,
+      redis_host: "192.168.40.7",
+      redis_server: true,
+      sensu_api_host: "192.168.40.7",
+      sensu_api_user_name: "admin",
+      sensu_api_password: "admin",
+      sensu_include_plugins: false,
+      sensu_include_dashboard: true,
+      sensu_master: true,
+      uchiwa_dc_name: "vagrant",
+      uchiwa_user_name: "admin",
+      uchiwa_password: "admin",
+    }
+
+    ansible.sudo = true
+    ansible.playbook = "provision.yml"
+  end
+end

+ 17 - 0
vars/FreeBSD.yml

@@ -0,0 +1,17 @@
+---
+# vars/FreeBSD.yml: Variables for FreeBSD
+# Defaults are defined in vars/default.yml
+
+# Sensu config/package properties
+sensu_config_path: /usr/local/etc/sensu
+sensu_pkg_version: 0.23.0_1
+sensu_pkg_download_url: https://core.sensuapp.com/freebsd-unstable/10.0/amd64/sensu-{{ sensu_pkg_version }}.txz
+sensu_pkg_download_path: /root/sensu_latest.txz
+
+# RabbitMQ options
+rabbitmq_config_path: /usr/local/etc/rabbitmq
+rabbitmq_service_name: rabbitmq
+
+# Internal settings
+__bash_path: /usr/local/bin/bash
+__root_group: wheel