Merge branch 'cli-tools' into 'main'

Added new playbook just for cli-tools and updated CI

See merge request sagidayan/linux-config!1
This commit is contained in:
Sagi Dayan 2021-12-18 09:58:03 +00:00
commit 67acabbe1a
11 changed files with 175 additions and 71 deletions

View file

@ -10,9 +10,25 @@ Run Workstation playbook on fedora:
- dnf install -y ansible python3-pip - dnf install -y ansible python3-pip
- pip3 install -r ci-requirements.txt - pip3 install -r ci-requirements.txt
- mkdir /tmp/artifacts - mkdir /tmp/artifacts
- ./play_workstation.sh - ./run_play.sh workstation
- cp /tmp/artifacts/workstation-*.xml report.xml - mv /tmp/artifacts/workstation-*.xml report.xml
- ls /tmp/artifacts artifacts:
when: always
reports:
junit: report.xml
Run cli-tools playbook on centos:
stage: dnf_systems
image: centos:8
script:
- dnf install -y epel-release dnf-plugins-core
- dnf install -y --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-8.noarch.rpm https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-8.noarch.rpm
- dnf makecache
- dnf install -y ansible python3-pip
- pip3 install -r ci-requirements.txt
- mkdir /tmp/artifacts
- ./run_play.sh cli-tools
- mv /tmp/artifacts/cli-tools-*.xml report.xml
artifacts: artifacts:
when: always when: always
reports: reports:
@ -22,14 +38,32 @@ Run Workstation playbook on ubuntu:
stage: apt_systems stage: apt_systems
image: ubuntu:latest image: ubuntu:latest
script: script:
- export DEBIAN_FRONTEND=noninteractive
- apt-get update - apt-get update
- apt install -y software-properties-common
- add-apt-repository -y --update ppa:ansible/ansible
- apt-get install -y ansible python3-pip python3-apt - apt-get install -y ansible python3-pip python3-apt
- pip3 install -r ci-requirements.txt - pip3 install -r ci-requirements.txt
- mkdir /tmp/artifacts - mkdir /tmp/artifacts
- ./play_workstation.sh - ./run_play.sh workstation
- mv /tmp/artifacts/workstation-*.xml report.xml - mv /tmp/artifacts/workstation-*.xml report.xml
- ls /tmp/artifacts
artifacts: artifacts:
when: always when: always
reports: reports:
junit: report.xml junit: report.xml
Run cli-tools playbook on debian:
stage: apt_systems
image: debian:latest
script:
- apt-get update
- apt-get install -y ansible python3-pip python3-apt
- pip3 install -r ci-requirements.txt
- mkdir /tmp/artifacts
- ./run_play.sh cli-tools
- mv /tmp/artifacts/cli-tools-*.xml report.xml
artifacts:
when: always
reports:
junit: report.xml

View file

@ -2,12 +2,29 @@
# Configurations and Applications # Configurations and Applications
## Using ansible playbooks ## Using ansible playbooks
Playbooks will install software and configure most of the tools.
⚠️ WIP Since dotfiles are the most basic thing this repo provides, It is constantly a WIP.
I do try to make sure playbooks work on RHEL/Debian based distros via gitlab CI.
This repo was created for my own use, But feel free to use it as you please.
Looking just for dotfiles? take a look at `files/dotfiles`
### Requirements:
- git
- Ansible (>=2.9.27)
### Workstation config ### Running plays
Playbooks are located in `play-books`
``` ```
ansible-playbook workstation.yml $ ./run_play.sh <playbook> # Defaults to workstation
``` ```
### Playbooks
- workstation
- cli-tools

View file

