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

Setup BWC repos, Install BWC and Setup RBAC #126

Merged
merged 40 commits into from
Mar 22, 2017
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
ab143a0
Initial commit
Mar 7, 2017
6d05514
First round of fixes after U16 testing
Mar 8, 2017
dca13a3
Remove Debug for GPG_URL
Mar 8, 2017
3098871
Fixes based on centos7 testing
Mar 8, 2017
b850d58
Fix typo in variable name
Mar 9, 2017
c287cc3
Remove support for user supplied RBAC roles&assignments
Mar 9, 2017
b3772fc
Let's support roles and assignments via dicts
Mar 9, 2017
8548acc
Rename files -> templates
Mar 9, 2017
a09cb88
use to_nice_yaml
Mar 9, 2017
ac4cd06
use yaml as file ext and not yml
Mar 9, 2017
69fd550
Move back RBAC to same role as BWC
Mar 10, 2017
1aa9d35
Remove separate RBAC role
Mar 10, 2017
ea34e3c
Coalesce bwc_repos into bwc
Mar 10, 2017
22f86a1
Fixes after testing
Mar 10, 2017
1c1ebd0
Fix variable names
Mar 10, 2017
bd198f2
Fix st2.conf file path
Mar 10, 2017
17d7045
@ me baby one more time
Mar 11, 2017
aaccdab
Setup CI
Mar 11, 2017
18da115
Lint fix
Mar 11, 2017
a5f2478
Variable name goofups (fix)
Mar 13, 2017
b7d84e7
Merge branch 'master' into bwc_install_role
Mar 13, 2017
a343cd6
Address review comments
Mar 13, 2017
6ff9e0b
Address code review comments
Mar 14, 2017
e1977f0
Fix README
Mar 14, 2017
5318182
Use no_log to hide tokens
Mar 14, 2017
9a5dee6
Use to_nice_json as opposed to to_nice_yaml
Mar 14, 2017
df65ee2
Setup default RBAC roles and assignments always
Mar 14, 2017
2fd65e8
YAML cleanup
Mar 14, 2017
56d0587
Fix 'no_logs' -> 'no_log' blocking the Ansible run
Mar 15, 2017
c1d98a9
Fix 'st2web' vs 'bwc-ui' conflict when enterprise is installed
Mar 15, 2017
8837fff
Fix st2web yaml
Mar 15, 2017
48dcd6b
Remove all safety checks because arma says so
Mar 16, 2017
b4843f3
Use to_nice_yaml
Mar 16, 2017
76084dd
Add smoke tests for BWC RBAC
Mar 16, 2017
15ac7e6
Add bwc_smoketests to stackstorm.yml
Mar 16, 2017
9891ed2
lets see if this makes ansible-lint happy
Mar 16, 2017
9b5ff73
Smoke tests need not be idempotent
Mar 20, 2017
a729179
Use hash to save license info and handle when license changed
Mar 21, 2017
51ff517
Use hash as opposed to password_hash
Mar 21, 2017
7baa909
Merge branch 'master' into bwc_install_role
Mar 22, 2017
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
3 changes: 3 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ provisioner:
idempotency_test: true
extra_vars:
st2_pkg_repo: <%= ENV['ST2_REPO'] || 'stable' %>
bwc_pkg_repo: <%= ENV['BWC_REPO'] || 'enterprise' %>
license_var: <%= ENV['LICENSE'] %>
bwc_license: <%= ENV[ENV['LICENSE']] || ENV['BWC_LICENSE_ENTERPRISE'] %>

platforms:
# Ubuntu Trusty with Upstart
Expand Down
16 changes: 8 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ branches:

env:
# default is stable repo
- DISTRO=ubuntu-14
- DISTRO=ubuntu-16
- DISTRO=centos-6
- DISTRO=centos-7
- DISTRO=ubuntu-14 LICENSE='BWC_LICENSE_ENTERPRISE'
- DISTRO=ubuntu-16 LICENSE='BWC_LICENSE_ENTERPRISE'
- DISTRO=centos-6 LICENSE='BWC_LICENSE_ENTERPRISE'
- DISTRO=centos-7 LICENSE='BWC_LICENSE_ENTERPRISE'

