diff --git a/README.md b/README.md index ef15fb74..65d38eb8 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/roles/st2mistral/defaults/main.yml b/roles/st2mistral/defaults/main.yml index 019c47a3..78523c18 100644 --- a/roles/st2mistral/defaults/main.yml +++ b/roles/st2mistral/defaults/main.yml @@ -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 diff --git a/roles/st2mistral/meta/main.yml b/roles/st2mistral/meta/main.yml index 96433144..3ee19d96 100644 --- a/roles/st2mistral/meta/main.yml +++ b/roles/st2mistral/meta/main.yml @@ -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: @@ -16,7 +16,9 @@ galaxy_info: - 6 - 7 categories: - - system + - automation + - devops + - workflows dependencies: - role: postgresql - role: st2repos diff --git a/roles/st2mistral/tasks/main.yml b/roles/st2mistral/tasks/main.yml index 3b008856..9226cf16 100644 --- a/roles/st2mistral/tasks/main.yml +++ b/roles/st2mistral/tasks/main.yml @@ -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 @@ -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 @@ -55,9 +42,29 @@ - restart mistral tags: st2mistral -- name: Setup Mistral DB tables, etc +- name: Make sure "Initiate mistral database" doesn't run twice 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 + 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 @@ -67,7 +74,7 @@ - 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 args: creates: /etc/mistral/mistral-db-manage.populate.ansible.has.run register: register_mistral_actions @@ -75,3 +82,11 @@ 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 diff --git a/roles/st2mistral/templates/init_mistral_db.SQL.j2 b/roles/st2mistral/templates/init_mistral_db.SQL.j2 index 264a151c..54c3aadd 100644 --- a/roles/st2mistral/templates/init_mistral_db.SQL.j2 +++ b/roles/st2mistral/templates/init_mistral_db.SQL.j2 @@ -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 }};