puppet自动化之用户资源定义

用户资源的定义

资源类之user用户

    user:
                    Manage users.
                    
                    属性:
                        name:用户名;
                        uid: UID;
                        gid:基本组ID;
                        groups:附加组,不能包含基本组;
                        comment:注释; 
                        expiry:过期时间 ;
                        home:家目录; 
                        shell:默认shell类型;
                        system:是否为系统用户 ;
                        ensure:present/absent;
                        password:加密后的密码串; 
                
                关系元参数:before/require
                    A before B: B依赖于A,定义在A资源中;
                        {
                            ...
                            before  => Type['B'],
                            ...
                        }
                    B require A: B依赖于A,定义在B资源中;
                        {
                            ...
                            require => Type['A'],
                            ...
                        }
                        
[root@centos7 ~]# puppet describe user    查看用户资源的相关属性

user
====
Manage users.  This type is mostly built to manage system
users, so it is lacking some features useful for managing normal
users.
This resource type uses the prescribed native tools for creating
groups and generally uses POSIX APIs for retrieving information
about them.  It does not directly modify `/etc/passwd` or anything.
**Autorequires:** If Puppet is managing the user's primary group (as
provided in the `gid` attribute), the user resource will autorequire
that group. If Puppet is managing any role accounts corresponding to the
user's roles, the user resource will autorequire those role accounts.


Parameters
----------

- **allowdupe**
    Whether to allow duplicate UIDs. Defaults to `false`.
    Valid values are `true`, `false`, `yes`, `no`. 

- **attribute_membership**
    Whether specified attribute value pairs should be treated as the
    **complete list** (`inclusive`) or the **minimum list** (`minimum`) of
    attribute/value pairs for the user. Defaults to `minimum`.
    Valid values are `inclusive`, `minimum`. 

- **attributes**
    Specify AIX attributes for the user in an array of attribute = value
    pairs.
Requires features manages_aix_lam.

- **auth_membership**
    Whether specified auths should be considered the **complete list**
    (`inclusive`) or the **minimum list** (`minimum`) of auths the user
    has. Defaults to `minimum`.
Valid values are `inclusive`, `minimum`. 

- **auths**
    The auths the user has.  Multiple auths should be
    specified as an array.
Requires features manages_solaris_rbac.

- **comment**
    A description of the user.  Generally the user's full name.

- **ensure**
    The basic state that the object should be in.
    Valid values are `present`(存在), `absent`(不存在), `role`.(角色)   

- **expiry**
    The expiry date for this user. Must be provided in
    a zero-padded YYYY-MM-DD format --- e.g. 2010-02-19.
    If you want to make sure the user account does never
    expire, you can pass the special value `absent`.
    Valid values are `absent`. Values can match `/^\d{4}-\d{2}-\d{2}$/`.
    Requires features manages_expiry.

- **forcelocal**
    Forces the mangement of local accounts when accounts are also
    being managed by some other NSS
    Valid values are `true`, `false`, `yes`, `no`. 
    Requires features libuser.

- **gid**
    The user's primary group.  Can be specified numerically or by name.
    This attribute is not supported on Windows systems; use the `groups`
    attribute instead. (On Windows, designating a primary group is only
    meaningful for domain accounts, which Puppet does not currently manage.)

- **groups**
    The groups to which the user belongs.  The primary group should
    not be listed, and groups should be identified by name rather than by
    GID.  Multiple groups should be specified as an array.

- **home**
    The home directory of the user.  The directory must be created
    separately and is not currently checked for existence.

- **ia_load_module**
    The name of the I&A module to use to manage this user.
    Requires features manages_aix_lam.

