~dvshkn/scripts

ref: 1a62835f3fc98d9d09d379213ae8ddecb806a62e scripts/playbooks/setup_new_droplet.yml -rw-r--r-- 1.1 KiB
1a62835fDavid Knight add setup_new_droplet.yml playbook 1 year, 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
---
- hosts: ip_addr
  remote_user: root

  vars_prompt:
    - name: username
      prompt: "new username"
      private: no
    - name: password
      prompt: "new password"
      private: yes
      encrypt: "sha512_crypt"
      confirm: yes
      salt_size: 16

  tasks:
  - name: test if user exists
    command: "ls -d /home/{{ username }}"
    register: home_dir_test
  - name: ensure that the user exists
    user:
      name: "{{ username }}"
      state: present
      create_home: yes
      append: yes
      groups: sudo
      shell: /bin/bash
      password: "{{ password }}"
      # uncomment to not override existing passwords
      # update_password: on_create
  - name: create .ssh dir
    file:
      path: "/home/{{ username }}/.ssh"
      state: directory
      owner: "{{ username }}"
      group: "{{ username }}"
  - name: install copy of authorized_keys from root
    copy:
      src: /root/.ssh/authorized_keys
      dest: "/home/{{ username }}/.ssh/authorized_keys"
      remote_src: yes
      owner: "{{ username }}"
      group: "{{ username }}"
  - name: reminder to disable root login
    debug:
      msg: "REMEMBER TO DISABLE SSH ROOT LOGIN!"