Skip to content

Commit 0b54b65

Browse files
committed
feat: add coding projects role
1 parent eda933d commit 0b54b65

File tree

5 files changed

+100
-0
lines changed

5 files changed

+100
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This Ansible collection provides a set of roles designed for configuring Kubuntu
99
| Role | Description | Dependencies |
1010
| -------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------ |
1111
| [xebis.ansible.apt](roles/apt/README.md) | Deb package updates and upgrades using the apt package manager. Can optionally clean up unused packages and reboot the system if required. | `xebis.ansible.system` |
12+
| [`xebis.ansible.coding_projects`](roles/coding_projects/README.md) | Creates and clones coding projects to `~/Projects` | `xebis.ansible.apt` |
1213
| [xebis.ansible.grub](roles/grub/README.md) | GRUB menu configuration. | |
1314
| `xebis.ansible.fail2ban` | Fail2ban IPS | `xebis.ansible.apt` |
1415
| `xebis.ansible.google_chrome` | Google Chrome (Stable) | `xebis.ansible.apt` |

roles/coding_projects/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Xebis.Ansible.Coding_Projects
2+
3+
Creates and clones coding projects to `~/Projects`.
4+
5+
## Tasks
6+
7+
- Installs `git`
8+
- Sets git user and email
9+
- Creates `~/Projects` directory and subdirectory for each _owner_
10+
- Adds GitHub.com fingerprints to SSH known hosts
11+
- Clones all repositories (only if not already cloned)
12+
13+
Example play:
14+
15+
```yaml
16+
---
17+
- hosts: all
18+
roles:
19+
- role: xebis.ansible.coding_projects
20+
vars:
21+
repositories:
22+
- owner: xebis
23+
name: ansible-collection
24+
```
25+
26+
## Variables
27+
28+
- `repositories` \[[{owner, name}, ...]]
29+
- Repositories to clone. Owner and name have to be valid GitHub owner and repository and the repository has to be initialized.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
dependencies:
3+
- role: xebis.ansible.apt # Expects updated apt cache
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
- name: Install git
3+
become: true
4+
ansible.builtin.apt:
5+
name: git
6+
state: latest
7+
8+
- name: Set up git user name
9+
community.general.git_config:
10+
name: user.name
11+
value: Martin Bruzina
12+
scope: global
13+
state: present
14+
15+
- name: Set up git user email
16+
community.general.git_config:
17+
name: user.email
18+
value: martin@bruzina.cz
19+
scope: global
20+
state: present
21+
22+
- name: Create Projects directory
23+
ansible.builtin.file:
24+
path: "~/Projects"
25+
state: directory
26+
mode: '0755'
27+
28+
- name: Create owner directory
29+
ansible.builtin.file:
30+
path: "~/Projects/{{ item.owner }}"
31+
state: directory
32+
mode: "0755"
33+
loop: "{{ repositories }}"
34+
loop_control:
35+
label: "{{ item.owner }}/{{ item.name }}"
36+
37+
- name: Add GitHub.com to known hosts
38+
ansible.builtin.known_hosts:
39+
name: github.com
40+
key: "{{ lookup('pipe', 'ssh-keyscan github.com') }}"
41+
hash_host: true
42+
state: present
43+
44+
- name: Clone repository (only if not already cloned)
45+
ansible.builtin.git:
46+
repo: "git@github.com:{{ item.owner }}/{{ item.name }}"
47+
dest: "~/Projects/{{ item.owner }}/{{ item.name }}"
48+
version: HEAD
49+
update: no
50+
loop: "{{ repositories }}"
51+
loop_control:
52+
label: "{{ item.owner }}/{{ item.name }}"

test.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,19 @@
3232
- role: xebis.ansible.google_chrome
3333
- role: xebis.ansible.obsidian
3434
- role: xebis.ansible.openssh_client
35+
- role: xebis.ansible.coding_projects
36+
vars:
37+
repositories:
38+
- owner: xebis
39+
name: .github
40+
- owner: xebis
41+
name: ansible-collection
42+
- owner: xebis
43+
name: github-actions-and-workflows
44+
- owner: xebis
45+
name: github-organization-as-code
46+
- owner: xebis
47+
name: hetzner-iac-cac
48+
- owner: xebis
49+
name: infra
3550
- role: xebis.ansible.visual_studio_code

0 commit comments

Comments
 (0)