From ab2a10806896090e499b7692bc6e04e2828b6dcf Mon Sep 17 00:00:00 2001 From: Oscar Pocock Date: Thu, 7 Apr 2022 21:35:41 +0100 Subject: [PATCH] Added code to create user --- ansible.cfg | 5 +++++ group_vars/all/vars.yml | 6 ++++++ hosts | 2 ++ run.yml | 11 +++++++++++ tasks/base.yml | 36 +++++++++++++++++++++++++++++++++++ tasks/docker.yml | 18 ++++++++++++++++++ tasks/unattended-upgrades.yml | 4 ++++ 7 files changed, 82 insertions(+) create mode 100644 ansible.cfg create mode 100644 group_vars/all/vars.yml create mode 100644 hosts create mode 100644 run.yml create mode 100644 tasks/base.yml create mode 100644 tasks/docker.yml create mode 100644 tasks/unattended-upgrades.yml diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..eecbc51 --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,5 @@ +[defaults] +INVENTORY = hosts + +[ssh_connections] +pipelining = true \ No newline at end of file diff --git a/group_vars/all/vars.yml b/group_vars/all/vars.yml new file mode 100644 index 0000000..716440e --- /dev/null +++ b/group_vars/all/vars.yml @@ -0,0 +1,6 @@ +username: noble +packages: + - vim + - htop + - neofetch + - tmux \ No newline at end of file diff --git a/hosts b/hosts new file mode 100644 index 0000000..ca95b46 --- /dev/null +++ b/hosts @@ -0,0 +1,2 @@ +[home] +void ansible_host=192.168.1.193 ansible_user=ansible ansible_connection=ssh ansible_ssh_private_key_file=/home/noble/.ssh/ansible \ No newline at end of file diff --git a/run.yml b/run.yml new file mode 100644 index 0000000..d67f68a --- /dev/null +++ b/run.yml @@ -0,0 +1,11 @@ +--- +- hosts: void + become: yes + + tasks: + - name: Print information + debug: + msg: "Release version: {{ ansible_distribution_release }}" + + - import_tasks: tasks/base.yml + - import_tasks: tasks/docker.yml \ No newline at end of file diff --git a/tasks/base.yml b/tasks/base.yml new file mode 100644 index 0000000..19083d3 --- /dev/null +++ b/tasks/base.yml @@ -0,0 +1,36 @@ +- name: Update packages + apt: + update_cache: yes + upgrade: yes + state: latest + +- name: Install essential packages + apt: + pkg: "{{ packages }}" + update_cache: yes + state: latest + +- name: Add the user "{{ username }}" + user: + name: "{{ username }}" + shell: /bin/bash + groups: sudo + append: yes + +- name: Set authorized ssh key for user "{{ username }}" + authorized_key: + user: "{{ username }}" + state: present + key: "{{ lookup('file', '/home/noble/.ssh/nexus-to-pi.pub') }}" + +- name: Enable passwordless sudo for ansible + lineinfile: + path: /etc/sudoers + state: present + regexp: '^ansible' + line: 'ansible ALL=(ALL) NOPASSWD:ALL' + validate: /usr/sbin/visudo -cf %s + +- name: Set hostname to void + hostname: + name: void \ No newline at end of file diff --git a/tasks/docker.yml b/tasks/docker.yml new file mode 100644 index 0000000..1c6d3f0 --- /dev/null +++ b/tasks/docker.yml @@ -0,0 +1,18 @@ +- name: Install dependencies + package: + name: + - ca-certificates + - curl + - gnupg + - lsb-release + +- name: Add Docker GPG key + apt_key: + url: https://download.docker.com/linux/raspbian/gpg + keyring: /usr/share/keyrings/docker-archive-keyring.gpg + state: present + +- name: Add Docker repository + apt_repository: + repo: https://download.docker.com/linux/raspbian {{ ansible_distribution_release }} stable + state: present diff --git a/tasks/unattended-upgrades.yml b/tasks/unattended-upgrades.yml new file mode 100644 index 0000000..3778a34 --- /dev/null +++ b/tasks/unattended-upgrades.yml @@ -0,0 +1,4 @@ +- name: Install unattended-upgrades + package: + name: + - unattended-upgrades \ No newline at end of file