AllInfo
Main: Info Blog Temp Mail


wrk 2024-12-05 11-47-49

  % cat creau.yml 
 ---
- name: Создание пользователя с правами
  hosts: all
  become: yes
  vars:
    username: prg  # Имя пользователя, которое можно изменить

  tasks:
    - name: Создание пользователя
      user:
        name: "{{ username }}"
        password: "{{ '123456' | password_hash('sha512') }}"
        shell: /bin/bash
        create_home: yes
        groups: wheel

    - name: Настройка sudo без пароля
      lineinfile:
        path: /etc/sudoers
        line: "{{ username }} ALL=(ALL) NOPASSWD: ALL"
        state: present

    - name: Добавление SSH-ключа для нового пользователя
      authorized_key:
        user: "{{ username }}"
        state: present
        key: "{{ lookup('file', lookup('env', 'HOME') + '/.ssh/id_rsa.pub') }}"
                                                                                                                                                                                               
0:root@ans:~/my/ans-c7-user-crea % cat go.sh 
#!/bin/bash


if [ -z "$MYPWD" ]; then  echo "Pass not set: read -s MYPWD ; export MYPWD "; exit 1 ; fi 
ansible-playbook -i hosts --extra-vars "ansible_connection=ssh ansible_ssh_user=root ansible_become_pass=$MYPWD ansible_ssh_pass=$MYPWD" creau.yml

2024-12-05_11-48-46


3.145.79.214 / 2024-12-22_20-59-18 UTC.