Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup controller #69

Merged
merged 10 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ansible/controller-playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- hosts: 127.0.0.1
connection: local
become: yes
roles:
- ssh_users
- ansible_controller
22 changes: 22 additions & 0 deletions ansible/group_vars/all/vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
ssh_users:
agrabeli:
login: agrabeli
comment: Maria Xynou
keys: ["ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDD0JSwM+t3Uz9lS3Mjoz9oo4vOToWyzboZhYQbP8JY5HvFtAvWanWHnUBO91t6hkgKIMiUqhdCJn26fqkhSGe/bRBaFUocOmuyfcmZoRdi0qzAskmycJsj/w6vWR4x6MYkmJvSeI/MGxjEFt4s2MfOG1tP8CBLUYft9qUleeJa7Jln8c+xbnqB7YngaI190icQHE9NuIB2CXvzbmo3tLtHNMagEwI7VoBDj6mxzTxBd9JhuhF4w5uGxxm0Gp1hzk+15obNnaBS+Anr7jXz8FPwwxCH+XhBZxB1PPpcIayKrf9iLyGtwmhkdDoWCqYAr1mue3LxFso+TZF4bwE4Cjt1 agrabelh@agrabelh"]
art:
login: art
comment: Arturo Filasto
keys: ["ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJsibU0nsQFFIdolD1POzXOws4VetV0ZNByINRzY8Hx0 [email protected]"]
majakomel:
login: majakomel
comment: Maja Komel
keys:
- "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC7gWQL4h/IyMbwDuMIXbTVmNEm8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el, mehul ]
non_admin_usernames: [ agrabeli ]
22 changes: 22 additions & 0 deletions ansible/roles/ansible_controller/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
- name: install base deps
ansible.builtin.apt:
name:
- "awscli"
- "etckeeper"
- "git"
- "python3-dnspython"
- "python3-boto3"
- "tmux"
- "vim"
state: "latest"
update_cache: "yes"

- name: set the hostname
ansible.builtin.hostname:
name: "ansible-controller"

- name: clone devops repo into /srv/devops
ansible.builtin.git:
repo: "https://github.com/ooni/devops.git"
dest: /srv/devops
65 changes: 65 additions & 0 deletions ansible/roles/ssh_users/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
- name: create admin users
tags: ssh_users
user:
name: "{{ item }}"
group: "admin"
comment: "{{ ssh_users[item].comment }}"
shell: /bin/bash
state: present
with_items: "{{ admin_usernames }}"

- name: create non-admin users
tags: ssh_users
user:
name: "{{ item }}"
group: "users"
comment: "{{ ssh_users[item].comment }}"
shell: /bin/bash
state: present
with_items: "{{ non_admin_usernames }}"

- name: create .ssh dir for admin users
tags: ssh_users
file:
path: "/home/{{item}}/.ssh"
state: directory
owner: "{{item}}"
group: "admin"
mode: 0700
with_items: "{{ admin_usernames }}"

- name: create .ssh dir for non-admin users
tags: ssh_users
file:
path: "/home/{{item}}/.ssh"
state: directory
owner: "{{item}}"
group: "users"
mode: 0700
with_items: "{{ non_admin_usernames }}"

- name: create .ssh/authorized_keys for each user
tags: ssh_users
template:
src: authorized_keys
dest: "/home/{{item}}/.ssh/authorized_keys"
owner: "{{item}}"
mode: 0400
with_items: "{{ admin_usernames | union(non_admin_usernames) }}"

- name: list all users currently on the system
shell: "getent passwd | awk -F: '$3 > 1000 {print $1}'"
register: user_list

- name: remove any stale users
user:
name: "{{ item }}"
state: "absent"
remove: yes
with_items: user_list.stdout_lines
when: "item != 'nobody' and item not in (admin_usernames | union(non_admin_usernames))"


- name: sudoers.d/80-admins
template: src=sudoers dest=/etc/sudoers.d/80-admins owner=root group=root mode=0440 validate='visudo -cf %s'
5 changes: 5 additions & 0 deletions ansible/roles/ssh_users/templates/authorized_keys
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# managed by ansible
# see roles/ssh_users/templates/authorized_keys
{% for k in ssh_users[item]['keys'] %}
{{ k }}
{% endfor %}
4 changes: 4 additions & 0 deletions ansible/roles/ssh_users/templates/sudoers
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# ansible-managed in roles/ssh_users/templates/sudoers
{% for username in admin_usernames %}
{{ ssh_users[username].login }} ALL=(ALL:ALL) NOPASSWD: ALL
{% endfor %}
Loading