Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rhel support for mistral and create postgresql role (remove AXNS.postgresql dependency) #78

Merged
merged 19 commits into from
Jan 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ provisioner:
name: ansible_playbook
hosts: all
roles_path: roles
requirements_path: roles/mistral/requirements.yml
ansible_verbose: true
ansible_verbosity: 2
# TODO: Make sure Ansible playbooks are idepotent
Expand Down
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Aka IFTTT orchestration for Ops.

## Supported platforms
* Ubuntu Trusty (14.04)
* Ubuntu Xenial (16.04)
* Ubuntu Xenial (16.04)

> If you're using the provided Vagrantfile, note that it uses Xenial by default. Due to some of the changes there, Vagrant 1.9.1 or better is required.

Expand All @@ -19,16 +19,10 @@ At least 2GB of memory and 3.5GB of disk space is required, since StackStorm is

## Installation
```sh
# ansible galaxy roles
ansible-playbook requirements.yml
# stackstorm
ansible-playbook stackstorm.yml
```

## Dependencies
Ansible Galaxy roles used by StackStorm installation:
* [ANXS.postgresql](https://galaxy.ansible.com/list#/roles/512) - PostgreSQL, needed by Mistral

## Variables
Below is the list of variables you can redefine in your playbook to customize st2 deployment:

Expand All @@ -52,15 +46,15 @@ ansible-playbook stackstorm.yml -i 'localhost,' --connection=local
```

> Note that keeping `stable` version is useful to update StackStorm by re-running playbook, since it will reinstall st2 if there is new version available.
This is default behavior. If you don't want updates - consider pinning version-revision numbers.
This is default behavior. If you don't want updates - consider pinning version-revision numbers.

Install specific numeric version of st2 with pinned revision number as well:
```sh
ansible-playbook stackstorm.yml --extra-vars='st2_version=1.4.0 st2_revision=8'
```

## Other Installers
You might be interested in other methods to deploy StackStorm engine:
You might be interested in other methods to deploy StackStorm engine:
* Configuration Management
* [Chef Cookbook](https://github.com/StackStorm/chef-stackstorm/)
* [Puppet Module](https://github.com/stackstorm/puppet-st2)
Expand Down
3 changes: 0 additions & 3 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
inline: "sudo yum -y install epel-release; sudo yum -y install ansible git"
end

vm_config.vm.provision :ansible do |ansible|
ansible.playbook = "requirements.yml"
end
vm_config.vm.provision :ansible do |ansible|
ansible.playbook = "stackstorm.yml"
end
Expand Down
7 changes: 0 additions & 7 deletions requirements.yml

This file was deleted.

26 changes: 0 additions & 26 deletions roles/mistral/meta/main.yml

This file was deleted.

3 changes: 0 additions & 3 deletions roles/mistral/requirements.yml

This file was deleted.

19 changes: 19 additions & 0 deletions roles/postgresql/meta/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
galaxy_info:
description: Install PostgreSQL
author: humblearner
company: StackStorm
license: Apache
min_ansible_version: 2.2
tags: [db, postgresql]
platforms:
- name: Ubuntu
versions:
- trusty
- xenial
- name: EL
versions:
- 6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

versions: is missing

- 7
categories:
- system
11 changes: 11 additions & 0 deletions roles/postgresql/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
- name: Install PostgreSQL on {{ ansible_distribution }}-{{ ansible_distribution_major_version }}
include: roles/postgresql/tasks/postgresql_{{ ansible_pkg_mgr }}{{ ansible_distribution_major_version }}.yml
tags: [db, postgresql]
when: ansible_os_family == "RedHat"

- name: Install PostgreSQL on {{ ansible_distribution }}-{{ ansible_distribution_major_version }}
include: roles/postgresql/tasks/postgresql_{{ ansible_pkg_mgr }}.yml
tags: [db, postgresql]
when: ansible_os_family == "Debian"

15 changes: 15 additions & 0 deletions roles/postgresql/tasks/postgresql_apt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
- name: apt | Install PostgreSQL
become: yes
apt:
name: postgresql
state: installed
tags: [db, postgresql]

- name: apt | Start and Enable PostgreSQL
become: yes
service:
name: postgresql
state: started
enabled: yes
tags: [db, postgresql]
66 changes: 66 additions & 0 deletions roles/postgresql/tasks/postgresql_yum6.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
- name: yum | Setup PostgreSQL repository for {{ ansible_distribution }}
become: yes
yum:
name: https://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-centos94-9.4-3.noarch.rpm
state: installed
when: ansible_distribution == "CentOS"
tags: [db, postgresql]

- name: yum | Setup PostgreSQL repository for {{ ansible_distribution }}
become: yes
yum:
name: https://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-redhat94-9.4-3.noarch.rpm
state: installed
when: ansible_distribution == "RedHat"
tags: [db, postgresql]

- name: yum | Install PostgreSQL dependency
become: yes
yum:
name: libselinux-python
state: installed
tags: [db, postgresql]

- name: yum | Install PostgreSQL-9.4
become: yes
yum:
name: "{{ item }}"
state: installed
with_items:
- postgresql94-server
- postgresql94-contrib
- postgresql94-devel
register: install_postgresql
tags: [db, postgresql]

- name: yum | Initialize PostgreSQL-9.4
become: yes
command: service postgresql-9.4 initdb
when: install_postgresql.changed
tags: [db, postgresql]
Copy link
Member

@arm4b arm4b Jan 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, this command needs a "file lock" to ensure that we run initdb only once per system and don't repeat it.

OR even better, - it's possible to run init only when previous block "changed", eg. only when package was installed.

See: https://raymii.org/s/tutorials/Ansible_-_Only-do-something-if-another-action-changed.html


- name: yum | MD5-encrypted password for PostgreSQL 1
become: yes
replace:
dest: /var/lib/pgsql/9.4/data/pg_hba.conf
regexp: ^(host.*all.*all.*127.0.0.1\/32.*)ident$
replace: \1md5
tags: [db, postgresql]

- name: yum | MD5-encrypted password for PostgreSQL 2
become: yes
replace:
dest: /var/lib/pgsql/9.4/data/pg_hba.conf
regexp: ^(host.*all.*all.*::1\/128.*)ident$
replace: \1md5
tags: [db, postgresql]

- name: yum | Start and Enable PostgreSQL-9.4
become: yes
service:
name: postgresql-9.4
state: started
enabled: yes
tags: [db, postgresql]

42 changes: 42 additions & 0 deletions roles/postgresql/tasks/postgresql_yum7.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
- name: yum | Install PostgreSQL
become: yes
yum:
name: "{{ item }}"
state: installed
with_items:
- postgresql-server
- postgresql-contrib
- postgresql-devel
register: install_postgresql
tags: [db, postgresql]

- name: yum | Initialize PostgreSQL
become: yes
command: postgresql-setup initdb
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This command needs idempotence, maybe creates some lock file, don't know what else we can do.

Copy link
Member

@arm4b arm4b Jan 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See another comment: https://github.com/StackStorm/ansible-st2/pull/78/files#r95995753 about executing an command only when another action is changed

when: install_postgresql.changed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice indeed 👍

tags: [db, postgresql]

- name: yum | MD5-encrypted password for PostgreSQL 1
become: yes
replace:
dest: /var/lib/pgsql/data/pg_hba.conf
regexp: ^(host.*all.*all.*127.0.0.1\/32.*)ident$
replace: \1md5
tags: [db, postgresql]

- name: yum | MD5-encrypted password for PostgreSQL 2
become: yes
replace:
dest: /var/lib/pgsql/data/pg_hba.conf
regexp: ^(host.*all.*all.*::1\/128.*)ident$
replace: \1md5
tags: [db, postgresql]

- name: yum | Start and Enable PostgreSQL
become: yes
service:
name: postgresql
state: started
enabled: yes
tags: [db, postgresql]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional "enable" action is missing

File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions roles/st2mistral/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
galaxy_info:
description: Install custom OpenStack Mistral, patched by StackStorm
author: armab
company: StackStorm
license: Apache
min_ansible_version: 2.2
tags: st2mistral
platforms:
- name: Ubuntu
versions:
- trusty
- xenial
- name: EL
versions:
- 6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

versions: is missing

- 7
categories:
- system
dependencies:
- role: postgresql
- role: st2repos
37 changes: 31 additions & 6 deletions roles/mistral/tasks/main.yml → roles/st2mistral/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
---
- name: Install st2mistral dependency
become: yes
package:
name: st2python
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch 👍
I assume that's the case why mistral didn't work for you.

We install st2python as package dependency for st2, see: https://github.com/StackStorm/st2-packages/blob/a46cc2267ac4b23c8f21a3471824c7c7f430cd1a/packages/st2/rpm/st2.spec#L15

Seems like we should add the same dependency for st2mistral as well in st2-packages.

Copy link
Member

@arm4b arm4b Jan 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created an Issue for that: StackStorm/st2-packages#407 so we won't forget about it and fix the root cause.

Copy link
Contributor Author

@humblearner humblearner Jan 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the bootstrap scripts we install st2 and its dependencies before st2mistral, that is why it was never caught: https://github.com/StackStorm/st2-packages/blob/master/scripts/st2bootstrap-el6.sh#L653. However, we may not have another use case, besides this and docker, where anyone installs st2mistral before st2.

state: present
when: (ansible_distribution == "CentOS" or ansible_distribution == "RedHat") and ansible_distribution_major_version == "6"
tags: st2mistral

- name: Install latest st2mistral
become: yes
apt:
package:
name: st2mistral
state: latest
when: mistral_version == "stable"
tags: st2mistral

- name: Install latest st2mistral
become: yes
apt:
package:
name: st2mistral={{ mistral_version }}
state: present
when: mistral_version != "stable"
tags: st2mistral

- name: Configure mistral
become: yes
Expand All @@ -22,56 +31,72 @@
option: connection
value: postgresql://{{ mistral_db_username }}:{{ mistral_db_password }}@localhost/{{ mistral_db }}
backup: yes
tags: st2mistral

- name: Deploy database init script
become: yes
template:
src: init_mistral_db.SQL.j2
dest: /etc/mistral/init_mistral_db.SQL
notify:
dest: /etc/mistral/init_mistral_db.SQL
register: mistral_deploy_database_init_script
notify:
- restart mistral
tags: st2mistral

- name: Initiate database
vars:
ansible_ssh_pipelining: true
become: yes
become_user: postgres
shell: psql < /etc/mistral/init_mistral_db.SQL
args:
args:
creates: /etc/mistral/init_mistral_db.SQL.ansible.has.run
register: mistral_initiate_database
notify:
- restart mistral
tags: st2mistral

- name: Make sure "Initiate database" doesn't run twice
become: yes
file:
path: /etc/mistral/init_mistral_db.SQL.ansible.has.run
state: touch
when: mistral_initiate_database.changed
tags: st2mistral

- name: Setup Mistral DB tables, etc
become: yes
command: /opt/stackstorm/mistral/bin/mistral-db-manage --config-file /etc/mistral/mistral.conf upgrade head
args:
creates: /etc/mistral/mistral-db-manage.upgrade.head.ansible.has.run
notify:
register: setup_mistral_DB_tables
notify:
- restart mistral
tags: st2mistral

- name: Make sure "Setup Mistral DB tables, etc" does not run again
become: yes
file:
path: /etc/mistral/mistral-db-manage.upgrade.head.ansible.has.run
state: touch
when: setup_mistral_DB_tables.changed
tags: st2mistral

- name: Register mistral actions
become: yes
command: /opt/stackstorm/mistral/bin/mistral-db-manage --config-file /etc/mistral/mistral.conf populate
args:
creates: /etc/mistral/mistral-db-manage.populate.ansible.has.run
register: register_mistral_actions
when: mistral_deploy_database_init_script.changed or mistral_initiate_database.changed or setup_mistral_DB_tables.changed
notify:
- restart mistral
tags: st2mistral

- name: Make sure "Register mistral actions" does not run again
become: yes
file:
path: /etc/mistral/mistral-db-manage.upgrade.head.ansible.has.run
state: touch
when: register_mistral_actions.changed
tags: st2mistral
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
CREATE ROLE {{ mistral_db_username }} WITH CREATEDB LOGIN ENCRYPTED PASSWORD {{ mistral_db_password }};
CREATE ROLE {{ mistral_db_username }} WITH CREATEDB LOGIN ENCRYPTED PASSWORD '{{ mistral_db_password }}';
CREATE DATABASE {{ mistral_db }} OWNER {{ mistral_db_username }};
Loading