zoukankan      html  css  js  c++  java
  • Ansible 创建用户 Playbook 脚本

    创建用户,设置wheel组sudo不需要密码,然后将用户添加到wheel组,并将用户的公钥传输到节点上:

    ---
    - name: Linux Create User and Upload User Public keys
      hosts: test
      #remote_user: xxxx
      #sudo: yes
      vars:
          user_1: xiaoxiaoleo
      tasks:
        - name: Make sure we have a 'wheel' group
          group:
            name: wheel
            state: present
    
        - name: Allow 'wheel' group to have passwordless sudo
          lineinfile:
            dest: /etc/sudoers
            state: present
            regexp: '^%wheel'
            line: '%wheel ALL=(ALL) NOPASSWD: ALL'
    
        - name: Create user {{ user_1 }}
          user:
            name: "{{ user_1 }}"
            shell: /bin/bash
            groups: wheel
            createhome: yes
            home: /home/{{ user_1 }}
            state: present
    
        - name: create key directory
          action: file path=/home/{{ user_1 }}/.ssh/ state=directory  owner={{ user_1 }} group={{ user_1 }} mode=0700
    
        - name: create key file
          action: file path=/home/{{ user_1 }}/.ssh/authorized_keys state=touch  owner={{ user_1 }} group={{ user_1 }} mode=0600
           
    
        - name: Set authorized key took from file
          authorized_key:
            user: "{{ user_1 }}"
            state: present
            key: "{{ lookup('file', '/tmp/pubkey/id_rsa.pub') }}"
    
    
    

      

  • 相关阅读:
    洛谷⑨月月赛Round2 官方比赛 OI
    3243 区间翻转
    3279 奶牛健美操
    1959 拔河比赛
    2144 砝码称重 2
    BZOJ1999 树网的核[数据加强版]
    U4704 函数
    U4687 不无聊的序列
    U4699 鸡蛋
    UVA 11212 Editing a Book
  • 原文地址:https://www.cnblogs.com/xiaoxiaoleo/p/6539433.html
Copyright © 2011-2022 走看看