1Rex::Commands::User(3)User Contributed Perl DocumentationRex::Commands::User(3)
2
3
4

NAME

6       Rex::Commands::User - Manipulate users and groups
7

DESCRIPTION

9       With this module you can manage user and groups.
10

SYNOPSIS

12        use Rex::Commands::User;
13
14        task "create-user", "remoteserver", sub {
15          create_user "root",
16            uid         => 0,
17            home        => '/root',
18            comment     => 'Root Account',
19            expire      => '2011-05-30',
20            groups      => [ 'root', '...' ],
21            password    => 'blahblah',
22            system      => 1,
23            create_home => TRUE,
24            shell       => '/bin/bash',
25            ssh_key     => "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQChUw...";
26        };
27

EXPORTED FUNCTIONS

29   account($name, %option)
30       Manage user account.
31
32        account "krimdomu",
33          ensure         => "present",  # default
34          uid            => 509,
35          home           => '/root',
36          comment        => 'User Account',
37          expire         => '2011-05-30',
38          groups         => [ 'root', '...' ],
39          login_class    => 'staff',   # on OpenBSD
40          password       => 'blahblah',
41          crypt_password => '*', # on Linux, OpenBSD and NetBSD
42          system         => 1,
43          create_home    => TRUE,
44          shell          => '/bin/bash',
45          ssh_key        => "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQChUw...";
46
47       There is also a no_create_home option similar to create_home but doing
48       the opposite. If both used, create_home takes precedence as it the
49       preferred option to specify home directory creation policy.
50
51       If none of them are specified, Rex follows the remote system's home
52       creation policy.
53
54       The crypt_password option specifies the encrypted value as found in
55       /etc/shadow; on Linux special values are '*' and '!' which mean
56       'disabled password' and 'disabled login' respectively.
57
58   create_user($user => {})
59       Create or update a user.
60
61       This function supports the following hooks:
62
63       before
64           This gets executed before the user is created. All original
65           parameters are passed to it.
66
67       after
68           This gets executed after the user is created. All original
69           parameters, and the user's "UID" are passed to it.
70
71   get_uid($user)
72       Returns the uid of $user.
73
74   get_user($user)
75       Returns all information about $user.
76
77   user_groups($user)
78       Returns group membership about $user.
79
80   user_list()
81       Returns user list via getent passwd.
82
83        task "list_user", "server01", sub {
84          for my $user (user_list) {
85            print "name: $user / uid: " . get_uid($user) . "\n";
86          }
87        };
88
89   delete_user($user)
90       Delete a user from the system.
91
92        delete_user "trak", {
93          delete_home => 1,
94          force     => 1,
95        };
96
97   lock_password($user)
98       Lock the password of a user account. Currently this is only available
99       on Linux (see passwd --lock) and OpenBSD.
100
101   unlock_password($user)
102       Unlock the password of a user account. Currently this is only available
103       on Linux (see passwd --unlock) and OpenBSD.
104
105   create_group($group, {})
106       Create or update a group.
107
108        create_group $group, {
109          gid => 1500,
110          system => 1,
111        };
112
113   get_gid($group)
114       Return the group id of $group.
115
116   get_group($group)
117       Return information of $group.
118
119        $info = get_group("wheel");
120
121   delete_group($group)
122       Delete a group.
123
124
125
126perl v5.34.0                      2021-07-21            Rex::Commands::User(3)
Impressum