-
-
Notifications
You must be signed in to change notification settings - Fork 74
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
Conversation
What do you think about moving
which is similar to Related question to that. Do you think we'll have more roles related to |
roles/bwc_rbac/defaults/main.yml
Outdated
@@ -0,0 +1,3 @@ | |||
--- | |||
|
|||
st2_config_file_path: /etc/st2/st2.conf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can hardcode it without any big worries. st2.conf
path is pretty much a constant everywhere, bundled in packaging.
Also that's what we do in st2
role (st2.conf path is hardcoded).
Just a note: We should think about better approaches for setting Vars like:
seems to provide not that much flexibility in terms of configuration. But yeah, it's a good start. |
@lakshmi-kannan Returning to your original concern about roles/galaxy/repos/distribution. Here is a more detailed write-up about our options: 1)
|
roles/bwc/tasks/ldap.yml
Outdated
dest: "{{ st2_config_file_path }}" | ||
section: auth | ||
option: backend_kwargs | ||
value: "{{ ldap.config | to_nice_json }}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This prints out a multi-line string in the ini file and our config parser pukes. I tried to_json. Still the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One important request is to define all used vars in defaults/main.yml
and include them in README.md #Variables with descriptons.
Another issue is idempotence. Packagecloud logic needs a good cleaning and refactoring.
Additionally, as noted before https://stackstorm.slack.com/archives/stackstorm/p1489014359911089?thread_ts=1489011496.584237&cid=C029K4CBU we need all these roles to run in TravisCI. It will show you more errors. See #125 (comment) and #125 (comment) in @humblearner's PR how to mask the secrets in Ansible/Travis debug logs.
If we don't run these Ansible roles in CI, - it's not real.
What I liked: dicts and all the logic to configure advanced things like rbac settings. Looks pretty flexible from the ops PR.
In general, - I like the high-level interface to interact with bwc
(again, according to ops
PR), - we'll just need to polish low-level tasks more.
For ansible-st2
repo, I think it's a good idea to set these rbac
var defaults so they conifgure the same settings as bwc installer. Good for consistency.
Finally, if you know how to check bwc
basic functionality by adding bwc-smoketests
, similar to st2smoketests
, - that would be very nice.
roles/bwc/defaults/main.yml
Outdated
# used only if 'bwc_version' is numeric | ||
bwc_revision: 1 | ||
|
||
st2_config_file_path: /etc/st2/st2.conf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As noted before, don't forget to hardcode st2.conf
path.
We don't need it in vars (#126 (comment) reasons why).
roles/bwc/tasks/ldap.yml
Outdated
section: auth | ||
option: backend | ||
value: ldap | ||
backup: yes |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
roles/bwc/tasks/main.yml
Outdated
- bwc | ||
- st2 enterprise | ||
|
||
- name: Setup RBAC and setup roles and assignments if enable_rbac is defined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is enable_rbac
?
roles/bwc/tasks/rbac.yml
Outdated
owner: st2 | ||
group: st2 | ||
with_items: "{{ rbac.roles }}" | ||
when: rbac_roles is defined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't find any occurrence of rbac_roles
var. Is it used anywhere?
roles/bwc/tasks/rbac.yml
Outdated
owner: st2 | ||
group: st2 | ||
with_items: "{{ rbac.assignments }}" | ||
when: rbac_assignments is defined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't find any occurrence of rbac_assignments
var. Is it used anywhere?
|
||
- name: Update yum package cache | ||
become: yes | ||
shell: yum -q makecache -y --disablerepo='*' --enablerepo='StackStorm_{{ bwc_pkg_repo|replace("/", "_") }}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any idea why do we need this?
Also it's not idempotent.
- name: Update yum package cache BWC enterprise source repo | ||
become: yes | ||
shell: yum -q makecache -y --disablerepo='*' --enablerepo='StackStorm_{{ bwc_pkg_repo|replace("/", "_") }}-source' | ||
when: ansible_os_family == "RedHat" and added_bwc_rpm_repository|success |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when: ansible_os_family == "RedHat"
we're already in os-family specific yum
task.
roles/bwc/tasks/main.yml
Outdated
|
||
- name: Setup RBAC and setup roles and assignments if enable_rbac is defined | ||
include: "rbac.yml" | ||
when: rbac is defined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please name vars accordingly to role, eg: bwc_rbac
.
roles/bwc/tasks/main.yml
Outdated
|
||
- name: Setup LDAP and set up LDAP configuration | ||
include: "ldap.yml" | ||
when: ldap is defined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please name vars accordingly to role, eg: bwc_ldap
.
bwc_version: latest | ||
# used only if 'bwc_version' is numeric | ||
bwc_revision: 1 | ||
|
There was a problem hiding this comment.
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
.
When all finished/merged, we'll need Ansible |
Just a note: sync-up with |
roles/bwc/tasks/bwc_repos_yum.yml
Outdated
tags: skip_ansible_lint | ||
|
||
# See: https://github.com/docker-library/docs/tree/master/centos#package-documentation | ||
# We ship `nginx.conf` via `st2` package doc files, for example |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block could be removed, was really critical for st2
package.
* master: Include memo to revert the version pinning later Fix idempotence test in kitchen-ansible
roles/bwc/tasks/bwc_repos_apt.yml
Outdated
--- | ||
|
||
- name: Assert that master_token is specified | ||
fail: msg="License key must be supplied for BWC enterprise installation." |
There was a problem hiding this comment.
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
roles/bwc/tasks/bwc_repos_setup.yml
Outdated
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
roles/bwc/tasks/ldap.yml
Outdated
value: ldap | ||
backup: yes | ||
# Don't even setup LDAP if backend_kwargs is not defined | ||
with_dict: "{{ bwc_ldap.backend_kwargs | default({}) }}" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
roles/bwc/tasks/ldap.yml
Outdated
option: backend_kwargs | ||
value: "{{ bwc_ldap.backend_kwargs | to_json | string }}" | ||
backup: yes | ||
with_dict: "{{ bwc_ldap.backend_kwargs | default({}) }}" |
There was a problem hiding this comment.
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
roles/bwc/tasks/main.yml
Outdated
name: bwc-enterprise | ||
state: latest | ||
register: bwc_installed | ||
when: bwc_repo_added|success and bwc_version == "latest" |
There was a problem hiding this comment.
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
roles/bwc/tasks/main.yml
Outdated
|
||
- 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 |
There was a problem hiding this comment.
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
roles/bwc/tasks/main.yml
Outdated
|
||
- name: Setup LDAP and set up LDAP configuration | ||
include: "ldap.yml" | ||
when: bwc_installed|success and bwc_ldap is defined |
There was a problem hiding this comment.
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
become: yes | ||
template: | ||
src: rbac_roles/roles.yml.j2 | ||
dest: /opt/stackstorm/rbac/roles/{{ item.name }}.yaml |
There was a problem hiding this comment.
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.
|
||
username: {{ item.name }} | ||
roles: | ||
{{ item.roles | to_nice_yaml }} |
There was a problem hiding this comment.
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.
|
||
username: {{ item.name }} | ||
roles: | ||
{{ item.roles | to_nice_yaml(2) | indent(2) }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation should be 2 spaces here, same as in roles.yml.j2
--- | ||
|
||
username: {{ item.name }} | ||
roles: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and 0 spaces here.
Otherwise {{ item.roles | to_nice_yaml(2) | indent(2) }}
won't work correctly if we add some complex data there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 🎉
Thanks for being serious about the quality! 💯 After merging, what we'll need also is respective |
* master: (28 commits) Add check for hubot_token Changed to right variable Move st2chatops smoke tests to seperate yml file Add tags and update failure message Update test for slack adapter Remove notify handler in favor of changed_when:no Fix for idempotency Errors only Travis can catch fix for ansible-lint update kitchen.yml for adapter smoketests for st2chatops Add matteruser as one of the supported adapters. Make adapter update idempotent Support for adapter update notify restart for shell Fix lint error Update README(2) and meta/main.yml Add support for shell and assert for supported adapter and its settings Add shell and mattermost in supported_adapters Making Travis happy ...
To test, I changed stackstorm.yml to include following:
TODO: