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

Rename st2mistral vars & Misc cosmetic improvements #94

Merged
merged 15 commits into from
Jan 23, 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
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ ansible-playbook stackstorm.yml
## Variables
Below is the list of variables you can redefine in your playbook to customize st2 deployment:

| Variable | Default | Description |
| --------------------- | ------------- | ------------ |
| Variable | Default | Description |
| ------------------------ | ------------- | ------------ |
| **st2repo**
| `st2_pkg_repo` | `stable` | StackStorm PackageCloud repository to install. [`stable`](https://packagecloud.io/StackStorm/stable/), [`unstable`](https://packagecloud.io/StackStorm/unstable/), [`staging-stable`](https://packagecloud.io/StackStorm/staging-stable/), [`staging-unstable`](https://packagecloud.io/StackStorm/staging-unstable/)
| `st2_pkg_repo` | `stable` | StackStorm PackageCloud repository to install. [`stable`](https://packagecloud.io/StackStorm/stable/), [`unstable`](https://packagecloud.io/StackStorm/unstable/), [`staging-stable`](https://packagecloud.io/StackStorm/staging-stable/), [`staging-unstable`](https://packagecloud.io/StackStorm/staging-unstable/)
| **st2**
| `st2_version` | `latest` | StackStorm version to install. Use latest `latest` to get automatic updates or pin it to numeric version like `2.1.1`.
| `st2_revision` | `1` | StackStorm revision to install. Used only with pinned `st2_version`.
| `st2_system_user` | `stanley` | System user from which st2 will execute local/remote shell actions.
| `st2_version` | `latest` | StackStorm version to install. Use latest `latest` to get automatic updates or pin it to numeric version like `2.1.1`.
| `st2_revision` | `1` | StackStorm revision to install. Used only with pinned `st2_version`.
| `st2_system_user` | `stanley` | System user from which st2 will execute local/remote shell actions.
| `st2_system_user_in_sudoers` | `yes`| Add `st2_system_user` to the sudoers (recommended for most `st2` features to work).
| `st2_ssh_key_file` | `/home/{{st2_system_user}}/.ssh/{{st2_system_user}}_rsa` | Path to `st2_system_user` SSH private key. It will be autogenerated by default.
| `st2_auth_enable` | `yes` | Enable StackStorm standalone authentication.
| `st2_auth_username` | `testu` | Username used by StackStorm standalone authentication.
| `st2_auth_password` | `testp` | Password used by StackStorm standalone authentication.
| `st2_ssh_key_file` | `/home/{{st2_system_user}}/.ssh/{{st2_system_user}}_rsa` | Path to `st2_system_user` SSH private key. It will be autogenerated by default.
| `st2_auth_enable` | `yes` | Enable StackStorm standalone authentication.
| `st2_auth_username` | `testu` | Username used by StackStorm standalone authentication.
| `st2_auth_password` | `testp` | Password used by StackStorm standalone authentication.
| **st2mistral**
| `mistral_version` | `latest` | st2mistral version to install. Use latest `latest` to get automatic updates or pin it to numeric version like `2.1.1`.
| `mistral_db` | `mistral` | PostgreSQL DB name for Mistral.
| `mistral_db_username` | `mistral` | PostgreSQL DB user for Mistral.
| `mistral_db_password` | `StackStorm` | PostgreSQL DB password for Mistral.
| `st2mistral_version` | `latest` | st2mistral version to install. Use latest `latest` to get automatic updates or pin it to numeric version like `2.1.1`.
| `st2mistral_db` | `mistral` | PostgreSQL DB name for Mistral.
| `st2mistral_db_username` | `mistral` | PostgreSQL DB user for Mistral.
| `st2mistral_db_password` | `StackStorm` | PostgreSQL DB password for Mistral.

## Examples
Install latest `stable` StackStorm with all its components on local machine:
Expand Down
12 changes: 8 additions & 4 deletions roles/st2mistral/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
mistral_version: latest
mistral_db_username: mistral
mistral_db_password: StackStorm
mistral_db: mistral
# st2mistral version to install. Use latest `latest` to get automatic updates or pin it to numeric version like `2.1.1`
st2mistral_version: latest
# PostgreSQL DB name for Mistral.
st2mistral_db: mistral
# PostgreSQL DB user for Mistral.
st2mistral_db_username: mistral
# PostgreSQL DB password for Mistral.
st2mistral_db_password: StackStorm
6 changes: 4 additions & 2 deletions roles/st2mistral/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ galaxy_info:
description: Install custom OpenStack Mistral, patched by StackStorm
author: armab
company: StackStorm
license: Apache
license: Apache 2.0
min_ansible_version: 2.2
tags: st2mistral
platforms:
Expand All @@ -16,7 +16,9 @@ galaxy_info:
- 6
- 7
categories:
- system
- automation
- devops
- workflows
dependencies:
- role: postgresql
- role: st2repos
63 changes: 39 additions & 24 deletions roles/st2mistral/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,26 @@
---

- name: Install st2mistral dependency
- name: Install st2python dependency for EL6
become: yes
package:
name: st2python
state: present
when: (ansible_distribution == "CentOS" or ansible_distribution == "RedHat") and ansible_distribution_major_version == "6"
when: ansible_os_family == "RedHat" and ansible_distribution_major_version == "6"
tags: st2mistral

- name: Install latest st2mistral
- name: Install latest st2mistral package
become: yes
package:
name: st2mistral
state: latest
when: mistral_version == "latest"
when: st2mistral_version == "latest"
tags: [st2mistral, skip_ansible_lint]

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

- name: Configure mistral
become: yes
ini_file:
dest: /etc/mistral/mistral.conf
section: database
option: connection
value: postgresql://{{ mistral_db_username }}:{{ mistral_db_password }}@localhost/{{ mistral_db }}
backup: yes
when: st2mistral_version != "latest"
tags: st2mistral

- name: Deploy database init script
Expand All @@ -40,11 +29,9 @@
src: init_mistral_db.SQL.j2
dest: /etc/mistral/init_mistral_db.SQL
register: mistral_deploy_database_init_script
notify:
- restart mistral
tags: st2mistral

- name: Initiate database
- name: Initiate mistral database
become: yes
become_user: postgres
shell: psql < /etc/mistral/init_mistral_db.SQL
Copy link
Member Author

@arm4b arm4b Jan 23, 2017

Choose a reason for hiding this comment

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

Here we have a problem when user will consider to change any of st2mistral_ database settings in future, - the SQL script will not run twice. That means, new DB is not created.

We can workaround with additional lock files, but #95 should solve it in a right way.

Expand All @@ -55,9 +42,29 @@
- restart mistral
tags: st2mistral

- name: Setup Mistral DB tables, etc
- name: Make sure "Initiate mistral database" doesn't run twice
Copy link
Member

Choose a reason for hiding this comment

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

You're creating the file here, but I don't see where you're checking for the presence of the file in the previous task (i.e. no when clause)

Copy link
Member Author

@arm4b arm4b Jan 23, 2017

Choose a reason for hiding this comment

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

See: creates: /etc/mistral/init_mistral_db.SQL.ansible.has.run in previous task.
If file from the creates exists, - the command won't be executed.

See: http://docs.ansible.com/ansible/shell_module.html for more info.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, okay I get it now.

become: yes
shell: /opt/stackstorm/mistral/bin/mistral-db-manage --config-file /etc/mistral/mistral.conf upgrade head && touch /etc/mistral/init_mistral_db.SQL.ansible.has.run
file:
path: /etc/mistral/init_mistral_db.SQL.ansible.has.run
state: touch
when: mistral_initiate_database.changed
tags: st2mistral, skip_ansible_lint

- name: Configure mistral
become: yes
ini_file:
dest: /etc/mistral/mistral.conf
section: database
option: connection
value: postgresql://{{ st2mistral_db_username }}:{{ st2mistral_db_password }}@localhost/{{ st2mistral_db }}
backup: yes
notify:
- restart mistral
tags: st2mistral

- name: Setup mistral DB tables, etc
Copy link
Member

Choose a reason for hiding this comment

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

Same as above - don't currently see how this is idempotent, since there is no when clause

Copy link
Member Author

Choose a reason for hiding this comment

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

become: yes
shell: /opt/stackstorm/mistral/bin/mistral-db-manage --config-file /etc/mistral/mistral.conf upgrade head && touch /etc/mistral/mistral-db-manage.upgrade.head.ansible.has.run
args:
creates: /etc/mistral/mistral-db-manage.upgrade.head.ansible.has.run
register: setup_mistral_DB_tables
Expand All @@ -67,11 +74,19 @@

- name: Register mistral actions
become: yes
shell: /opt/stackstorm/mistral/bin/mistral-db-manage --config-file /etc/mistral/mistral.conf populate && touch /etc/mistral/mistral-db-manage.upgrade.head.ansible.has.run
shell: /opt/stackstorm/mistral/bin/mistral-db-manage --config-file /etc/mistral/mistral.conf populate && touch /etc/mistral/mistral-db-manage.populate.ansible.has.run
Copy link
Member

Choose a reason for hiding this comment

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

same

Copy link
Member Author

@arm4b arm4b Jan 23, 2017

Choose a reason for hiding this comment

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

We touch the file first, find: && touch /etc/mistral/mistral-db-manage.populate.ansible.has.run
and later in block don't execute it if touch exists:

creates: /etc/mistral/mistral-db-manage.populate.ansible.has.run

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, skip_ansible_lint

- name: Ensure mistral service is enabled and running
become: yes
service:
name: mistral
enabled: yes
state: started
tags: st2mistral
4 changes: 2 additions & 2 deletions roles/st2mistral/templates/init_mistral_db.SQL.j2
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 DATABASE {{ mistral_db }} OWNER {{ mistral_db_username }};
CREATE ROLE {{ st2mistral_db_username }} WITH CREATEDB LOGIN ENCRYPTED PASSWORD '{{ st2mistral_db_password }}';
CREATE DATABASE {{ st2mistral_db }} OWNER {{ st2mistral_db_username }};