Comments (3)
Following Powershell remove groups if it's configure with an empty list
- name: remove groups members
ansible.windows.win_powershell:
script: |
[CmdletBinding()]
param (
[String]
$groups_name
)
#Remove existing Group
$Groups = (Get-ADGroup $groups_name -Properties Member).Member
Remove-ADGroupMember -Identity $groups_name -Members $Groups -Confirm:$false
parameters:
groups_name: "{{ item.name }}"
loop: "{{ site_ADDC_groups }}"
when: item.member_of == ''
from microsoft.ad.
The problem here is that the members/set option is set to be a list
type with string
elements. Traditionally in Ansible the argument validation will convert the value to a list if a single value was specified for example foo: bar
would become foo: ['bar']
. The same applies to an empty string where foo: ""
becomes foo: [""]
.
This is a problem because the code will see this list, go through each member and try to find the group's identity which in this case will be an empty string.
The best way to specify an empty list as the value is to just use an empty list like so
- name: Creat ADDC groups whith members
microsoft.ad.group:
name: "{{ item.name }}"
description : "{{ item.description }}"
scope: "{{ item.scope }}"
path: "{{ group_fqdn_path }}"
state: present
members:
set: []
protect_from_deletion: true
loop: "{{ site_ADDC_groups }}"
I'll leave this open as I think the code should probably just ignore empty strings for these values or at the very least it should document this scenario to help others who might come across it.
from microsoft.ad.
Related Issues (20)
- Encrypt LAPS credentials with ansible-vault HOT 4
- New Release of microsoft.ad HOT 1
- microsoft.ad.group module : Set members list HOT 3
- microsoft.ad.user - New-ADUser failed: A parameter cannot be found that matches parameter name 'LockedOut' HOT 1
- microsoft.ad.user - Created user not found while deleting by ad-hoc command HOT 1
- Error: The term 'Get-ADRootDSE' is not recognized as the name of a cmdlet HOT 5
- Error: Skip computer 'x' with new name 'x' because the new name is the same as the current name. HOT 1
- Getting an error while running the microsoft.ad module HOT 1
- microsoft.ad.domain fails with 'InstallDNS' not recognized error HOT 3
- microsoft.ad.user groups documentation should detail which formats it accepts
- How do you actually execute modules in this collection (requires powershell)? HOT 7
- Adding members to a group requires an explicit path to be set HOT 3
- The system cannot find the file specified. HOT 4
- Ansible Semaphore compatibility HOT 1
- Unable to parse microsoft.ad.ldap.yaml HOT 3
- Add action_groups HOT 3
- Using microsoft.ad.group to set members of a group does not work when both groups are in different OUs HOT 2
- microsoft.ad.object can't assign attribute PrincipalsAllowedToRetrieveManagedPassword HOT 2
- Not able to run module, giving an error AnsibleADObject not found HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from microsoft.ad.