1Rex::Commands::User(3)User Contributed Perl DocumentationRex::Commands::User(3)
2
3
4
6 Rex::Commands::User - Manipulate users and groups
7
9 With this module you can manage user and groups.
10
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
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 password => 'blahblah',
40 crypt_password => '*', # on Linux, OpenBSD and NetBSD
41 system => 1,
42 create_home => TRUE,
43 shell => '/bin/bash',
44 ssh_key => "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQChUw...";
45
46 There is also a no_create_home option similar to create_home but doing
47 the opposite. If both used, create_home takes precedence as it the
48 preferred option to specify home directory creation policy.
49
50 If none of them are specified, Rex follows the remote system's home
51 creation policy.
52
53 The crypt_password option specifies the encrypted value as found in
54 /etc/shadow; on Linux special values are '*' and '!' which mean
55 'disabled password' and 'disabled login' respectively.
56
57 create_user($user => {})
58 Create or update a user.
59
60 get_uid($user)
61 Returns the uid of $user.
62
63 get_user($user)
64 Returns all information about $user.
65
66 user_groups($user)
67 Returns group membership about $user.
68
69 user_list()
70 Returns user list via getent passwd.
71
72 task "list_user", "server01", sub {
73 for my $user (user_list) {
74 print "name: $user / uid: " . get_uid($user) . "\n";
75 }
76 };
77
78 delete_user($user)
79 Delete a user from the system.
80
81 delete_user "trak", {
82 delete_home => 1,
83 force => 1,
84 };
85
86 lock_password($user)
87 Lock the password of a user account. Currently this is only available
88 on Linux (see passwd --lock).
89
90 unlock_password($user)
91 Unlock the password of a user account. Currently this is only available
92 on Linux (see passwd --unlock).
93
94 create_group($group, {})
95 Create or update a group.
96
97 create_group $group, {
98 gid => 1500,
99 system => 1,
100 };
101
102 get_gid($group)
103 Return the group id of $group.
104
105 get_group($group)
106 Return information of $group.
107
108 $info = get_group("wheel");
109
110 delete_group($group)
111 Delete a group.
112
113
114
115perl v5.30.0 2019-07-24 Rex::Commands::User(3)