본문 바로가기

Automation Tools/Ansible

8.1 ansible | [playbook] Linux user 추가

반응형

linux ssh를 통해 user를 생성 하고 sudo 권한을 추가

---
- name: "user add"
  hosts: all
  # sudo 권한 획득
  become: true
  tasks:
    - name: "user add" 
      user:
        name: "{{ add_user_name }}"
        password: "{{ upassword | password_hash('sha512') }}"
        shell: "/bin/bash"
    - name: "Add user to sudoers"
      lineinfile:
        dest: /etc/sudoers
        regexp: "{{ add_user_name }}   ALL"
        line: "{{ add_user_name }}   ALL=(ALL)   NOPASSWD: ALL"
        state: present
  #vars:
  #  add_user_name: test3
  #  upassword: test1212

 

 

 

반응형