@ -13,6 +13,7 @@ alias :Q=exit
alias ls='lsd' alias ls='lsd'
alias f='printf "\033c"' alias f='printf "\033c"'
alias cat=bat alias cat=bat
alias top=btm
alias t=tmux alias t=tmux
@ -82,6 +83,60 @@ function ide() {
tmux rename-window ${IDE_NAME} tmux rename-window ${IDE_NAME}
} }
# Create a tmux layout with fast
# Usage: $ layout "<num_rows> [<num_rows>]+ [layout_name]"
# Examples: $ layout "2" Bob # Single column with 2 rows, named Bob
# $ layout "2 1" # Two columns, left column with 2 rows, right column with ine row
function layout() {
pre_check_tmux_for_layout "layout/grid" || return 1
CURRENT_DIR=$(echo "${PWD##*/}")
LAYOUT_NAME="[#⃣ Layout: ${2:=$CURRENT_DIR}]"
INPUT=${1-}
if [ -z $INPUT ]; then
echo "Error: Invalid layout. Usage: $ layout <layout>"
return 1
fi
COLS=($(echo $INPUT))
# echo "Number of Columns: ${#COLS[@]}"
# Create columns
H_RATIO=$((100 / ${#COLS[@]}))
cols=$((${#COLS[@]} - 1))
if [ $cols -le 0 ]; then
cols=1
else
for col in {1..$(($cols))}
do
H_SIZE=$((100 - (col * H_RATIO)))
tmux split-window -h -p $((H_SIZE))
done
fi
tmux select-pane -t 0
# Create Rows
for col in {1..$(($cols + 1))}
do
if [ $col != 1 ]; then
tmux select-pane -R #Move pane to the right
fi
ROWS=$((COLS[col]))
if [ $((ROWS)) -gt 1 ]; then
V_RATIO=$((100 / (ROWS)))
for row in {1..$((ROWS - 1))}
do
V_SIZE=$((100 - (row * V_RATIO)))
tmux split-window -v -p $((V_SIZE))
done
fi
done
tmux select-pane -t 0
tmux rename-window ${LAYOUT_NAME}
tmux send-keys "clear" C-m
}
# Create a tmux grid layout. default 2x2 # Create a tmux grid layout. default 2x2
# Usage: $ grid # Usage: $ grid
# $ grid 3x3 # $ grid 3x3
@ -98,35 +153,15 @@ function grid() {
GRID_COLS="2" GRID_COLS="2"
GRID_ROWS="2" GRID_ROWS="2"
fi fi
V_PANES=$((GRID_ROWS))
H_PANES=$((GRID_COLS))
V_RATIO=$((100 / V_PANES))
H_RATIO=$((100 / H_PANES))
echo "COLS: $GRID_COLS"
echo "ROWS: $GRID_ROWS"
for h in {1..$((H_PANES - 1))} LAYOUT_SCHEME=""
for i in {1..$((GRID_COLS))}
do do
H_SIZE=$((100 - (h * H_RATIO))) LAYOUT_SCHEME="${LAYOUT_SCHEME} ${GRID_ROWS}"
tmux split-window -h -p $((H_SIZE))
echo " $h H_SIZE $H_SIZE"
done done
for cell in {$((H_PANES - 1))..0} layout $LAYOUT_SCHEME $2 || return 1
do return 0
tmux select-pane -t ${cell}
CURRENT_PANE=$(tmux list-panes | grep '(active)$' | grep -oP '^[\d]+')
echo Current pane: $CURRENT_PANE
for v in {1..$((V_PANES - 1))}
do
V_SIZE=$((100 - (v * V_RATIO)))
tmux split-window -v -p $((V_SIZE))
echo " $v V_SIZE $V_SIZE"
done
done
# Select top left cell (Starting point)
tmux select-pane -t 0
} }

View file

View file

@ -1,7 +0,0 @@
#!/bin/bash
# Install Dependencies
ansible-galaxy collection install community.general
# Run Playbook
ANSIBLE_CONFIG=$(pwd)/ansible.cfg JUNIT_OUTPUT_DIR=/tmp/artifacts ansible-playbook playbooks/workstation.yml || (mv /tmp/artifacts/workstation-*.xml report.xml && exit 1)

10
playbooks/cli-tools.yml Normal file
View file

@ -0,0 +1,10 @@
- hosts: localhost
vars:
# Theme options: monokai, gruvbox, nord, tomorrow-night
theme: tomorrow-night
# The running user
running_user: "{{ ansible_user_id }}"
roles:
- base
- tmux_user
- vim_user

View file

@ -10,5 +10,4 @@
- tmux_user - tmux_user
- vim_user - vim_user
- alacritty_user - alacritty_user
- lsd_user
- flatpaks - flatpaks

View file

@ -4,10 +4,10 @@
name: name:
- zsh - zsh
- curl - curl
- bat - gcc
- make
- wget - wget
- git - git
- flatpak
- ranger - ranger
state: present state: present
@ -53,6 +53,7 @@
dest: ~/.config/ranger/plugins/ranger_devicons dest: ~/.config/ranger/plugins/ranger_devicons
- name: Validate ranger config file - name: Validate ranger config file
changed_when: false
file: file:
path: ~/.config/ranger/rc.conf path: ~/.config/ranger/rc.conf
state: touch state: touch
@ -69,12 +70,14 @@
state: directory state: directory
- name: Sync Common shell settings... - name: Sync Common shell settings...
changed_when: false
copy: copy:
src: dotfiles/shellconfig/common.sh src: dotfiles/shellconfig/common.sh
dest: ~/.shellconfig/common.sh dest: ~/.shellconfig/common.sh
force: yes force: yes
- name: verify Bat (better Cat) theme - name: verify Bat (better Cat) theme
changed_when: false
ansible.builtin.lineinfile: ansible.builtin.lineinfile:
path: "~/.shellconfig/common.sh" path: "~/.shellconfig/common.sh"
regexp: "^export BAT_THEME=" regexp: "^export BAT_THEME="
@ -98,3 +101,10 @@
dest: ~/.shellconfig/environment.sh dest: ~/.shellconfig/environment.sh
force: no force: no
- name: Install rust and common tooling
vars:
rustup_user: "{{ running_user }}"
rustup_cargo_crates: [bat,lsd,bottom]
ansible.builtin.include_role:
name: hurricanehrndz.rustup

View file

@ -1,4 +1,11 @@
--- ---
- name: Installing packages
become: true
package:
name:
- flatpak
state: present
- name: Add the flathub flatpak repository remote - name: Add the flathub flatpak repository remote
community.general.flatpak_remote: community.general.flatpak_remote:
name: flathub name: flathub

View file

@ -1,27 +0,0 @@
- name: Install LSDeluxe (RHEL family)
become: true
package:
name: lsd
state: present
when: ansible_facts['os_family'] == "RedHat"
- name: Check if lsd is installed (Debian Family)
command: dpkg-query -W lsd
register: lsd_package_check
failed_when: lsd_package_check.rc > 1
changed_when: lsd_package_check.rc == 1
when: ansible_facts['os_family'] == "Debian"
#===== Debian Only - No need for ansible_disrebution
- name: Download LSDeluxe deb file (Debian Family)
get_url:
url: https://github.com/Peltoche/lsd/releases/download/0.20.1/lsd-musl_0.20.1_amd64.deb
dest: ./lsd.deb
when: lsd_package_check.changed
- name: Install LSDeluxe Deb file (Debian Family)
become: true
apt:
deb: ./lsd.deb
when: lsd_package_check.changed

26
run_play.sh Executable file
View file

@ -0,0 +1,26 @@
#!/bin/bash
TARGET_PLAY="${1:-workstation}"
PLAYBOOK="playbooks/${TARGET_PLAY}.yml"
if [ ! -f $PLAYBOOK ]; then
echo "Invalid play '${TARGET_PLAY}'. Unable to locate ${PLAYBOOK}"
exit 1
fi
function print_fail_and_exit() {
echo "❌ Something went wrong..."
cp /tmp/artifacts/${TARGET_PLAY}*.xml ./report.xml
exit 1
}
echo "======> Running ${TARGET_PLAY}"
# Install Dependencies
ansible-galaxy collection install community.general
ansible-galaxy install hurricanehrndz.rustup
# Run Playbook
ANSIBLE_CONFIG=$(pwd)/ansible.cfg JUNIT_OUTPUT_DIR="/tmp/artifacts" ansible-playbook ${PLAYBOOK} -vvvv || print_fail_and_exit
echo "======> Done."