# StackStorm 'unstable' repo check
- DISTRO=ubuntu-14 ST2_REPO=unstable
- DISTRO=ubuntu-16 ST2_REPO=unstable
- DISTRO=centos-6 ST2_REPO=unstable
- DISTRO=centos-7 ST2_REPO=unstable
- DISTRO=ubuntu-14 ST2_REPO=unstable BWC_REPO=enterprise-unstable LICENSE='BWC_LICENSE_ENTERPRISE_UNSTABLE'
- DISTRO=ubuntu-16 ST2_REPO=unstable BWC_REPO=enterprise-unstable LICENSE='BWC_LICENSE_ENTERPRISE_UNSTABLE'
- DISTRO=centos-6 ST2_REPO=unstable BWC_REPO=enterprise-unstable LICENSE='BWC_LICENSE_ENTERPRISE_UNSTABLE'
- DISTRO=centos-7 ST2_REPO=unstable BWC_REPO=enterprise-unstable LICENSE='BWC_LICENSE_ENTERPRISE_UNSTABLE'

script:
# run kitchen tests (destroy, create, converge, setup, verify and destroy)
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ Below is the list of variables you can redefine in your playbook to customize st
| `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.
| **bwc**
| `bwc_license` | `null` | BWC license key is required for installing BWC enteprise bits via this ansible role.
| `bwc_pkg_repo` | `enterprise` | BWC PackageCloud repository to install. [`enterprise`](https://packagecloud.io/StackStorm/enterprise/), [`enterprise-unstable`](https://packagecloud.io/StackStorm/enterprise-unstable/), [`staging-enterprise`](https://packagecloud.io/StackStorm/staging-enteprise/), [`staging-enterprise-unstable`](https://packagecloud.io/StackStorm/staging-enterprise-unstable/)
| `bwc_version` | `latest` | BWC enterprise version to install. Use latest `latest` to get automatic updates or pin it to numeric version like `2.1.1`. The version used here should match `st2_version`.
| `bwc_revision` | `1` | BWC enterprise revision to install. Used only with pinned `bwc_version`.
| `bwc_rbac` | [See `bwc_rbac` variable in role defaults](roles/bwc/defaults/main.yml) | BWC RBAC roles and assignments. This is a dictionary with two keys `roles` and `assignments`. `roles` and `assignments` are in turn both arrays. Each element in the array follows the exact YAML schema for [roles](https://bwc-docs.brocade.com/rbac.html#user-permissions) and [assignments](https://bwc-docs.brocade.com/rbac.html#defining-user-role-assignments) defined in BWC documentation.
| `bwc_ldap` | [See `bwc_ldap` variable in role defaults](roles/bwc/defaults/main.yml) | Settings for BWC LDAP authentication backend. `bwc_ldap` is a dictionary and has one item `backend_kwargs`. `backend_kwargs` should be provided as exactly listed in BWC documentation for [LDAP configuration](https://bwc-docs.brocade.com/authentication.html#auth-backends).

## Examples
Install latest `stable` StackStorm with all its components on local machine:
Expand Down
41 changes: 41 additions & 0 deletions roles/bwc/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
# BWC PackageCloud repository to install: enterprise, enterprise-unstable, staging-enterprise, staging-enterprise-unstable.
bwc_pkg_repo: "enterprise"
# 'latest' to get latest version or numeric like '2.1.1'
bwc_version: latest
# used only if 'bwc_version' is numeric
bwc_revision: 1

Copy link
Member

Choose a reason for hiding this comment

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

Please define all vars used in this role with comments, as well as include them in README.md.

# BWC license to install BWC enterprise bits
master_token: "{{ bwc_license }}"

# Specify roles and assignments for BWC RBAC.
# Roles are pushed as YML files to /opt/stackstorm/rbac/roles
# Assignments are pushed as YML files to /opt/stackstorm/rbac/assignments/
# The schema for roles and assignments follow the exact schema definition
# define in https://bwc-docs.brocade.com/rbac.html#defining-roles-and-permission-grants
# and https://bwc-docs.brocade.com/rbac.html#defining-user-role-assignments.

bwc_rbac_default_roles: []

bwc_rbac_default_assignments:
- name: "{{ st2_system_user }}"
roles:
- admin

- name: "{{ st2_auth_username }}"
roles:
- system_admin

bwc_rbac:
roles: "{{ bwc_rbac_default_roles }}"

assignments: "{{ bwc_rbac_default_assignments }}"


# By specifying a valid configuration for LDAP,
# (See https://bwc-docs.brocade.com/authentication.html#ldap )
# LDAP auth backend is setup for st2 and BWC.
# Note that you just need to provide the backend_kwargs.
bwc_ldap:
backend_kwargs: {}
5 changes: 5 additions & 0 deletions roles/bwc/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---

- name: reload bwc_rbac
become: yes
command: st2-apply-rbac-definitions --config-file /etc/st2/st2.conf
27 changes: 27 additions & 0 deletions roles/bwc/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
galaxy_info:
description: Install BWC Entperprise components, setup RBAC and LDAP
author: lakshmi-kannan
company: StackStorm
license: Apache 2.0
min_ansible_version: 2.2
platforms:
- name: Ubuntu
versions:
- trusty
- xenial
- name: EL
versions:
- 6
- 7
categories:
- stackstorm
- BWC
- Brocade Workflow Composer
- repositories
- packagecloud
dependencies:
- role: st2repos
- role: st2
- role: st2web
- role: bwc_repos
32 changes: 32 additions & 0 deletions roles/bwc/tasks/bwc_repos_apt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---

- name: Assert that master_token is specified
fail: msg="License key must be supplied for BWC enterprise installation."
Copy link
Member

Choose a reason for hiding this comment

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

Not needed in this file, since you include that check in previous step bwc_repos_setup.yml

when: bwc_license is not defined

- name: Install prereqs (Debian)
become: yes
apt:
name: "{{ item }}"
state: present
with_items:
- debian-archive-keyring
- apt-transport-https

# This is the exact key as the open source repo but this behavior might change.
- name: Add keys to keyring
become: yes
apt_key:
id: 418A7F2FB0E1E6E7EABF6FE8C2E73424D59097AB
url: https://packagecloud.io/StackStorm/{{ bwc_pkg_repo }}/gpgkey
state: present

- name: "Add packagecloud.io repository: StackStorm/{{ bwc_pkg_repo }}"
become: yes
no_log: yes
apt_repository:
filename: "StackStorm_{{ bwc_pkg_repo }}"
repo: 'deb https://{{ bwc_read_token }}:@packagecloud.io/StackStorm/{{ bwc_pkg_repo }}/{{ ansible_distribution|lower }}/ {{ ansible_distribution_release|lower }} main'
state: present
update_cache: yes
register: added_bwc_deb_repository
42 changes: 42 additions & 0 deletions roles/bwc/tasks/bwc_repos_setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---

- name: Assert that master_token is specified
fail: msg="License key must be supplied for BWC enterprise installation."
when: bwc_license is not defined

- name: Create packagecloud dir
become: yes
file:
path: "/etc/packagecloud"
mode: "u=rwx,g=rx,o=rx"
owner: st2
group: st2
state: directory

- name: Get read token for repo from packagecloud
become: yes
no_log: yes
uri:
url: https://{{ bwc_license }}:@packagecloud.io/install/repositories/StackStorm/{{ bwc_pkg_repo }}/tokens.text
creates: "/etc/packagecloud/StackStorm_{{ bwc_pkg_repo }}_read_token.txt" # Don't download if file already exists
Copy link
Member

Choose a reason for hiding this comment

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

Following our previous case when we rotated {{ bwc_license }}.

What will happen if user changes {{ bwc_license }}? Seems like read token will remain from the old license.

Eg. if user changes the license - Ansible should update apt/yum repository too with new read token.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep. Unfortunately, if I generate a token every time, it would cause idempotency failures. If I do what I did, then installation with fail if they swapped the license. But I think this is fine. It fails out with an error.

Another approach is to ask user for {{ bwc_read_token }} which I am -1 to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like I could force changed_when: no. That sounds hacky to me.

Copy link
Member

@arm4b arm4b Mar 16, 2017

Choose a reason for hiding this comment

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

What we can do is to additionally generate the hash from the {{ bwc_license }} via http://docs.ansible.com/ansible/playbooks_filters.html#hashing-filters and store hash somewhere in file.

If hash changed (eg. user provided new license), - then we request new {{ bwc_read_token }} and update apt/yum repo config.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can address this in a different PR. I am not too keen on adding more scope to this PR.

Copy link
Member

Choose a reason for hiding this comment

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

Deal. Feel free to create an issue for this then so maybe someone else could pick it up.

dest: "/etc/packagecloud/StackStorm_{{ bwc_pkg_repo }}_read_token.txt"
force_basic_auth: yes
method: POST
status_code: 201,200
headers:
Content-Type: "application/x-www-form-urlencoded"
body: "name={{ ansible_nodename }}"

- name: Set bwc_read_token variable
become: yes
no_log: yes
set_fact:
bwc_read_token: "{{ lookup('file', '/etc/packagecloud/StackStorm_{{ bwc_pkg_repo }}_read_token.txt') }}"

- name: Add BWC enterprise repos on {{ ansible_distribution }}
include: bwc_repos_{{ ansible_pkg_mgr }}.yml
tags:
- BWC repos
- StackStorm enterprise
register: bwc_repo_added
when: bwc_read_token != ''
26 changes: 26 additions & 0 deletions roles/bwc/tasks/bwc_repos_yum.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---

# Fixes "Failure talking to yum: Cannot retrieve repository metadata (repomd.xml) for repository: StackStorm_stable. Please verify its path and try again" when installing st2
- name: Update ca-certificates package
become: yes
yum:
name: ca-certificates
state: latest
tags: skip_ansible_lint

- name: "Add packagecloud.io repository: StackStorm/{{ bwc_pkg_repo }}"
become: yes
no_log: yes
yum_repository:
name: "StackStorm_{{ bwc_pkg_repo }}"
description: "StackStorm_{{ bwc_pkg_repo }}"
file: "StackStorm_{{ bwc_pkg_repo }}"
baseurl: https://{{ bwc_read_token }}:@packagecloud.io/StackStorm/{{ bwc_pkg_repo }}/el/{{ ansible_distribution_major_version }}/$basearch
repo_gpgcheck: yes
gpgkey: "https://{{ bwc_read_token }}:@packagecloud.io/StackStorm/{{ bwc_pkg_repo }}/gpgkey"
sslcacert: /etc/pki/tls/certs/ca-bundle.crt
metadata_expire: 300
gpgcheck: no
enabled: yes
sslverify: yes
register: added_bwc_rpm_repository
32 changes: 32 additions & 0 deletions roles/bwc/tasks/ldap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---

- name: Setup st2.conf auth backend to LDAP
become: yes
# Unfortunately, ``with_dict`` also logs the dict which could leak passwords.
no_logs: yes
ini_file:
dest: /etc/st2/st2.conf
section: auth
option: backend
value: ldap
backup: yes
Copy link
Member

Choose a reason for hiding this comment

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

Notify st2 restart or reload handler (if enough) trigger when changing the st2.conf file.
Example: https://github.com/StackStorm/ansible-st2/blob/master/roles/st2/tasks/auth.yml#L34

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we also have to set the backend_kwargs before restarting. See next step. I did notify.

Copy link
Member

@arm4b arm4b Mar 10, 2017

Choose a reason for hiding this comment

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

Include notify for every task where its needed logically (ex: changing the conf file), its less error prone since "next task" could be removed, adjusted or never ran because of some conditional.

It doesn't matter how many times we call Ansible handlers, - they will be executed in the end of entire play run in any way.

See "Handlers: Running Operations On Change": http://docs.ansible.com/ansible/playbooks_intro.html with better explanation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh, good to know about that.

# Don't even setup LDAP if backend_kwargs is not defined
with_dict: "{{ bwc_ldap.backend_kwargs | default({}) }}"
Copy link
Member

@arm4b arm4b Mar 15, 2017

Choose a reason for hiding this comment

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

I see with_dict here but don't see {{ item }}. That thing is used only for loops, see http://docs.ansible.com/ansible/playbooks_loops.html#looping-over-hashes.

So you probably want something like:

when: bwc_ldap.backend_kwargs is defined and bwc_ldap.backend_kwargs|length > 0

Copy link
Member

@arm4b arm4b Mar 15, 2017

Choose a reason for hiding this comment

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

Also @lakshmi-kannan length for dict worked in yaml:

TASK [bwc : debug] *************************************************************
task path: /vagrant/roles/bwc/tasks/ldap.yml:6
ok: [ubuntu16] => {
    "{}|length": "0"
}
TASK [bwc : debug] *************************************************************
task path: /vagrant/roles/bwc/tasks/ldap.yml:6
ok: [ubuntu16] => {
    "{'key':'val','a':'b'}|length": "2"
}

Just interesting fact.

notify:
- restart st2api
- restart st2stream

- name: Setup st2.conf auth backend_kwargs for LDAP
become: yes
# Unfortunately, ``with_dict`` also logs the dict which could leak passwords.
no_log: yes
ini_file:
dest: /etc/st2/st2.conf
section: auth
option: backend_kwargs
value: "{{ bwc_ldap.backend_kwargs | to_json | string }}"
backup: yes
with_dict: "{{ bwc_ldap.backend_kwargs | default({}) }}"
Copy link
Member

@arm4b arm4b Mar 15, 2017

Choose a reason for hiding this comment

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

Same here, with_dict is used only for loops, just:

when: bwc_ldap.backend_kwargs is defined and bwc_ldap.backend_kwargs|length > 0

notify:
- restart st2api
- restart st2stream
38 changes: 38 additions & 0 deletions roles/bwc/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---

- name: Add BWC enterprise repos
include: bwc_repos_setup.yml
tags:
- BWC repos
- StackStorm enterprise

- name: Install latest bwc-enterprise package
become: yes
package:
name: bwc-enterprise
state: latest
register: bwc_installed
when: bwc_repo_added|success and bwc_version == "latest"
Copy link
Member

Choose a reason for hiding this comment

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

Don't need bwc_repo_added|success, since ansible will stop on first failure

tags:
- bwc
- st2 enterprise
- skip_ansible_lint

- name: Install pinned bwc-enterprise package
become: yes
package:
name: bwc-enterprise={{ bwc_version }}-{{ bwc_revision }}
state: present
register: bwc_installed
when: bwc_repo_added|success and bwc_version != "latest"
tags:
- bwc
- st2 enterprise

- name: Setup RBAC and setup roles and assignments if bwc_rbac is defined
include: "rbac.yml"
when: bwc_installed|success and bwc_rbac is defined
Copy link
Member

Choose a reason for hiding this comment

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

Don't need bwc_installed|success since Ansible will stop on first failure


- name: Setup LDAP and set up LDAP configuration
include: "ldap.yml"
when: bwc_installed|success and bwc_ldap is defined
Copy link
Member

Choose a reason for hiding this comment

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

Same here to avoid unecessary check bwc_installed|success

64 changes: 64 additions & 0 deletions roles/bwc/tasks/rbac.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---

- name: Create BWC RBAC directories
become: yes
file:
path: "{{ item }}"
mode: "u=rwx,g=rx,o=rx"
owner: st2
group: st2
state: directory
with_items:
- /opt/stackstorm/rbac/assignments
- /opt/stackstorm/rbac/roles

- name: Copy default RBAC roles to /opt/stackstorm/rbac/roles directory
become: yes
template:
src: rbac_roles/roles.yml.j2
dest: /opt/stackstorm/rbac/roles/{{ item.name }}.yaml
Copy link
Member

Choose a reason for hiding this comment

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

Changing any file in /rbac/ dir should notify reload bwc_rbac trigger.

Make sure we run that thing for other tasks in this file.

owner: st2
group: st2
with_items: "{{ bwc_rbac_default_roles }}"

- name: Copy user defined RBAC roles to /opt/stackstorm/rbac/roles directory
become: yes
template:
src: rbac_roles/roles.yml.j2
dest: /opt/stackstorm/rbac/roles/{{ item.name }}.yaml
owner: st2
group: st2
with_items: "{{ bwc_rbac.roles }}"
when: bwc_rbac.roles is defined

- name: Copy default RBAC assignments to /opt/stackstorm/rbac/assignments directory
become: yes
template:
src: rbac_assignments/assignments.yml.j2
dest: /opt/stackstorm/rbac/assignments/{{ item.name }}.yaml
owner: st2
group: st2
with_items: "{{ bwc_rbac_default_assignments }}"

- name: Copy user defined RBAC assignments to /opt/stackstorm/rbac/assignments directory
become: yes
template:
src: rbac_assignments/assignments.yml.j2
dest: /opt/stackstorm/rbac/assignments/{{ item.name }}.yaml
owner: st2
group: st2
with_items: "{{ bwc_rbac.assignments }}"
when: bwc_rbac.assignments is defined

- name: Enable RBAC in st2 configuration
Copy link
Member

Choose a reason for hiding this comment

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

Enable auth maybe?

become: yes
ini_file:
dest: /etc/st2/st2.conf
section: rbac
option: enable
value: True
backup: yes
notify:
- restart st2
- reload bwc_rbac
- restart st2api
5 changes: 5 additions & 0 deletions roles/bwc/templates/rbac_assignments/assignments.yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---

username: {{ item.name }}
roles:
{{ item.roles | to_nice_yaml }}
Copy link
Member

@arm4b arm4b Mar 15, 2017

Choose a reason for hiding this comment

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

Since we found indentation fix for https://github.com/StackStorm/ansible-st2/pull/126/files#r106033276 this must be the right way:
{{ item.roles | to_nice_yaml(2) | indent(2) }}

in case if someday item.roles will contain more complex data.

6 changes: 6 additions & 0 deletions roles/bwc/templates/rbac_roles/roles.yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---

name: {{ item.name }}
description: {{ item.description }}
permission_grants:
{{ item.permission_grants | to_nice_json }}
Copy link
Contributor Author

@lakshmi-kannan lakshmi-kannan Mar 14, 2017

Choose a reason for hiding this comment

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

See https://gist.github.com/lakshmi-kannan/0f5f073311a40d209d3e19c7cab3e864 for why I had to use to_nice_json as opposed to to_nice_yaml.

Copy link
Member

@arm4b arm4b Mar 15, 2017

Choose a reason for hiding this comment

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

I played with this to_nice_json and found this solution working:

---
name: {{ item.name }}
description: {{ item.description }}
permission_grants:
  {{ item.permission_grants | to_nice_yaml(2) | indent(2) }}

Which will generate:

---
name: basic
description: This role has access only to action core.remote in pack 'core'
permission_grants:
  - permission_types:
    - action_execute
    resource_uid: action:core:remote

Related issue: ansible/ansible#16207

1 change: 1 addition & 0 deletions stackstorm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
- st2web
- nodejs
- st2smoketests
- bwc