- **iterations**
    This is the number of iterations of a chained computation of the
    password hash (http://en.wikipedia.org/wiki/PBKDF2).  This parameter
    is used in OS X. This field is required for managing passwords on OS X
    >= 10.8.
Requires features manages_password_salt.

- **key_membership**
    Whether specified key/value pairs should be considered the
    **complete list** (`inclusive`) or the **minimum list** (`minimum`) of
    the user's attributes. Defaults to `minimum`.
    Valid values are `inclusive`, `minimum`. 

- **keys**
    Specify user attributes in an array of key = value pairs.
    Requires features manages_solaris_rbac.

- **managehome**
    Whether to manage the home directory when managing the user.
    This will create the home directory when `ensure => present`, and
    delete the home directory when `ensure => absent`. Defaults to `false`.
    Valid values are `true`, `false`, `yes`, `no`. 

- **membership**
    Whether specified groups should be considered the **complete list**
    (`inclusive`) or the **minimum list** (`minimum`) of groups to which
    the user belongs. Defaults to `minimum`.
    Valid values are `inclusive`, `minimum`. 

- **name**
    The user name. While naming limitations vary by operating system,
    it is advisable to restrict names to the lowest common denominator,
    which is a maximum of 8 characters beginning with a letter.
    Note that Puppet considers user names to be case-sensitive, regardless
    of the platform's own rules; be sure to always use the same case when
    referring to a given user.

- **password**
    The user's password, in whatever encrypted format the local
    system requires.
    * Most modern Unix-like systems use salted SHA1 password hashes. You can
    use
      Puppet's built-in `sha1` function to generate a hash from a password.
    * Mac OS X 10.5 and 10.6 also use salted SHA1 hashes.
    * Mac OS X 10.7 (Lion) uses salted SHA512 hashes. The Puppet Labs
    [stdlib][]
      module contains a `str2saltedsha512` function which can generate
    password
      hashes for Lion.
    * Mac OS X 10.8 and higher use salted SHA512 PBKDF2 hashes. When
      managing passwords on these systems the salt and iterations properties
      need to be specified as well as the password.
    * Windows passwords can only be managed in cleartext, as there is no
    Windows API
      for setting the password hash.
    [stdlib]: https://github.com/puppetlabs/puppetlabs-stdlib/
    Be sure to enclose any value that includes a dollar sign ($) in single
    quotes (') to avoid accidental variable interpolation.
    Requires features manages_passwords.

- **password_max_age**
    The maximum number of days a password may be used before it must be
    changed.
Requires features manages_password_age.

- **password_min_age**
    The minimum number of days a password must be used before it may be
    changed.
Requires features manages_password_age.

- **profile_membership**
    Whether specified roles should be treated as the **complete list**
    (`inclusive`) or the **minimum list** (`minimum`) of roles
    of which the user is a member. Defaults to `minimum`.
    Valid values are `inclusive`, `minimum`. 

- **profiles**
    The profiles the user has.  Multiple profiles should be
    specified as an array.
Requires features manages_solaris_rbac.

- **project**
    The name of the project associated with a user.
    Requires features manages_solaris_rbac.

- **purge_ssh_keys**
    Purge ssh keys authorized for the user
    if they are not managed via ssh_authorized_keys. When true,
    looks for keys in .ssh/authorized_keys in the user's home
    directory. Possible values are true, false, or an array of
    paths to file to search for authorized keys. If a path starts
    with ~ or %h, this token is replaced with the user's home directory.
    Valid values are `true`, `false`. 

- **role_membership**
    Whether specified roles should be considered the **complete list**
    (`inclusive`) or the **minimum list** (`minimum`) of roles the user
    has. Defaults to `minimum`.
Valid values are `inclusive`, `minimum`. 

- **roles**
    The roles the user has.  Multiple roles should be
    specified as an array.
Requires features manages_solaris_rbac.

- **salt**
    This is the 32 byte salt used to generate the PBKDF2 password used in
    OS X. This field is required for managing passwords on OS X >= 10.8.
    Requires features manages_password_salt.

- **shell**
    The user's login shell.  The shell must exist and be
    executable.
    This attribute cannot be managed on Windows systems.
    Requires features manages_shell.

- **system**
    Whether the user is a system user, according to the OS's criteria;
    on most platforms, a UID less than or equal to 500 indicates a system
    user. Defaults to `false`.
    Valid values are `true`, `false`, `yes`, `no`. 

- **uid**
    The user ID; must be specified numerically. If no user ID is
    specified when creating a new user, then one will be chosen
    automatically. This will likely result in the same user having
    different UIDs on different systems, which is not recommended. This is
    especially noteworthy when managing the same user on both Darwin and
    other platforms, since Puppet does UID generation on Darwin, but
    the underlying tools do so on other platforms.
    On Windows, this property is read-only and will return the user's
    security identifier (SID).

Providers
---------
    aix, directoryservice, hpuxuseradd, ldap, pw, user_role_add, useradd,
    windows_adsi
[root@centos7 ~]# vim chenxi.pp   定义

group{'cx':
        ensure => present,
}
user{'myuser':
        ensure => present,
        groups => cx,
        shell => '/bin/tcsh',
        comment => 'test user',
}
[root@centos7 ~]# puppet apply -v --noop chenxi.pp 
Notice: Compiled catalog for centos7.3-chenxi3 in environment production in 0.22 seconds
Info: Applying configuration version '1506252308'
Notice: /Stage[main]/Main/User[myuser]/ensure: current_value absent, should be present (noop)
Notice: Class[Main]: Would have triggered 'refresh' from 1 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.04 seconds

`[root@centos7 ~]# puppet apply -v --noop chenxi.pp   测试
Notice: Compiled catalog for centos7.3-chenxi3 in environment production in 0.22 seconds
Info: Applying configuration version '1506252308'
Notice: /Stage[main]/Main/User[myuser]/ensure: current_value absent, should be present (noop)
Notice: Class[Main]: Would have triggered 'refresh' from 1 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.04 seconds
有意把 组删掉
[root@centos7 ~]# groupdel cx   删掉组的定义
[root@centos7 ~]# puppet apply -v --noop chenxi.pp   重行运行此资源
Notice: Compiled catalog for centos7.3-chenxi3 in environment production in 0.23 seconds
Info: Applying configuration version '1506252597'
Notice: /Stage[main]/Main/Group[cx]/ensure: current_value absent, should be present (noop)  创建组
Notice: /Stage[main]/Main/User[myuser]/ensure: current_value absent, should be present (noop) 创建用户
Notice: Class[Main]: Would have triggered 'refresh' from 2 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.04 seconds
[root@centos7 ~]# puppet apply -v  chenxi.pp   创建组与用户
Notice: Compiled catalog for centos7.3-chenxi3 in environment production in 0.22 seconds
Info: Applying configuration version '1506252827'
Notice: /Stage[main]/Main/Group[cx]/ensure: created
Notice: /Stage[main]/Main/User[myuser]/ensure: created
Notice: Finished catalog run in 0.21 seconds
查看结果
[root@centos7 ~]# tail -n 2 /etc/{passwd,group}
==> /etc/passwd <==
puppet:x:52:52:Puppet:/var/lib/puppet:/sbin/nologin
myuser:x:1001:1002:test user:/home/myuser:/bin/tcsh

==> /etc/group <==
cx:x:1001:myuser
myuser:x:1002:
删除用户用户与组之后重新定义
[root@centos7 ~]# cat chenxi.pp   把组定义在用户之后而用户有依赖组
user{'myuser':
    ensure => present,
    groups => cx,
    shell => '/bin/tcsh',
    comment => 'test user',
}

group{'cx':
    ensure => present,
}
[root@centos7 ~]# puppet apply -v --noop chenxi.pp 
Notice: Compiled catalog for centos7.3-chenxi3 in environment production in 0.23 seconds
Info: Applying configuration version '1506253416'
Notice: /Stage[main]/Main/Group[cx]/ensure: current_value absent, should be present (noop)  它会自动检查依赖的,先定义组,而后定义用户
Notice: /Stage[main]/Main/User[myuser]/ensure: current_value absent, should be present (noop)
Notice: Class[Main]: Would have triggered 'refresh' from 2 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.04 seconds
如果不是很明确的话还可以手动指定先运行谁后运行谁
关系元参数:before/require
                    A before B: B依赖于A,定义在A资源中;
                        {
                            ...
                            before  => Type['B'],
                            ...
                        }
                    B require A: B依赖于A,定义在B资源中;
                        {
                            ...
                            require => Type['A'],
                            ...
                        }
                        
                package:
                    Manage packages.
[root@centos7 ~]# cat chenxi.pp 
user{'myuser':
    ensure => present,
    groups => cx,
    shell => '/bin/tcsh',
    comment => 'test user',
    managehome => true,
#   require => Group['cx'],   表示此资源依赖于Group[cx]
}

group{'cx':
    ensure => present,
#   before => User['myuser'], # 表示此资源要先于User资源
}
Group['cx'] -> User['myuser']  表示先运行Group资源
[root@centos7 ~]# puppet apply -v --noop chenxi.pp 
Notice: Compiled catalog for centos7.3-chenxi3 in environment production in 0.22 seconds
Info: Applying configuration version '1506258232'
Notice: /Stage[main]/Main/Group[cx]/ensure: current_value absent, should be present (noop)
Notice: /Stage[main]/Main/User[myuser]/ensure: current_value absent, should be present (noop)
Notice: Class[Main]: Would have triggered 'refresh' from 2 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.05 seconds

https://docs.puppet.com/puppet/5.2/cheatsheet_core_types.html 官网的定义

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 206,311评论 6 481
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 88,339评论 2 382
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 152,671评论 0 342
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 55,252评论 1 279
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 64,253评论 5 371
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,031评论 1 285
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,340评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,973评论 0 259
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,466评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,937评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,039评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,701评论 4 323
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,254评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,259评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,485评论 1 262
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,497评论 2 354
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,786评论 2 345

推荐阅读更多精彩内容