From: Andrew Schoen Date: Wed, 7 Mar 2018 15:44:58 +0000 (-0600) Subject: ansible: adds kraken role and example playbook X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=eb2d34b44b131f804d2746a6f36a474486a85a1c;p=ceph-build.git ansible: adds kraken role and example playbook Signed-off-by: Andrew Schoen --- diff --git a/ansible/examples/kraken.yml b/ansible/examples/kraken.yml new file mode 100644 index 00000000..ca3c5f86 --- /dev/null +++ b/ansible/examples/kraken.yml @@ -0,0 +1,83 @@ +--- + +- hosts: kraken + roles: + - kraken + vars: + ansible_ssh_user: "centos" + + # bot specific vars + venv: "{{ helga_home }}/venv" + helga_nick: 'kraken' + helga_irc_host: irc.devel.redhat.com + helga_irc_port: 6667 + helga_use_ssl: false + helga_cmd_prefix: '!' + + helga_irc_channels: + - bogus + + helga_operators: ['alfredodeza', 'ktdreyer', 'andrewschoen'] + helga_default_plugins: + - dubstep + - facts + - help + - manager + - meant_to_say + - oneliner + - operator + - stfu + # custom ones + - norris + - redmine + - yall + - ugrep + - wut + - jenkins + - excuses + - poems + - reminders + - karma + - bugzilla + + helga_external_plugins: + - git+https://github.com/alfredodeza/helga-norris#egg=helga-norris + - git+https://github.com/alfredodeza/helga-yall#egg=helga-yall + - git+https://github.com/alfredodeza/helga-ugrep#egg=helga-ugrep + - git+https://github.com/alfredodeza/helga-wut#egg=helga-wut + - git+https://github.com/alfredodeza/helga-karma#egg=helga-karma + - git+https://github.com/alfredodeza/helga-jenkins#egg=helga-jenkins + - git+https://github.com/alfredodeza/helga-excuses#egg=helga-excuses + + helga_pypi_plugins: + - helga-redmine + - helga-poems + - helga-reminders + - helga-facts + - helga-bugzilla + - helga-pika + + bugzilla_xmlrpc_url: 'https://bugzilla.redhat.com/xmlrpc.cgi' + bugzilla_ticket_url: 'https://bugzilla.redhat.com/%(ticket)s' + + helga_twitter_consumer_key: "key" + helga_twitter_consumer_secret: "consumer_secret" + helga_twitter_oauth_token: "token" + helga_twitter_oauth_token_secret: "token_secret" + helga_twitter_username: "username" + + # needed for helga-pika + rabbitmq_user: "" + rabbitmq_password: "" + rabbitmq_host: "" + rabbitmq_exchange:"" + rabbitmq_routing_keys: [] + + # needed for helga-redmine + redmine_url: '' + # This API key corresponds to the Kraken system account in Ceph's Redmine. + redmine_api_key: '' + + # needed for helga-jenkins + jenkins_url: '' + jenkins_credentials: {} diff --git a/ansible/roles/kraken/defaults/main.yml b/ansible/roles/kraken/defaults/main.yml new file mode 100644 index 00000000..63430622 --- /dev/null +++ b/ansible/roles/kraken/defaults/main.yml @@ -0,0 +1,41 @@ +--- +helga_home: /opt/helga +helga_settings_path: '{{ helga_home }}/bin/settings.d' +helga_nick: helga +helga_irc_host: localhost +helga_irc_port: 6667 +helga_use_ssl: yes +helga_operators: [] +helga_irc_channels: +- "#bots" +helga_timezone: 'UTC' +helga_default_plugins: +- dubstep +- facts +- help +- manager +- meant_to_say +- oneliner +- operator +- poems +- reminders +- stfu + +helga_external_plugins: [] +helga_cmd_prefix: '!' +helga_webhooks_port: 8080 +helga_twitter_api_key: null +helga_twitter_api_secret: null +helga_twitter_oauth_token: null +helga_twitter_oauth_secret: null +helga_twitter_username: null +helga_system_packages: + - python-devel + - git + - python-virtualenv + - mongodb-server + - gcc-c++ + +helga_ssl_requirements: + - openssl + - openssl-devel diff --git a/ansible/roles/kraken/handlers/main.yml b/ansible/roles/kraken/handlers/main.yml new file mode 100644 index 00000000..775d990a --- /dev/null +++ b/ansible/roles/kraken/handlers/main.yml @@ -0,0 +1,6 @@ +--- + +- name: restart helga service + service: + name: helga + status: restarted diff --git a/ansible/roles/kraken/tasks/main.yml b/ansible/roles/kraken/tasks/main.yml new file mode 100644 index 00000000..c3354392 --- /dev/null +++ b/ansible/roles/kraken/tasks/main.yml @@ -0,0 +1,103 @@ +--- + +- name: Create a home for Helga. + become: yes + file: + path: {{ helga_home }} + owner: {{ ansible_ssh_user }} + group: {{ ansible_ssh_user }} + state: directory + recurse: yes + +- name: Install ssl requirements. + become: yes + yum: + name: {{ item }} + state: present + with_items: helga_ssl_requirements + when: helga_use_ssl + +- name: Install GCC + become: yes + yum: + name: gcc + state: present + +- name: Enable EPEL + become: yes + yum: + name: epel-release + state:present + +- name: Retrieve software requirements. + become: yes + yum: + name: {{ item }} + state: present + with_items: "{{ helga_system_packages }}" + +- name: Create a virtualenv with latest pip. + pip: + name: pip + virtualenv: {{ helga_home }} + extra_args: '--upgrade' + +- name: Install Helga. + pip: + name: helga + virtualenv: {{ helga_home }} + +- name: Install Helga unreleased enhancements. + pip: + name: {{ item }} + state: present + extra_args: "-e" + virtualenv: {{ helga_home }} + with_items: "{{ helga_external_plugins }}" + notify: restart helga service + +- name: Install Helga released enhancements. + pip: + name: {{ item }} + state: latest + virtualenv: {{ helga_home }} + with_items: "{{ helga_pypi_plugins }}" + notify: restart helga service + +- name: Create settings directory + file: + path: {{ helga_settings_path }} + state: directory + +- name: Install base personality. + template: + src: custom_settings.j2 + dest: {{ helga_settings_path }}/00_base_settings.py + +- name: Install personality customizations (files). + copy: + src: {{ item }} + dest: {{ helga_settings_path }} +# this one is tricky, because the relative path is relative to +# roles/common/files + with_fileglob: + - helga/settings.d/* + +- name: Custom settings, ASSEMBLE! + assemble: + src: {{ helga_settings_path }}/ + dest: {{ helga_home }}/bin/custom_settings.py + +- name: ensure mongod is running + become: true + service: + name: mongod + state: started + +- name: ensure mongod is set to start at boot (enabled) + become: true + service: + name: mongod + enabled: true + +- include: systemd.yml diff --git a/ansible/roles/kraken/tasks/systemd.yml b/ansible/roles/kraken/tasks/systemd.yml new file mode 100644 index 00000000..83bb0525 --- /dev/null +++ b/ansible/roles/kraken/tasks/systemd.yml @@ -0,0 +1,36 @@ +--- + + +- name: ensure /etc/sysconfig/ dir exists + sudo: true + file: + path: /etc/sysconfig + state: directory + +# prevents issues when updating systemd files +- name: reload systemd + sudo: yes + command: systemctl daemon-reload + +- name: install the systemd configuration file for celery + template: + src: helga.sysconfig.j2 + dest: /etc/sysconfig/helga + sudo: true + notify: + - reload systemd + +- name: install the systemd unit file for helga + template: + src: helga.service.j2 + dest: /etc/systemd/system/helga.service + sudo: true + notify: + - reload systemd + +- name: ensure helga is enabled and running + sudo: true + service: + name: helga + state: running + enabled: yes diff --git a/ansible/roles/kraken/templates/circus.ini.j2 b/ansible/roles/kraken/templates/circus.ini.j2 new file mode 100644 index 00000000..05fd4194 --- /dev/null +++ b/ansible/roles/kraken/templates/circus.ini.j2 @@ -0,0 +1,26 @@ +[watcher:helga] +cmd = {{ helga_home }}/bin/helga + +stdout_stream.class = FileStream +stdout_stream.filename=/var/log/circus/helga-stdout.log + +stderr_stream.class = FileStream +stderr_stream.filename=/var/log/circus/helga-stderr.log + + +[env:helga] +HELGA_SETTINGS=custom_settings + + +[circus] +statsd = 1 +httpd = 1 + +[watcher:webapp] +cmd = {{ helga_home }}/bin/chaussette --fd $(circus.sockets.web) +numprocesses = 3 +use_sockets = True + +[socket:web] +host = 0.0.0.0 +port = 9999 diff --git a/ansible/roles/kraken/templates/custom_settings.j2 b/ansible/roles/kraken/templates/custom_settings.j2 new file mode 100644 index 00000000..e9a6eea5 --- /dev/null +++ b/ansible/roles/kraken/templates/custom_settings.j2 @@ -0,0 +1,60 @@ +NICK = '{{ helga_nick }}' + +SERVER = { + 'HOST': '{{ helga_irc_host }}', + 'PORT': {{ helga_irc_port }}, + 'SSL': {{ helga_use_ssl }}, +} + +CHANNELS = [ + {% for channel in helga_irc_channels %} + ('{{ channel }}',), + {% endfor %} +] + +OPERATORS = [ + {% for operator in helga_operators %} + '{{ operator }}', + {% endfor %} +] + +TIMEZONE = '{{ helga_timezone }}' + +ENABLED_PLUGINS = [ + {% for plugin in helga_default_plugins %} + '{{ plugin }}', + {% endfor %} + {% for plugin in helga_external_plugins %} + '{{ plugin }}', + {% endfor %} +] + +COMMAND_PREFIX_CHAR = '{{ helga_cmd_prefix }}' +WEBHOOKS_PORT = {{ helga_webhooks_port }} + +# Twitter API +TWITTER_CONSUMER_KEY = {{ helga_twitter_api_key }} +TWITTER_CONSUMER_SECRET = {{ helga_twitter_api_secret }} +TWITTER_OAUTH_TOKEN = {{ helga_twitter_oauth_token }} +TWITTER_OAUTH_TOKEN_SECRET = {{ helga_twitter_oauth_secret }} +TWITTER_USERNAME = {{ helga_twitter_username }} + +BUGZILLA_XMLRPC_URL = "{{ bugzilla_xmlrpc_url }}" +BUGZILLA_TICKET_URL = "{{ bugzilla_ticket_url }}" + +FACTS_REQUIRE_NICKNAME = True + +RABBITMQ_USER = "" +RABBITMQ_PASSWORD= "" +RABBITMQ_HOST = "" +RABBITMQ_EXCHANGE= "" + +RABBITMQ_ROUTING_KEYS = [] + +REDMINE_URL = '' +# This API key corresponds to the Kraken system account in Ceph's Redmine. +REDMINE_API_KEY = '' + +JENKINS_URL = '' + +JENKINS_CREDENTIALS = {} diff --git a/ansible/roles/kraken/templates/helga.service.j2 b/ansible/roles/kraken/templates/helga.service.j2 new file mode 100644 index 00000000..edbbabd2 --- /dev/null +++ b/ansible/roles/kraken/templates/helga.service.j2 @@ -0,0 +1,15 @@ +[Unit] +Description=helga (kraken) bot service +After=network.target + +[Service] +Type=simple +ExecStart={{ app_home }}/bin/helga +EnvironmentFile=/etc/sysconfig/helga +User={{ ansible_ssh_user }} +WorkingDirectory={{ app_home }}/src/ +StandardOutput=journal +StandardError=journal + +[Install] +WantedBy=multi-user.target diff --git a/ansible/roles/kraken/templates/helga.sysconfig.j2 b/ansible/roles/kraken/templates/helga.sysconfig.j2 new file mode 100644 index 00000000..9448c950 --- /dev/null +++ b/ansible/roles/kraken/templates/helga.sysconfig.j2 @@ -0,0 +1,2 @@ +HOME=/home/{{ ansible_ssh_user }} +HELGA_SETTINGS=custom_settings