# Setup Fedora Workstation Ansible


# Overview
This post covers setting up personal a Fedora Workstation with Ansible, using a playbook with setup sections broken down into roles. Tags are used for testing and to further segragate tasks when modifying a configuration element.

## Why? 
- I have been wanting to learn Ansible and there is nothing like doing the thing to help learn it.
- I went through a couple of iterations of trying out Linux distros and took several [Fedora Spins](https://spins.fedoraproject.org/) for a... spin. Automation was needed.

I thought I would share what I have to help out a fellow learner and to act as a reminder for me. The playbook is intended to be run locally on the workstation you wish to configure. It

## Requirements

{{< admonition type=info title="Requirements" open=true  >}}
- Fresh installation of Fedora Workstation.
- Tested with Fedora 38 and Gnome 44.
  - Ansible
  - Git

```shell
sudo dnf install ansible git -y
git clone git@github.com:steve-rackham/ansible-workstation.git 

```
{{< /admonition >}} 

{{< admonition type=tip title="Tip: Adjust Variables:" open=true  >}}
Adjust the variable files for global variables and for each role.
- **Global**: group_vars/all.yml
- **Role**: <role>/vars/vars.yml
  
{{< /admonition >}} 

<br>

# Playbook
The playbook defines:
- the host inventory.
  - Assumed localhost. #TODO: Add multiple hosts for automation across the home network.
- root access for operations needing administrative privelege. 
  - Use *--ask-become-pass* or *-K* for privilege escalation password.
- the roles to be called.
    - System
    - User
    - App-Packages
    - App-Config
    - Desktop-Customisation

Tags may be used to target a role or particular task.

<br>

## Usage
{{< admonition type=example title="Examples:" open=true  >}}

First:
- Update any var files and global vars as required.
- From within the ansible-workstation directory:

Then run one of the following examples: 

```shell
# Example: Run all roles and tasks on localhost:
ansible-playbook --inventory localhost site.yml -K

# Example: Run only themes tag
ansible-playbook --inventory localhost site.yml -K --tags theme

# Example: Run every but the themes tag
ansible-playbook --inventory localhost site.yml -K --skip-tags theme

```
{{< /admonition >}} 

<br>

## Roles
The following roles are utilised and are intended to run in sequence.

### 1. System
Anything system or host related.

**Tasks**:
- Set hostname.

### 2. User
User related settings and config.

**Tasks**:
- Create directory structure.
- Add SSH Keys.
- Add git config.
 
### 3. App-Packages
Installation of repos, flatpaks, and app packages.

**Tasks**:
- Add RPM and third party repos.
- Add Flatpak repo.
- Install: 
  - Drivers.
  - Gnome Packages.
  - Shell Extensions.
  - Codecs.
  - User Packages.
  - User Flatpaks.
- Remove unwanted packages.
  
### 4. App-Config
Set application settings and config.

**Tasks**:
- Install [VSCodium](https://vscodium.com/) extensions.
- Install and enable [Starship](https://starhip.rs) Prompt.


### 5. Desktop-Customisation
Set the desktop how we like it.

**Tasks**:
- Install and apply:
  - Theme.
  - Icons.
  - Cursors.
  - Wallpaper.
- Apply:
  - Common Gnome Settings.
    - FileChooser.
    - Numlock State.
  - Set Shell Extensions.
    - User Themes.
    - ArcMenu Settings.
    - Dash to Dock Settings.
    - Dash to Panel Settings.
    - Open Weather Settings.

## Tags
Tags are heavily utilised throughout the playbook so you can target or test specific areas.

### Available Tags
Show available tags: 

```shell
ansible-playbook --inventory localhost site.yml --list-tags
```

```shell 
# Result:
  play #1 (localhost): Fedora Workstation Configuration	TAGS: []
      TASK TAGS: [app-config, apps, cleanup, codecs, codium, cursors, customisation, dconf, debug, dnf, drivers, extensions, flatpaks, git, gnome, icons, remote-access, remove, repo, rpm, ssh, system, terminal, theme, wallpaper]

```

<br>

## Todo
Items that would like to add to the playbook.
- Add avatar for login prompt.
- Set Power to Performance.
- Add LibreWolf config.
- Add Evolution config and backup/restore.
- Check and mount data and gaming drives.

# Summary
I have had a blast learning this far and am looking forward to further automation. Hope this helps you on your automation journey!

{{< admonition type=info title="References:" open=true  >}}

**Ansible Official Documentation:**
- [Getting Started Guide](https://docs.ansible.com/ansible/latest/getting_started/index.html_)
- [Ansible Builtin Modules](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/index.html\ )
- [Ansible Playbook Guide](https://docs.ansible.com/ansible/latest/playbook_guide/index.html)
- [Ansible Playbook Tags](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_tags.html)
- [Ansible Dictionary Lookup](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/dict_lookup.html)
- [Ansible Loops](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_loops.html)
- [Ansible Variables](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html)
{{< /admonition >}} 

Cheers.
