summaryrefslogtreecommitdiff
path: root/initial-deploy.yml
blob: c0905c758023ffd8ecb223985532f410706b966d (plain)
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
---
# use: specify inventory on command line
- name: Setup Ansible user and authorized keys
  hosts: all
  gather_facts: false
  tasks:
    - name: Check for single host
      fail:
        msg: "Single host check failed."
      when: "play_hosts | length != 1"
      delegate_to: localhost
      run_once: true
    - name: Install Python if not already installed
      raw: test -e /usr/bin/python3 || (apt -y update && apt install -y python3-minimal)
      changed_when: false
      failed_when: false
    - name: Install sudo package
      package:
        name: "sudo"
        state: "present"
    - name: Setup ansible user
      user:
        name: "ansible"
        groups: "sudo"
        password: "{{ mypass | password_hash('sha512') }}"
        shell: /bin/bash
    - name: Setup Authorized keys
      ansible.posix.authorized_key:
        user: "ansible"
        state: present
        key: "{{ lookup('file', '~/.ssh/ansible.pub') }}"