group-exists

Example:

# Create a group called 'freckles' with gid 1111.
- group-exists:
    group: freckles
    gid: 1111

Description

Create a group on a system if it doesn't exist yet.

If the group argument is not present or empty, this task will be skipped.

If the group exists, and the optional gid argument is specified, it'll be changed if necessary. Optionally, the group can be marked as a 'system' group.

Resources

Variables

Name Type Default Description

group

string --

The name of the group. Required

gid

integer --

The gid of the group.

system_group

boolean --

Whether the group should be created as 'system' group.

Examples

Example 1

Create a group called 'freckles' with gid 1111.

Code
- group-exists:
    group: freckles
    gid: 1111

Example 2

Create a group called 'freckles' with a random gid.

Code
- group-exists:
    group: freckles

Code

doc:
  short_help: Ensure a group exists.
  help: |
    Create a group on a system if it doesn't exist yet.

    If the ``group`` argument is not present or empty, this task will be skipped.

    If the group exists, and the optional ``gid`` argument is specified, it'll be changed if necessary.
    Optionally, the group can be marked as a 'system' group.

  references:
    what is a 'system' group: https://askubuntu.com/questions/523949/what-is-a-system-group-as-opposed-to-a-normal-group
  examples:
  - title: Create a group called 'freckles' with gid 1111.
    vars:
      group: freckles
      gid: 1111
  - title: Create a group called 'freckles' with a random gid.
    vars:
      group: freckles


args:
  group:
    doc:
      short_help: The name of the group.
    type: string
    required: true
    cli:
      param_type: argument
      metavar: GROUP_NAME
  gid:
    doc:
      short_help: The gid of the group.
    type: integer
    required: false
    cli:
      metavar: GID
  system_group:
    doc:
      short_help: Whether the group should be created as 'system' group.
    type: boolean
    required: false
    cli:
      show_default: true
      is_flag: true

meta:
  tags:
  - group
  - user-management
  - system

frecklets:

- task:
    become: true
  frecklet:
    name: group
    type: ansible-module
    skip: '{{:: group | true_if_empty ::}}'
    desc:
      short: "ensure group '{{:: group ::}}' exists"
      long: |
        Create group '{{:: group ::}}'{%:: if gid ::%}, using the group id '{{:: gid ::}}'{%:: endif ::%}.

        {%:: if system_group ::%}The new group should be a system group.{%:: endif ::%}
      references:
        "'group' Ansible module": https://docs.ansible.com/ansible/latest/modules/group_module.html
    properties:
      idempotent: true
      elevated: true
      internet: false
  vars:
    name: '{{:: group ::}}'
    state: present
    gid: '{{:: gid ::}}'
    system: '{{:: system_group ::}}'
frecklecute group-exists --help

Usage: frecklecute group-exists [OPTIONS] GROUP_NAME

  Create a group on a system if it doesn't exist yet.

  If the ``group`` argument is not present or empty, this task will be
  skipped.

  If the group exists, and the optional ``gid`` argument is specified, it'll
  be changed if necessary. Optionally, the group can be marked as a 'system'
  group.

Options:
  --gid GID                       The gid of the group.
  --system-group / --no-system-group
                                  Whether the group should be created as
                                  'system' group.
  --help                          Show this message and exit.
# -*- coding: utf-8 -*-


#
# module path: pycklets.group_exists.GroupExists
#


from dataclasses import dataclass
from pyckles import AutoPycklet
from typing import *    # noqa

@dataclass
class GroupExists(AutoPycklet):
    """Create a group on a system if it doesn't exist yet.

     If the ``group`` argument is not present or empty, this task will be skipped.

     If the group exists, and the optional ``gid`` argument is specified, it'll be changed if necessary.
     Optionally, the group can be marked as a 'system' group.

       Args:
         gid: The gid of the group.
         group: The name of the group.
         system_group: Whether the group should be created as 'system' group.

    """

    FRECKLET_ID = "group-exists"

    gid: int = None
    group: str = None
    system_group: bool = None


    def __post_init__(self):
        super(GroupExists, self).__init__(var_names=["gid", "group", "system_group"])


frecklet_class = GroupExists
# -*- coding: utf-8 -*-


#
# module path: pycklets.group_exists.GroupExists
#


from pyckles import AutoPycklet

class GroupExists(AutoPycklet):
    """Create a group on a system if it doesn't exist yet.

     If the ``group`` argument is not present or empty, this task will be skipped.

     If the group exists, and the optional ``gid`` argument is specified, it'll be changed if necessary.
     Optionally, the group can be marked as a 'system' group.

       Args:
         gid: The gid of the group.
         group: The name of the group.
         system_group: Whether the group should be created as 'system' group.

    """

    FRECKLET_ID = "group-exists"

    def __init__(self, gid=None, group=None, system_group=None):

        super(GroupExists, self).__init__(var_names=["gid", "group", "system_group"])
        self._gid = gid
        self._group = group
        self._system_group = system_group

    @property
    def gid(self):
        return self._gid

    @gid.setter
    def gid(self, gid):
        self._gid = gid

    @property
    def group(self):
        return self._group

    @group.setter
    def group(self, group):
        self._group = group

    @property
    def system_group(self):
        return self._system_group

    @system_group.setter
    def system_group(self, system_group):
        self._system_group = system_group



frecklet_class = GroupExists