Repository navigation
Add support for defining OpenStack groups #94
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
Open
seunghun1ee
wants to merge
7
commits into
main
Choose a base branch
from
add-group-to-project2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e34cbf1
Add support for defining OpenStack groups
seunghun1ee 0b4f747
Add quote filter for exporting values
seunghun1ee 9df0ffb
Add documentation for groups
seunghun1ee 982daf7
Spilt tasks for users and group users
seunghun1ee 06d077a
Add tasks to disambiguate group identity
seunghun1ee fb0f429
Fix typo and wrong docs/comments
seunghun1ee 6329a11
Prevent leaking password
seunghun1ee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| --- | ||
| - name: Ensure openrc environment file exists for group users | ||
| ansible.builtin.template: | ||
| src: group-openrc.j2 | ||
| dest: "{{ item.1.openrc_file }}" | ||
| mode: "0600" | ||
| with_subelements: | ||
| - "{{ project.groups }}" | ||
| - users | ||
| - skip_missing: true | ||
| when: | ||
| - project.groups is defined | ||
| - item.1.openrc_file is defined | ||
| loop_control: | ||
| label: "{{ project.name }}: {{ item.0.name }}: {{ item.1.name }}" | ||
| delegate_to: localhost |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| --- | ||
| - name: Ensure group users exist | ||
| openstack.cloud.identity_user: | ||
| auth_type: "{{ os_projects_auth_type }}" | ||
| auth: "{{ os_projects_admin_auth }}" | ||
| region_name: "{{ os_projects_region | default(omit) }}" | ||
| cacert: "{{ os_projects_cacert | default(omit) }}" | ||
| cloud: "{{ os_projects_cloud | default(omit) }}" | ||
| interface: "{{ os_projects_interface | default(omit, true) }}" | ||
| name: "{{ item.1.name }}" | ||
| description: "{{ item.1.description | default(omit) }}" | ||
| email: "{{ item.1.email | default(omit) }}" | ||
| password: "{{ item.1.password | default(omit) }}" | ||
| # NOTE(bbezak): identity_user looks up default_project in the user domain | ||
| # ('domain'). Omit default_project for cross-domain users to avoid false | ||
| # "No Project found" errors. | ||
| default_project: "{{ (user_domain_id == project_domain_id) | ternary(project.name, omit) }}" | ||
| domain: "{{ user_domain_id }}" | ||
| state: present | ||
| enabled: true | ||
| wait: true | ||
| with_subelements: | ||
| - "{{ project.groups }}" | ||
| - users | ||
| - skip_missing: true | ||
| when: | ||
| - project.groups is defined | ||
| - item.1.create_user | default(true) | bool | ||
| environment: "{{ os_projects_environment }}" | ||
| vars: | ||
| user_domain_id: "{{ (project.user_domain in os_projects_domain_to_id.values()) | ternary(project.user_domain, os_projects_domain_to_id[project.user_domain]) }}" | ||
| project_domain_id: "{{ (project.project_domain in os_projects_domain_to_id.values()) | ternary(project.project_domain, os_projects_domain_to_id[project.project_domain]) }}" | ||
| loop_control: | ||
| label: "{{ item.0.name }}: {{ item.1.name }}" | ||
|
|
||
| # This task is to ensure we don't miss users that have ``create_user`` set to false | ||
| - name: Look up users | ||
| openstack.cloud.identity_user_info: | ||
| auth_type: "{{ os_projects_auth_type }}" | ||
| auth: "{{ os_projects_admin_auth }}" | ||
| region_name: "{{ os_projects_region | default(omit) }}" | ||
| cacert: "{{ os_projects_cacert | default(omit) }}" | ||
| cloud: "{{ os_projects_cloud | default(omit) }}" | ||
| interface: "{{ os_projects_interface | default(omit, true) }}" | ||
| domain: "{{ user_domain_id }}" | ||
| name: "{{ item.1.name }}" | ||
| with_subelements: | ||
| - "{{ project.groups }}" | ||
| - users | ||
| - skip_missing: true | ||
| when: | ||
| - project.groups is defined | ||
| environment: "{{ os_projects_environment }}" | ||
| vars: | ||
| user_domain_id: "{{ (project.user_domain in os_projects_domain_to_id.values()) | ternary(project.user_domain, os_projects_domain_to_id[project.user_domain]) }}" | ||
| project_domain_id: "{{ (project.project_domain in os_projects_domain_to_id.values()) | ternary(project.project_domain, os_projects_domain_to_id[project.project_domain]) }}" | ||
| loop_control: | ||
| label: "{{ item.0.name }}: {{ item.1.name }}" | ||
| index_var: idx | ||
| register: os_projects_fetched_users | ||
|
|
||
| - name: Assert that all users exist | ||
| ansible.builtin.assert: | ||
| quiet: true | ||
| that: | ||
|
seunghun1ee marked this conversation as resolved.
Resolved
|
||
| - os_projects_fetched_users.results[idx].users is defined | ||
| - os_projects_fetched_users.results[idx].users | length > 0 | ||
| fail_msg: "The user '{{ item.1.name }}' does not exist in the '{{ project.user_domain }}' domain" | ||
| with_subelements: | ||
| - "{{ project.groups }}" | ||
| - users | ||
| - skip_missing: true | ||
| when: | ||
| - project.groups is defined | ||
| loop_control: | ||
| label: "{{ item.0.name }}: {{ item.1.name }}" | ||
| index_var: idx | ||
|
|
||
| - name: Ensure users are added to the group | ||
| openstack.cloud.group_assignment: | ||
| auth_type: "{{ os_projects_auth_type }}" | ||
| auth: "{{ os_projects_admin_auth }}" | ||
| region_name: "{{ os_projects_region | default(omit) }}" | ||
| cacert: "{{ os_projects_cacert | default(omit) }}" | ||
| cloud: "{{ os_projects_cloud | default(omit) }}" | ||
| interface: "{{ os_projects_interface | default(omit, true) }}" | ||
| user: "{{ user_id }}" | ||
| group: "{{ group_id }}" | ||
| state: present | ||
| wait: true | ||
| with_subelements: | ||
| - "{{ project.groups }}" | ||
| - users | ||
| - skip_missing: true | ||
| when: project.groups is defined | ||
| environment: "{{ os_projects_environment }}" | ||
| vars: | ||
| user_id: "{{ os_projects_fetched_users.results[idx].users[0].id }}" | ||
| group_domain_id: "{{ (item.0.domain in os_projects_domain_to_id.values()) | ternary(item.0.domain, os_projects_domain_to_id[item.0.domain]) }}" | ||
| group_id: "{{ os_projects_group_to_id[group_domain_id][item.0.name] }}" | ||
| loop_control: | ||
| label: "{{ item.0.name }}: {{ item.1.name }}" | ||
| index_var: idx | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| --- | ||
| - name: Ensure the groups exist | ||
| openstack.cloud.identity_group: | ||
| auth_type: "{{ os_projects_auth_type }}" | ||
| auth: "{{ os_projects_admin_auth }}" | ||
| region_name: "{{ os_projects_region | default(omit) }}" | ||
| cacert: "{{ os_projects_cacert | default(omit) }}" | ||
| cloud: "{{ os_projects_cloud | default(omit) }}" | ||
| interface: "{{ os_projects_interface | default(omit, true) }}" | ||
| name: "{{ item.name }}" | ||
| description: "{{ item.description | default(omit) }}" | ||
| domain_id: "{{ group_domain_id }}" | ||
| state: present | ||
| wait: true | ||
| with_items: "{{ project.groups }}" | ||
| when: item.create_group | default(true) | bool | ||
| environment: "{{ os_projects_environment }}" | ||
| vars: | ||
| group_domain_id: "{{ (item.domain in os_projects_domain_to_id.values()) | ternary(item.domain, os_projects_domain_to_id[item.domain]) }}" | ||
| loop_control: | ||
| label: "{{ project.name }}: {{ item.name }}" | ||
|
|
||
| # This task is to ensure we don't miss groups that have ``create_group`` set to false | ||
| - name: Look up groups | ||
| openstack.cloud.identity_group_info: | ||
| auth_type: "{{ os_projects_auth_type }}" | ||
| auth: "{{ os_projects_admin_auth }}" | ||
| region_name: "{{ os_projects_region | default(omit) }}" | ||
| cacert: "{{ os_projects_cacert | default(omit) }}" | ||
| cloud: "{{ os_projects_cloud | default(omit) }}" | ||
| interface: "{{ os_projects_interface | default(omit, true) }}" | ||
| name: "{{ item.name }}" | ||
| domain: "{{ group_domain_id }}" | ||
| with_items: "{{ project.groups }}" | ||
| environment: "{{ os_projects_environment }}" | ||
| vars: | ||
| group_domain_id: "{{ (item.domain in os_projects_domain_to_id.values()) | ternary(item.domain, os_projects_domain_to_id[item.domain]) }}" | ||
| loop_control: | ||
| label: "{{ project.name }}: {{ item.name }}" | ||
| index_var: idx | ||
| register: os_projects_fetched_groups | ||
|
|
||
| - name: Assert that all groups exist | ||
| ansible.builtin.assert: | ||
| quiet: true | ||
| that: | ||
|
seunghun1ee marked this conversation as resolved.
Resolved
|
||
| - os_projects_fetched_groups.results[idx].groups is defined | ||
| - os_projects_fetched_groups.results[idx].groups | length > 0 | ||
| fail_msg: "The group '{{ item.name }}' does not exist in the '{{ item.domain }}' domain" | ||
| with_items: "{{ project.groups }}" | ||
| loop_control: | ||
| label: "{{ project.name }}: {{ item.name }}" | ||
| index_var: idx | ||
|
|
||
| - name: Populate domain ID - group name - group ID mapping | ||
| ansible.builtin.set_fact: | ||
| os_projects_group_to_id: "{{ os_projects_group_to_id | combine(sub_map, recursive=true) }}" | ||
| with_items: "{{ project.groups }}" | ||
| vars: | ||
| group_domain_id: "{{ (item.domain in os_projects_domain_to_id.values()) | ternary(item.domain, os_projects_domain_to_id[item.domain]) }}" | ||
| sub_map: "{{ {group_domain_id: {item.name: os_projects_fetched_groups.results[idx].groups[0].id}} }}" | ||
| loop_control: | ||
| index_var: idx | ||
| label: "Domain: {{ item.domain }} - Group: {{ item.name }}" | ||
|
|
||
| - name: Ensure groups have required project roles | ||
| openstack.cloud.role_assignment: | ||
| auth_type: "{{ os_projects_auth_type }}" | ||
| auth: "{{ os_projects_admin_auth }}" | ||
| region_name: "{{ os_projects_region | default(omit) }}" | ||
| cacert: "{{ os_projects_cacert | default(omit) }}" | ||
| cloud: "{{ os_projects_cloud | default(omit) }}" | ||
| interface: "{{ os_projects_interface | default(omit, true) }}" | ||
| group: "{{ item.0.name }}" | ||
| project: "{{ project.name }}" | ||
| role: "{{ item.1 }}" | ||
| group_domain: "{{ item.0.domain | default(omit, true) }}" | ||
| project_domain: "{{ project.project_domain | default(omit, true) }}" | ||
| state: present | ||
| with_subelements: | ||
| - "{{ project.groups }}" | ||
| - roles | ||
| - skip_missing: true | ||
| environment: "{{ os_projects_environment }}" | ||
| loop_control: | ||
| label: "{{ project.name }}: {{ item.0.name }}: {{ item.1 }}" | ||
|
|
||
| - name: Ensure groups have required domain roles | ||
| openstack.cloud.role_assignment: | ||
| auth_type: "{{ os_projects_auth_type }}" | ||
| auth: "{{ os_projects_admin_auth }}" | ||
| region_name: "{{ os_projects_region | default(omit) }}" | ||
| cacert: "{{ os_projects_cacert | default(omit) }}" | ||
| cloud: "{{ os_projects_cloud | default(omit) }}" | ||
| interface: "{{ os_projects_interface | default(omit, true) }}" | ||
| group: "{{ item.0.name }}" | ||
| domain: "{{ domain_is_id | ternary(item.0.domain, os_projects_domain_to_id[item.0.domain]) }}" | ||
| role: "{{ item.1 }}" | ||
| state: present | ||
| with_subelements: | ||
| - "{{ project.groups }}" | ||
| - domain_roles | ||
| - skip_missing: true | ||
| environment: "{{ os_projects_environment }}" | ||
| vars: | ||
| domain_is_id: "{{ item.0.domain in os_projects_domain_to_id.values() }}" | ||
| loop_control: | ||
| label: "{{ item.0.domain }}: {{ item.0.name }}: {{ item.1 }}" | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.