From 3aad5c143c2aae565d9adaa9baf76d8e97aee2fb Mon Sep 17 00:00:00 2001 From: e88z4 Date: Thu, 20 Jan 2022 23:19:04 -0500 Subject: [PATCH] - add truenas_group_debug tag - set fact of existing groups after create/update/delete tasks --- tasks/group.yml | 56 ++++++++++++++++++++++++++++++++++++++++++++-- tasks/main.yml | 5 +++++ templates/group.j2 | 3 ++- 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/tasks/group.yml b/tasks/group.yml index 033aa63..26386c1 100644 --- a/tasks/group.yml +++ b/tasks/group.yml @@ -10,26 +10,37 @@ delegate_to: localhost tags: - truenas_group + - truenas_user + - truenas_group_debug + - truenas_user_debug - name: group | setting group configuration fact set_fact: truenas_group_config: "{{ lookup('template', 'group.j2') }}" tags: - truenas_group + - truenas_user + - truenas_group_debug + - truenas_user_debug - name: group | print group fact debug: msg: "{{ truenas_group_config }}" tags: - - truenas_group + - truenas_user_debug + - truenas_group_debug + -- name: group | terminate if any built-in groups (id<1000) is modified +- name: group | terminate if any built-in groups is modified fail: msg: "{{ item.name + ' is a built-in group' }}" when: truenas_group_config.built_in_groups | length > 0 with_items: "{{ truenas_group_config.built_in_groups }}" tags: + - truenas_user - truenas_group + - truenas_group_debug + - truenas_user_debug - name: group | create group uri: @@ -43,7 +54,10 @@ with_items: "{{ truenas_group_config.create_groups }}" delegate_to: localhost tags: + - truenas_user - truenas_group + - truenas_group_debug + - truenas_user_debug - name: group | update group uri: @@ -57,7 +71,10 @@ with_items: "{{ truenas_group_config.update_groups }}" delegate_to: localhost tags: + - truenas_user - truenas_group + - truenas_group_debug + - truenas_user_debug - name: group | delete_group uri: @@ -69,5 +86,40 @@ with_items: "{{ truenas_group_config.delete_groups }}" delegate_to: localhost tags: + - truenas_user + - truenas_user_debug + - truenas_group + - truenas_group_debug + +- name: group | get all groups + uri: + url: "{{ truenas_api_url + '/group' }}" + force_basic_auth: true + method: "GET" + user: "{{ truenas_api_user }}" + password: "{{ truenas_api_password }}" + register: truenas_group_found + delegate_to: localhost + tags: + - truenas_user + - truenas_user_debug - truenas_group + - truenas_group_debug + +- name: group | setting group configuration fact + set_fact: + truenas_group_config: "{{ lookup('template', 'group.j2') }}" + tags: + - truenas_user + - truenas_user_debug + - truenas_group + - truenas_group_debug + +- name: group | print all group + debug: + msg: "{{ truenas_group_config.existing_groups }}" + delegate_to: localhost + tags: + - truenas_user_debug + - truenas_group_debug diff --git a/tasks/main.yml b/tasks/main.yml index ee7b32c..5dcd278 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -2,11 +2,16 @@ - include_tasks: update.yml tags: - truenas_update + - truenas_update_debug - include_tasks: group.yml tags: - truenas_group + - truenas_user + - truenas_user_debug + - truenas_group_debug - include_tasks: user.yml tags: - truenas_user + - truneas_user_debug diff --git a/templates/group.j2 b/templates/group.j2 index 11bd97a..bafa1aa 100644 --- a/templates/group.j2 +++ b/templates/group.j2 @@ -33,7 +33,8 @@ 'create_groups': create_groups, 'update_groups': update_groups, 'delete_groups': delete_groups, - 'built_in_groups': built_in_groups + 'built_in_groups': built_in_groups, + 'existing_groups': existing_groups }) %} {{ truenas_groups }}