Skip to main content

User Overview

User Overview

A user in the context of an AIX system refers to an entity that can be created, modified, or deleted using the provided module. This module allows for the creation of a new user with specified attributes, modification of existing user attributes, or deletion of a user. The module requires root user privileges or a privileged user with specific authorizations to perform these actions. It supports operations on users present in the local machine or in an LDAP server.

User Attributes and Options

The module provides options to specify user attributes, delete the home directory upon user removal, and enforce password changes on first login. This flexibility ensures that user management can be tailored to specific requirements.

Example: Creating a User

This example demonstrates how to create a user named aixguest1010 with specific attributes and password settings.


The code snippet shows how to create a user named aixguest1010 with specific attributes and password settings.

EXAMPLES = r'''
- name: Create user aixguest1010
ibm.power_aix.user:
state: present
name: aixguest1010
change_passwd_on_login: false
password: as$12ndhkfjk$1c
attributes:
home: /home/test/aixguest1010
data: 1272
'''

Main Functions

There are several main functions in this module. Some of them are get_user_attrs, changed_attrs, modify_user, create_user, remove_user, user_exists, change_password, and main. We will dive a little into modify_user, create_user, and remove_user.

modify_user

The modify_user function modifies the attributes of an existing user. It retrieves the current attributes of the user, determines the changes needed, and applies those changes using the chuser command. If a password change is required, it also updates the user's password.


The modify_user function modifies the attributes of the user and returns the output, return code, and error of the chuser command, if any.

def modify_user(module):
'''
Modify_user function modifies the attributes of the user and returns
output, return code and error of chuser command, if any.

arguments:
module (dict): The Ansible module
note:
Exits with fail_json in case of error
return:
(message for command, changed status)
'''

name = module.params['name']
msg = None
changed = False
# Get current user attributes
current_attrs = get_user_attrs(module)
# Get user attributes to change
attrs = changed_attrs(module, current_attrs)
# Redefine attributes

create_user

The create_user function creates a new user with the specified attributes. It constructs the mkuser command with the provided attributes and executes it. If a password is provided, it sets the password for the new user.


The create_user function creates the user with the attributes provided in the attributes field. It returns the standard output, return code, and error for the mkuser command, if any.

def create_user(module):
'''
Create_user function creates the user with the attributes provided in the
attribiutes field. It returns the standard output, return code and error
for mkuser command, if any.

arguments:
module (dict): The Ansible module
note:
Exits with fail_json in case of error
If this successfully returns, that means changes were made.
return:
Message for successful command.
'''
attributes = module.params['attributes']
name = module.params['name']
opts = ""
load_module_opts = None
msg = ""

# Adding the load module to the command so that the user is created at the right location.

remove_user

The remove_user function removes an existing user from the system. It constructs the userdel command and executes it. If the remove_homedir option is set, it also deletes the user's home directory.


The remove_user function removes the user from the system. It returns the standard output, return code, and error for the userdel command, if any.

def remove_user(module):
'''
Remove_user function removes the user from the system.It returns the standard output,
return code and error for mkuser command, if any.

arguments:
module (dict): The Ansible module
note:
Exits with fail_json in case of error
return:
Message for successfull command
'''
name = module.params['name']
cmd = ['userdel']

if module.params['remove_homedir']:
cmd.append('-r')

cmd.append(name)

rc, stdout, stderr = module.run_command(cmd)

 

This is an auto-generated document by Swimm 🌊 and has not yet been verified by a human