Skip to content

Instantly share code, notes, and snippets.

@jnovack
Last active August 21, 2020 15:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnovack/bd7b4f052e3a74f18b47c293f0b9a252 to your computer and use it in GitHub Desktop.
Save jnovack/bd7b4f052e3a74f18b47c293f0b9a252 to your computer and use it in GitHub Desktop.
ansible bootstrap a clean installation
---
- name: Bootstrap Alpine
hosts: all
gather_facts: false
become: no
vars:
ansible_python_interpreter: auto_silent
tasks:
## Alpine does not have python3 installed, must install raw.
- name: Install pre-requisities
raw: apk update && apk add --no-cache python3
## Once python3 is installed, we can continue with the rest of the boostrapping.
- name: Import bootstrap.yml
import_playbook: bootstrap.yml
---
- name: Bootstrap
hosts: all
gather_facts: false
become: no
vars:
ansible_python_interpreter: auto_silent
tasks:
- name: Install base packages
package: name={{ item }} state=present
loop: [ 'sudo' ]
- name: set sshd service to start on boot
service:
name: sshd
state: started
enabled: yes
runlevel: default
- name: create ansible user
user:
name: ansible
comment: ansible
password: ''
- name: Add ssh-key as authorized_key for ansible
authorized_key:
user: ansible
state: present
key: "{{ lookup('file', lookup('env','HOME') + '/.ssh/id_rsa.pub') }}"
- name: Permit ansible to sudo
lineinfile:
path: /etc/sudoers.d/ansible
state: present
create: yes
regexp: '^ansible.*'
line: 'ansible ALL=(ALL) NOPASSWD: ALL'
validate: '/usr/sbin/visudo -cf %s'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment