From 3887c8df9f54c43b2140a3c44ed9f9e150b06477 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Tue, 14 Dec 2021 13:20:38 +0200 Subject: [PATCH] Added new playbook just for cli-tools and updated CI --- .gitlab-ci.yml | 44 ++++++++++++-- README.md | 23 +++++++- files/dotfiles/shellconfig/common.sh | 85 ++++++++++++++++++++-------- play_server.sh | 0 play_workstation.sh | 7 --- playbooks/cli-tools.yml | 10 ++++ playbooks/workstation.yml | 1 - roles/base/tasks/main.yml | 16 +++++- roles/flatpaks/tasks/main.yml | 7 +++ roles/lsd_user/tasks/main.yml | 27 --------- run_play.sh | 26 +++++++++ 11 files changed, 175 insertions(+), 71 deletions(-) delete mode 100755 play_server.sh delete mode 100755 play_workstation.sh create mode 100644 playbooks/cli-tools.yml delete mode 100644 roles/lsd_user/tasks/main.yml create mode 100755 run_play.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b589d80..a953b8f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,9 +10,25 @@ Run Workstation playbook on fedora: - dnf install -y ansible python3-pip - pip3 install -r ci-requirements.txt - mkdir /tmp/artifacts - - ./play_workstation.sh - - cp /tmp/artifacts/workstation-*.xml report.xml - - ls /tmp/artifacts + - ./run_play.sh workstation + - mv /tmp/artifacts/workstation-*.xml report.xml + 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: when: always reports: @@ -22,14 +38,32 @@ Run Workstation playbook on ubuntu: stage: apt_systems image: ubuntu:latest script: + - export DEBIAN_FRONTEND=noninteractive - 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 - pip3 install -r ci-requirements.txt - mkdir /tmp/artifacts - - ./play_workstation.sh + - ./run_play.sh workstation - mv /tmp/artifacts/workstation-*.xml report.xml - - ls /tmp/artifacts artifacts: when: always reports: 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 + diff --git a/README.md b/README.md index 2777a90..c4def9d 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,29 @@ # Configurations and Applications ## 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 # Defaults to workstation ``` + +### Playbooks + - workstation + - cli-tools diff --git a/files/dotfiles/shellconfig/common.sh b/files/dotfiles/shellconfig/common.sh index 34310e0..7c88d92 100644 --- a/files/dotfiles/shellconfig/common.sh +++ b/files/dotfiles/shellconfig/common.sh @@ -13,6 +13,7 @@ alias :Q=exit alias ls='lsd' alias f='printf "\033c"' alias cat=bat +alias top=btm alias t=tmux @@ -82,6 +83,60 @@ function ide() { tmux rename-window ${IDE_NAME} } +# Create a tmux layout with fast +# Usage: $ layout " []+ [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 " + 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 # Usage: $ grid # $ grid 3x3 @@ -98,35 +153,15 @@ function grid() { GRID_COLS="2" GRID_ROWS="2" 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 - H_SIZE=$((100 - (h * H_RATIO))) - tmux split-window -h -p $((H_SIZE)) - echo " $h H_SIZE $H_SIZE" - done - - for cell in {$((H_PANES - 1))..0} - do - 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 + LAYOUT_SCHEME="${LAYOUT_SCHEME} ${GRID_ROWS}" done - # Select top left cell (Starting point) - tmux select-pane -t 0 + layout $LAYOUT_SCHEME $2 || return 1 + return 0 } diff --git a/play_server.sh b/play_server.sh deleted file mode 100755 index e69de29..0000000 diff --git a/play_workstation.sh b/play_workstation.sh deleted file mode 100755 index ef79268..0000000 --- a/play_workstation.sh +++ /dev/null @@ -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) diff --git a/playbooks/cli-tools.yml b/playbooks/cli-tools.yml new file mode 100644 index 0000000..d489c95 --- /dev/null +++ b/playbooks/cli-tools.yml @@ -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 diff --git a/playbooks/workstation.yml b/playbooks/workstation.yml index bd69e70..0e96e0b 100644 --- a/playbooks/workstation.yml +++ b/playbooks/workstation.yml @@ -10,5 +10,4 @@ - tmux_user - vim_user - alacritty_user - - lsd_user - flatpaks diff --git a/roles/base/tasks/main.yml b/roles/base/tasks/main.yml index c386b8e..1ef595a 100644 --- a/roles/base/tasks/main.yml +++ b/roles/base/tasks/main.yml @@ -4,10 +4,10 @@ name: - zsh - curl - - bat + - gcc + - make - wget - git - - flatpak - ranger state: present @@ -53,6 +53,7 @@ dest: ~/.config/ranger/plugins/ranger_devicons - name: Validate ranger config file + changed_when: false file: path: ~/.config/ranger/rc.conf state: touch @@ -69,12 +70,14 @@ state: directory - name: Sync Common shell settings... + changed_when: false copy: src: dotfiles/shellconfig/common.sh dest: ~/.shellconfig/common.sh force: yes - name: verify Bat (better Cat) theme + changed_when: false ansible.builtin.lineinfile: path: "~/.shellconfig/common.sh" regexp: "^export BAT_THEME=" @@ -97,4 +100,11 @@ src: dotfiles/shellconfig/environment.sh dest: ~/.shellconfig/environment.sh 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 + diff --git a/roles/flatpaks/tasks/main.yml b/roles/flatpaks/tasks/main.yml index 635da78..f3fdef3 100644 --- a/roles/flatpaks/tasks/main.yml +++ b/roles/flatpaks/tasks/main.yml @@ -1,4 +1,11 @@ --- +- name: Installing packages + become: true + package: + name: + - flatpak + state: present + - name: Add the flathub flatpak repository remote community.general.flatpak_remote: name: flathub diff --git a/roles/lsd_user/tasks/main.yml b/roles/lsd_user/tasks/main.yml deleted file mode 100644 index a795b07..0000000 --- a/roles/lsd_user/tasks/main.yml +++ /dev/null @@ -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 diff --git a/run_play.sh b/run_play.sh new file mode 100755 index 0000000..7189427 --- /dev/null +++ b/run_play.sh @@ -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."