users-exist

Description

Make sure a list of users exist on a system.

This is a fairly basic frecklet, use the 'user-exist' one if you need to specify details about users.

Resources

Variables

Name Type Default Description

names

list --

A list of usernames to make sure exist. Required

system_user

boolean False

Whether the users to create should be created as system user.

Code

doc:
  short_help: Make sure a list of users exist on a system.
  help: |
    Make sure a list of users exist on a system.

    This is a fairly basic frecklet, use the 'user-exist' one if you need to specify details about users.

  references:
    Creating a User in Ansible: https://serversforhackers.com/c/create-user-in-ansible

args:
  names:
    doc:
      short_help: A list of usernames to make sure exist.
    type: list
    required: true
    empty: false
    schema:
      type: string
    cli:
      metavar: USER_NAME
      param_type: argument
  system_user:
    doc:
      short_help: Whether the users to create should be created as system user.
    type: boolean
    required: false
    default: false
    cli:
      show_default: true
      is_flag: true

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

frecklets:
- frecklet:
    name: user
    type: ansible-module
    desc:
      short: "ensure users exit: {{:: names | join(', ') ::}}"
      references:
        "'useradd' tutorial (tecmint)": https://www.tecmint.com/add-users-in-linux/
        "'user' Ansible module": https://docs.ansible.com/ansible/latest/modules/user_module.html
    properties:
      idempotent: true
      elevated: true
      internet: false
  task:
    become: true
    loop: '{{:: names ::}}'
    loop_control:
      loop_var: __name__
  vars:
    name: '{{ __name__ }}'
    state: present
    system: '{{:: system_user ::}}'
frecklecute users-exist --help

Usage: frecklecute users-exist [OPTIONS] USER_NAME

  Make sure a list of users exist on a system.

  This is a fairly basic frecklet, use the 'user-exist' one if you need to
  specify details about users.

Options:
  --system-user / --no-system-user
                                  Whether the users to create should be
                                  created as system user.
  --help                          Show this message and exit.
# -*- coding: utf-8 -*-


#
# module path: pycklets.users_exist.UsersExist
#


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

@dataclass
class UsersExist(AutoPycklet):
    """Make sure a list of users exist on a system.

     This is a fairly basic frecklet, use the 'user-exist' one if you need to specify details about users.

       Args:
         names: A list of usernames to make sure exist.
         system_user: Whether the users to create should be created as system user.

    """

    FRECKLET_ID = "users-exist"

    names: List = None
    system_user: bool = None


    def __post_init__(self):
        super(UsersExist, self).__init__(var_names=["names", "system_user"])


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


#
# module path: pycklets.users_exist.UsersExist
#


from pyckles import AutoPycklet

class UsersExist(AutoPycklet):
    """Make sure a list of users exist on a system.

     This is a fairly basic frecklet, use the 'user-exist' one if you need to specify details about users.

       Args:
         names: A list of usernames to make sure exist.
         system_user: Whether the users to create should be created as system user.

    """

    FRECKLET_ID = "users-exist"

    def __init__(self, names=None, system_user=None):

        super(UsersExist, self).__init__(var_names=["names", "system_user"])
        self._names = names
        self._system_user = system_user

    @property
    def names(self):
        return self._names

    @names.setter
    def names(self, names):
        self._names = names

    @property
    def system_user(self):
        return self._system_user

    @system_user.setter
    def system_user(self, system_user):
        self._system_user = system_user



frecklet_class = UsersExist