• ansible User 模块


    文章目录

    User 模块

    功能:系统用户管理

    官方文档:https://docs.ansible.com/ansible/latest/modules/user_module.html#user-module

    常用参数:

    参数选项/默认值说明
    password输入密码信息(password设置密码时不能使用明文方式,只能使用密文方式,可以给用户设置密码 还可以给用户修改密码)
    name指定用户名
    systemyes/no创建一个用户并设置这个用户为系统用户,这个设置不能更改现在的用户
    uid指定用户 uid 信息
    group指定用户所属组
    groups指定用户所属附加组
    shell/bin/bash或/sbin/nologin指定用户是否可以登陆
    create_homeyes/no是否创建家目录
    move_homeyes/no假如此用户已经存在,yes为覆盖家目录,no为创建为此用户创建另外一个家目录,两个家目录通过uid区分
    home指定家目录创建在什么路径 默认/home
    state指定用户状态
    state=presentpresent 为创建
    state=absentabsent 为删除
    removeyes/noremove=yes 则表示在删除(state=absent)用户时同时删除用户家目录,remove=no 则表示不删除
    generate_ssh_key=yes创建用户的同时是否为此用户创建ssh密钥文件

    password 密码加密方式:

    参考官网地址:https://docs.ansible.com/ansible/latest/reference_appendices/faq.html#how-do-i-generate-encrypted-passwords-for-the-user-module

    # 安装 python 工具
    [root@master ~]# yum -y install python-pip
    [root@master ~]# pip install --upgrade pip
    [root@master ~]# pip install passlib
    
    [root@master ~]# python -c "from passlib.hash import sha512_crypt; import getpass; print(sha512_crypt.using(rounds=5000).hash(getpass.getpass()))"
    Password: 
    $6$i36wkjavj/M/K/2T$EUFdeExIDsZgCzWH3ckYNKoau0BFr3FZ.8g9tjq/A8unFThrpS1iBJ0Ou3ikjl0KgozKA12GDGqdLH06bCIPR/
    
    注意:这里的 $ 符在使用时需要使用 \$ 转义
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    示例:

    • 新增一个用户,指定密码,设置家目录,并且禁止远程登陆
    [root@master ~]# ansible dong -m user -a "name=123 password=\$6\$i36wkjavj/M/K/2T\$EUFdeExIDsZgCzWH3ckYNKoau0BFr3FZ.8g9tjq/A8unFThrpS1iBJ0Ou3ikjl0KgozKA12GDGqdLH06bCIPR/ create_home=yes home=/data shell=/sbin/nologin"
    
    • 1
    • 删除一个用户
    [root@master ~]# ansible dong -m user -a "name=123 state=absent remove=yes"
    
    • 1

     
     
     
     
     

  • 相关阅读:
    面试题:说说Java并发运行中的一些安全问题
    常用类面试题总结(一)
    靠近用户侧和数据,算网融合实现极致协同
    idea,web开发中jsp页面中不提示控制层的请求地址
    c#怎么折叠代码快捷
    Linux中的服务管理
    ViP-LLaVA: Making Large Multimodal Models Understand Arbitrary Visual Prompts
    IDEA中SVN 的使用
    前端文件上传的几种交互造轮子
    Flex布局使用
  • 原文地址:https://blog.csdn.net/D1179869625/article/details/126195688