Skip to content
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
23 changes: 9 additions & 14 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name: Test Developer Environment Setup
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ '*' ]
branches: [ '**' ]
pull_request:
branches: [ master ]

Expand All @@ -15,22 +15,17 @@ on:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:

# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
strategy:
matrix:
fedora_version: [43]

steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

# Runs a single command using the runners shell
- name: Test Deployment
run: echo Test Deployment

# Runs a set of commands using the runners shell
- name: Test Deployment 33
run: test/test.sh 33
- name: Test Deployment 34
run: test/test.sh 34
- uses: actions/checkout@v4
- name: Test Deployment Fedora ${{ matrix.fedora_version }}
run: test/test.sh ${{ matrix.fedora_version }} all
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.venv
secrets.json
*.retry
.idea/
.vagrant/
Expand Down
52 changes: 40 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# developer-environment-setup

[![Test Developer Environment Setup](https://github.com/ottenwbe/developer-environment-setup/actions/workflows/main.yml/badge.svg)](https://github.com/ottenwbe/developer-environment-setup/actions/workflows/main.yml)

This ansible playbook is used by me to automate the setup of my Linux developer machines.
If you frequently reinstall your system, you know why these scripts had been created.
If you frequently reinstall your system, you know why these scripts were created.
Therefore, this repository will be updated whenever I setup a new machine (commits to master).

## Supported Linux Distributions

Right now the only tested Distributions are:
* Fedora 33
* Fedora 34
* Fedora 43

## Structure

Expand All @@ -21,11 +22,15 @@ Right now the only tested Distributions are:
│   ├── common // Installation of common tools, external repos (rpm-fusion...), etc.
│   ├── user // Creation of users
│   ├── zsh // Installation of zsh for each user
│   ├── vscode // Installation of Visual Studio Code
│   ├── ansible // Installation of Ansible and linting tools
│   ├── cpp // Everything needed for C(pp) development
│   ├── go // Everything needed for Golang development
│   ├── java // Everything needed for Java development
│   ├── kubernetes // Everything needed for Kubernetes development (minikube, helm, ...)
│   ├── python // Everything needed for Python development
│   └── ruby // Everything needed for Ruby development
│   └── virtualization // Virtualization tools (VirtualBox, Vagrant)
└── test/ // Test the playbook in docker images
└── docker/
```
Expand All @@ -42,20 +47,43 @@ The ```bootstrap_local.sh``` script installs ansible as a prerequisite for execu
On a local Fedora installation where ansible is __not__ installed the playbook can be executed as follows:

```bash
sh bootstrap_local.sh hosts <your user> Fedora
sh bootstrap_local.sh inventory.yml <your user> Fedora
```

On a local Linux installation where ansible is installed the playbook can be executed as follows:
```bash
ansible-playbook -i hosts site.yml --connection=local --extra-vars '{"users": ["your user"]}' --ask-become-pass
ansible-playbook -i inventory.yml site.yml --connection=local --extra-vars '{"users": [{"username": "your user", "git_name": "Your Name", "git_email": "email@example.com"}]}' --ask-become-pass
```

### Go Specific Details
## Tags

The playbook uses tags to allow running specific parts of the setup.

Available tags:
* system: Runs all system setup roles (user, zsh, vscode, ansible, common)
* dev: Runs all development environment roles (go, java, ruby, cpp, python, kubernetes, virtualization)
* user: User creation and configuration
* zsh: ZSH shell setup
* vscode: Visual Studio Code installation
* ansible: Ansible installation
* common: Common tools and repositories
* go: Go development environment
* java: Java development environment
* ruby: Ruby development environment
* cpp: C++ development environment
* python: Python development environment
* kubernetes: Kubernetes tools (Minikube, Helm, etc.)
* virtualization: Virtualization tools (VirtualBox, Vagrant)

To run only specific tags:
```bash
ansible-playbook -i inventory.yml site.yml ... --tags "tag1,tag2"
```

You can specify a specific go version to install.
Or using the bootstrap script (4th argument):

```yaml
"go_version": "1.17.1.linux-amd64"
```bash
sh bootstrap_local.sh inventory.yml <extra-vars> Fedora "tag1,tag2"
```

## Testing
Expand All @@ -73,14 +101,14 @@ chcon -Rt svirt_sandbox_file_t "${PWD}"
On a non SELinux you can simply build a docker image and execute the playbook in a container. Replace one of the 'testuser's' with a username that suits you and run the following commands:

```bash
docker build --file=test/docker/Dockerfile.fedora --build-arg "FEDORA_VERSION=33" --tag=fedora33:ansible test/docker
docker run --name=test-fedora --volume="${PWD}":/home/ansible:ro fedora33:ansible ansible-playbook -i /home/ansible/test/docker/test_hosts /home/ansible site.yml --connection=local --become --extra-vars '{"users": ["testuser1","testuser2"], "go_version": "1.17.2.linux-amd64" "}' --skip-tags "systemd"
docker build --file=test/docker/Dockerfile.fedora --build-arg "FEDORA_VERSION=43" --tag=fedora43:ansible test/docker
docker run --name=test-fedora --rm --volume="${PWD}":/home/ansible:ro fedora43:ansible ansible-playbook -i /home/ansible/test/docker/inventory.yml /home/ansible/site.yml --connection=local --become --extra-vars '{"users": [{"username": "testuser1"}, {"username": "testuser2"}]}' --skip-tags "common"
```

or simply use the test scripts

```bash
sh test/test.sh 33
sh test/test.sh 43 all
```

__Note__: We skip everything related to systemd, since systemd is not monitoring our services in the container.
Expand Down
37 changes: 23 additions & 14 deletions bootstrap_local.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,42 @@
#!/usr/bin/env bash

echo "== BEGIN BOOTSTRAP =="
# Ensure we are in the script directory
cd "$(dirname "$0")"

hostfile=$1
user=$2
system=$3
inventoryfile=${1:-}
extra_vars=${2:-}
system=${3:-Fedora}
tags=${4:-all}
start_sshd=${5:-true}

set -uex pipefail

if [ -z "${hostfile}" -o -z "${user}" ] ; then
echo "usage: ./bootstrap_local.sh <path-to-host-file> <user> [<Fedora>]"
if [ -z "${inventoryfile}" ] || [ -z "${extra_vars}" ] ; then
echo "usage: ./bootstrap_local.sh <path-to-host-file> <extra-vars-json> [<Fedora> [<all|tag1,tag2> [<start_sshd>]]]"
exit 1
fi

if [ -z "${system}" ] ; then
system="Fedora"
fi

echo "== BEGIN BOOTSTRAP =="
echo "== SETUP ${system} =="
if [ "${system}" == "Fedora" ] ; then
echo "== Ensure Python on Fedora=="
sudo dnf -y install python3 python3-pip
echo "== Start ssh service on Fedora=="
sudo systemctl start sshd
if [ "${start_sshd}" == "true" ]; then
echo "== Start ssh service on Fedora=="
sudo systemctl start sshd
fi
fi

echo "== SETUP VIRTUAL ENVIRONMENT =="
if [ ! -d ".venv" ]; then
python3 -m venv .venv
fi
source .venv/bin/activate

echo "== INSTALL ANSIBLE (AND PREREQUISITES)=="
pip3 install -r requirements.txt
pip install --upgrade pip
pip install -r requirements.txt

ansible-playbook -i hosts site.yml --connection=local --extra-vars "{\"users\": [\"${user}\"]}" --ask-become-pass
ansible-playbook -i "${inventoryfile}" site.yml --connection=local --extra-vars "${extra_vars}" --become --tags "${tags}"

echo "== END BOOTSTRAP =="
2 changes: 0 additions & 2 deletions hosts

This file was deleted.

6 changes: 6 additions & 0 deletions inventory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
all:
children:
Laptop:
hosts:
127.0.0.1:
ansible_connection: local
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
docker==4.0.1
markupsafe
docker
ansible
22 changes: 16 additions & 6 deletions roles/ansible/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
---
- name: ansible - prerequisites
- name: Ansible - install ansible and linting tools
become: true
command: dnf -y install python3 python3-pip
- name: ansible - install with pip
command: pip3 install markupsafe ansible
- name: ansible - install molecule
command: pip3 install molecule
ansible.builtin.dnf:
name:
- ansible
- ansible-lint
- yamllint
state: present
- name: Ansible - create default directory structure
become: true
ansible.builtin.file:
path: "/home/{{ item.0.username }}/.ansible/{{ item.1 }}"
state: directory
owner: "{{ item.0.username }}"
group: "{{ item.0.username }}"
mode: '0755'
loop: "{{ users | product(['roles', 'collections']) | list }}"
21 changes: 20 additions & 1 deletion roles/common/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
---
---
common_packages:
- git
- git-lfs
- curl
- wget
- vim
- htop
- jq
- tree
- tmux
- fzf
- unzip
- zip
- nano
- bind-utils

common_gui_packages:
- evince
- libreoffice
16 changes: 8 additions & 8 deletions roles/common/tasks/chrome.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---
- name: chrome - add google repository
- name: Chrome - add google repository
become: true
yum_repository:
ansible.builtin.yum_repository:
name: google-chrome
description: google-chrome - $basearch
gpgcheck: yes
enabled: yes
gpgcheck: true
enabled: true
gpgkey: https://dl-ssl.google.com/linux/linux_signing_key.pub
baseurl: http://dl.google.com/linux/chrome/rpm/stable/$basearch
- name: chrome - install
baseurl: https://dl.google.com/linux/chrome/rpm/stable/$basearch
- name: Chrome - install
become: true
dnf:
ansible.builtin.dnf:
name: google-chrome-stable
state: latest
state: present
51 changes: 28 additions & 23 deletions roles/common/tasks/development.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
---
- name: dev dependencies - dnf plugins
- name: Dev dependencies - dnf plugins
become: true
dnf:
ansible.builtin.dnf:
name: dnf-plugins-core
state: latest
- name: dev dependencies - gh repos
state: present

- name: Import RPM Fusion free GPG key
become: true
command: dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
- name: install the 'Development tools' package group
ansible.builtin.rpm_key:
state: present
key: https://rpmfusion.org/keys?action=AttachFile&do=get&target=RPM-GPG-KEY-rpmfusion-free-fedora-2020
fingerprint: E9A4 91A3 DE24 7814 E7E0 67EA E06F 8ECD D651 FF2E

- name: Import RPM Fusion nonfree GPG key
become: true
dnf:
name: "@Development tools"
state: latest
- name: install the 'C Development Tools and Libraries' package group
ansible.builtin.rpm_key:
state: present
key: https://rpmfusion.org/keys?action=AttachFile&do=get&target=RPM-GPG-KEY-rpmfusion-nonfree-fedora-2020
fingerprint: 79BD B88F 9BBF 7391 0FD4 095B 6A2A F961 9484 3C65


- name: Common - install rpmfusion
become: true
dnf:
name: "@C Development Tools and Libraries"
state: latest
- name: tools - scm
ansible.builtin.dnf:
name:
- "https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-{{ ansible_distribution_major_version }}.noarch.rpm"
- "https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-{{ ansible_distribution_major_version }}.noarch.rpm"
state: present

- name: Common - install packages
become: true
package: name={{ item }} state=latest
with_items:
- git
- gh
- name: tools - virtualization
become: true
package: name={{ item }} state=latest
with_items:
- vagrant
ansible.builtin.dnf:
name: "{{ common_packages }}"
state: present
18 changes: 0 additions & 18 deletions roles/common/tasks/docker.yml

This file was deleted.

6 changes: 0 additions & 6 deletions roles/common/tasks/dropbox.yml

This file was deleted.

Loading