From c512adf04d3bf1bc0790fc275f8f51cd7aaba3a9 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Tue, 18 Jan 2022 11:19:19 +0200 Subject: [PATCH] Added ansible lint CI step. Cleanup and lint fixes --- .gitlab-ci.yml | 27 ++++++++++++++++--- files/dotfiles/shellconfig/cheat.sh | 12 ++++----- files/dotfiles/shellconfig/common.sh | 37 ++++++++++++++++---------- files/dotfiles/tmux.conf | 2 +- install-ansible-modules.sh | 6 +++++ roles/alacritty_user/tasks/main.yml | 7 +++-- roles/base/tasks/main.yml | 14 ++++++++++ roles/flatpaks/tasks/main.yml | 1 + roles/fonts/tasks/main.yml | 3 +++ roles/gh_release_bin/tasks/main.yml | 15 ++++++++--- roles/modern_unix_tools/tasks/main.yml | 22 ++++++++++++--- roles/tmux_user/tasks/main.yml | 4 ++- roles/vim_user/tasks/main.yml | 8 ++++-- run_play.sh | 4 +-- 14 files changed, 123 insertions(+), 39 deletions(-) create mode 100755 install-ansible-modules.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 58a8a11..5f5a81a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,10 +1,26 @@ --- stages: +- ansible lint - x86 Systems +Ansible Lint: + stage: ansible lint + image: + name: fedora:latest + before_script: + - dnf install -y git ansible python3-ansible-lint + - export ANSIBLE_CONFIG=$(pwd)/ansible.cfg + - ./install-ansible-modules.sh + - ansible-lint --version + script: + - ansible-lint --force-color . &> lint-output.txt + - cat lint-output.txt + - if [ ! -z "$(cat lint-output.txt)" ]; then echo "Lint returned with warnings/fails"; exit 1; fi + Run Workstation playbook on fedora: stage: x86 Systems - image: fedora:latest + image: + name: fedora:latest script: - dnf install -y ansible python3-pip - pip3 install -r ci-requirements.txt @@ -18,7 +34,8 @@ Run Workstation playbook on fedora: Run cli-tools playbook on centos: stage: x86 Systems - image: centos:latest + image: + name: centos:latest 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 @@ -35,7 +52,8 @@ Run cli-tools playbook on centos: Run Workstation playbook on ubuntu: stage: x86 Systems - image: ubuntu:latest + image: + name: ubuntu:latest script: - export DEBIAN_FRONTEND=noninteractive - apt-get update @@ -53,7 +71,8 @@ Run Workstation playbook on ubuntu: Run cli-tools playbook on debian: stage: x86 Systems - image: debian:latest + image: + name: debian:latest script: - apt-get update - apt-get install -y ansible python3-pip python3-apt diff --git a/files/dotfiles/shellconfig/cheat.sh b/files/dotfiles/shellconfig/cheat.sh index ec0d79c..393a4ad 100755 --- a/files/dotfiles/shellconfig/cheat.sh +++ b/files/dotfiles/shellconfig/cheat.sh @@ -4,16 +4,16 @@ ######################################################## # Get docs fast -selected=`cat ~/.shellconfig/cheat/topics | fzf --header="🏳️ Select a Topic: " --reverse` -if [[ -z $selected ]]; then +SELECTED=`cat ~/.shellconfig/cheat/topics | fzf --header="🏳️ Select a Topic: " --reverse` +if [[ -z $SELECTED ]]; then exit 0 fi -read -p "What you want to know?: " query +read -p "🏳️ What do you want to know about ${SELECTED}?: " query query=`echo $query | tr ' ' '+'` -if [[ $selected == "TLDR" ]]; then - tmux neww -n "[🏳️ Cheat: ${selected}/${query}]" bash -c "tldr ${query} | bat --paging=always --file-name='${selected} | Query: ${query}'" +if [[ $SELECTED == "TLDR" ]]; then + tmux neww -n "[🏳️ Cheat: ${SELECTED}/${query}]" bash -c "tldr ${query} | bat --paging=always --file-name='${SELECTED} | Query: ${query}'" else - tmux neww -n "[🏳️ Cheat: ${selected}/${query}]" bash -c "curl -s https://cht.sh/$selected/$query | bat --paging=always --file-name='Topic: ${selected} | Query: ${query}'" + tmux neww -n "[🏳️ Cheat: ${SELECTED}/${query}]" bash -c "curl -s https://cht.sh/$SELECTED/$query | bat --paging=always --file-name='Topic: ${SELECTED} | Query: ${query}'" fi diff --git a/files/dotfiles/shellconfig/common.sh b/files/dotfiles/shellconfig/common.sh index c4111f7..a96c975 100644 --- a/files/dotfiles/shellconfig/common.sh +++ b/files/dotfiles/shellconfig/common.sh @@ -38,6 +38,27 @@ export EDITOR=vim; # Shell functions ############################################ +function huh() { + CURRENT_DIR=$(echo "${PWD##*/}") + TITLE="${1:=$CURRENT_DIR}" + + echo "=-=-=-=-=-=-=-=-=-=-=-=-=-="; \ + echo "${TITLE}"; \ + echo "=-=-=-=-=-=-=-=-=-=-=-=-=-="; \ + echo;echo Status:; \ + echo -=-=-=-; \ + git status; \ + echo; \ + echo Remotes:; \ + echo -=-=-=-=; \ + git remote -v | cat; \ + echo;echo Files:; \ + echo -=-=-=; \ + ls -l; \ + echo;echo; + +} + function pre_check_tmux_for_layout() { ERROR_PREFIX="[ERROR]: " @@ -70,20 +91,8 @@ function ide() { IDE_NAME="[⌨️ IDE: ${1:=$CURRENT_DIR}]" pre_check_tmux_for_layout "ide" || return 1 - - echo "=-=-=-=-=-=-=-=-=-=-=-=-=-="; \ - echo "${IDE_NAME}"; \ - echo "=-=-=-=-=-=-=-=-=-=-=-=-=-="; \ - echo;echo Status:; \ - echo -=-=-=-; \ - git status; \ - echo; \ - echo Remotes:; \ - echo -=-=-=-=; \ - git remote -v | cat; \ - echo;echo Files:; \ - echo -=-=-=; \ - ls -l + clear; + huh "${IDE_NAME}"; tmux split-window -h -p 80 tmux split-window -h -p 30 tmux send-keys "gitui" C-m diff --git a/files/dotfiles/tmux.conf b/files/dotfiles/tmux.conf index 4616dac..c39a811 100644 --- a/files/dotfiles/tmux.conf +++ b/files/dotfiles/tmux.conf @@ -35,7 +35,7 @@ bind-key j send-keys Down bind-key r source-file ~/.tmux.conf \; display-message "~/.tmux.conf reloaded." # Lookup the cheat sheet -i -bind-key i run-shell "tmux neww ~/.shellconfig/cheat.sh" +bind-key i run-shell "tmux neww -n '🏳️ CHEATER\! 😎' ~/.shellconfig/cheat.sh" ############################ # Themes ########################### diff --git a/install-ansible-modules.sh b/install-ansible-modules.sh new file mode 100755 index 0000000..b2364e2 --- /dev/null +++ b/install-ansible-modules.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +echo "===> Installing Ansible Dependencies" +ansible-galaxy collection install community.general +ansible-galaxy install hurricanehrndz.rustup + diff --git a/roles/alacritty_user/tasks/main.yml b/roles/alacritty_user/tasks/main.yml index 062532e..4b63521 100644 --- a/roles/alacritty_user/tasks/main.yml +++ b/roles/alacritty_user/tasks/main.yml @@ -10,16 +10,19 @@ become: true package: name: alacritty - state: latest + state: present - name: Setting up alacritty config file copy: src: dotfiles/alacritty.yml dest: ~/.alacritty.yml + mode: preserve + changed_when: false - name: "Setting Alacritty theme" ansible.builtin.lineinfile: path: "~/.alacritty.yml" regexp: "^colors:" - line: "colors: *{{theme}}" + line: "colors: *{{ theme }}" + changed_when: false diff --git a/roles/base/tasks/main.yml b/roles/base/tasks/main.yml index f085d11..da26d4c 100644 --- a/roles/base/tasks/main.yml +++ b/roles/base/tasks/main.yml @@ -25,11 +25,14 @@ src: dotfiles/gitconfig dest: ~/.gitconfig force: no + mode: preserve - name: Setting up oh-my-zsh git: repo: https://github.com/ohmyzsh/ohmyzsh.git dest: ~/.oh-my-zsh + version: master + - name: Making sure to use ZSH as shell become: true @@ -42,17 +45,20 @@ src: dotfiles/zshrc dest: ~/.zshrc force: yes + mode: preserve - name: Add ranger devicons plugin repo git: repo: https://github.com/alexanderjeurissen/ranger_devicons.git dest: ~/.config/ranger/plugins/ranger_devicons + version: main - name: Validate ranger config file changed_when: false file: path: ~/.config/ranger/rc.conf state: touch + mode: u=rw,g=r,o=r - name: Activate ranger devicons plugin lineinfile: @@ -64,16 +70,19 @@ file: path: ~/.shellconfig state: directory + mode: '0755' - name: Verifying shell autocomplete config folder file: path: ~/.shellconfig/autocomplete state: directory + mode: '0755' - name: Verifying shell cheat config folder file: path: ~/.shellconfig/cheat state: directory + mode: '0755' - name: Sync Common shell settings... changed_when: false @@ -81,6 +90,7 @@ src: dotfiles/shellconfig/common.sh dest: ~/.shellconfig/common.sh force: yes + mode: preserve - name: Sync Cheat script changed_when: false @@ -95,24 +105,28 @@ src: dotfiles/shellconfig/aliases.sh dest: ~/.shellconfig/aliases.sh force: no + mode: preserve - name: Copy shell functions copy: src: dotfiles/shellconfig/functions.sh dest: ~/.shellconfig/functions.sh force: no + mode: preserve - name: Copy shell environment copy: src: dotfiles/shellconfig/environment.sh dest: ~/.shellconfig/environment.sh force: no + mode: preserve - name: Copy topics cheat sheet list copy: src: dotfiles/shellconfig/cheat/topics dest: ~/.shellconfig/cheat/topics force: yes + mode: preserve - name: Install modern UNIX tools include_role: diff --git a/roles/flatpaks/tasks/main.yml b/roles/flatpaks/tasks/main.yml index f3fdef3..01c142e 100644 --- a/roles/flatpaks/tasks/main.yml +++ b/roles/flatpaks/tasks/main.yml @@ -33,6 +33,7 @@ - name: Check if open function is set shell: grep -c "^function open" ~/.shellconfig/functions.sh || true register: open_test + changed_when: false - name: "Adding 'open' shell function" ansible.builtin.lineinfile: diff --git a/roles/fonts/tasks/main.yml b/roles/fonts/tasks/main.yml index 271a9ab..473704d 100644 --- a/roles/fonts/tasks/main.yml +++ b/roles/fonts/tasks/main.yml @@ -5,6 +5,8 @@ state: directory owner: root group: root + mode: '0755' + changed_when: false - name: Installing Hack Nerd Font become: true @@ -13,3 +15,4 @@ dest: /usr/share/fonts/hack/hack_nerd_font.ttf owner: root group: root + mode: preserve diff --git a/roles/gh_release_bin/tasks/main.yml b/roles/gh_release_bin/tasks/main.yml index 0134d2f..804cba6 100644 --- a/roles/gh_release_bin/tasks/main.yml +++ b/roles/gh_release_bin/tasks/main.yml @@ -3,6 +3,7 @@ ansible.builtin.file: state: directory path: ~/.ansible_gh_release_versions + mode: '0755' - name: Setting local release file path set_fact: @@ -16,7 +17,8 @@ changed_when: false - name: Get latest version tag from github - shell: echo {{ tar_url.stdout }} | grep -oP "(?<=download\/).*(?=\/)" + shell: + cmd: 'echo {{ tar_url.stdout }} | grep -oP "(?<=download\/).*(?=\/)"' changed_when: false register: version @@ -35,6 +37,13 @@ remote_src: yes when: version != local_version +- name: Unarchive release source + ansible.builtin.unarchive: + src: "https://github.com/{{ repo }}/archive/refs/tags/{{ version }}.tar.gz" + dest: /tmp/ + remote_src: yes + when: version != local_version and (include_source is defined) + - name: Moving bin to /usr/local/bin become: true shell: | @@ -50,12 +59,12 @@ - name: Update mandb if needed become: true - shell: mandb + shell: mandb || true when: added_man is defined and (version != local_version) - name: Adding autocomplete if needed shell: | - cp /tmp/{{ autocomplete_path }} ~/.shellconfig/autocomplete/ + cp /tmp/{{ autocomplete_path }} ~/.shellconfig/autocomplete/{{ name }}.autocomplete when: autocomplete_path is defined and (version != local_version) - name: Updating local version entry diff --git a/roles/modern_unix_tools/tasks/main.yml b/roles/modern_unix_tools/tasks/main.yml index e3d1c0e..0869645 100644 --- a/roles/modern_unix_tools/tasks/main.yml +++ b/roles/modern_unix_tools/tasks/main.yml @@ -1,4 +1,16 @@ --- +- name: Installing fzf + ansible.builtin.include_role: + name: gh_release_bin + vars: + name: fzf + repo: junegunn/fzf + bin_path: "/fzf" + autocomplete_path: "/fzf-*/shell/completion.zsh" + man_path: "/fzf-*/man/man1/fzf.1" + include_source: yes + filter: linux_amd64.tar.gz + - name: Installing bat (cat like) ansible.builtin.include_role: name: gh_release_bin @@ -7,7 +19,6 @@ repo: sharkdp/bat bin_path: "/bat-*/bat" man_path: "/bat-*/bat.1" - autocomplete_path: "/bat-*/autocomplete/bat.bash" filter: x86_64-unknown-linux-gnu - name: verify Bat (better Cat) theme @@ -15,10 +26,12 @@ ansible.builtin.lineinfile: path: "~/.shellconfig/common.sh" regexp: "^export BAT_THEME=" - line: 'export BAT_THEME="${{theme}}"' + line: 'export BAT_THEME="${{ theme }}"' - name: Instaling TLDR (pip3) - shell: pip3 install tldr + become: true + shell: pip3 install tldr || true + changed_when: false - name: Installing bottom (btm) (Top like) ansible.builtin.include_role: @@ -43,18 +56,21 @@ file: path: ~/.config/gitui state: directory + mode: '0755' - name: Copy gitui keybindings copy: src: dotfiles/gitui/key_config.ron dest: ~/.config/gitui/key_config.ron force: yes + mode: preserve - name: Copy gitui theme config copy: src: dotfiles/gitui/theme.ron dest: ~/.config/gitui/theme.ron force: yes + mode: preserve - name: Installing LSD (ls like) ansible.builtin.include_role: diff --git a/roles/tmux_user/tasks/main.yml b/roles/tmux_user/tasks/main.yml index ed6137d..6319fcd 100644 --- a/roles/tmux_user/tasks/main.yml +++ b/roles/tmux_user/tasks/main.yml @@ -2,15 +2,17 @@ become: true package: name: tmux - state: latest + state: present - name: Install tmux plugin manager git: repo: https://github.com/tmux-plugins/tpm dest: ~/.tmux/plugins/tpm update: yes + version: master - name: Copy tmux config file copy: src: dotfiles/tmux.conf dest: ~/.tmux.conf + mode: preserve diff --git a/roles/vim_user/tasks/main.yml b/roles/vim_user/tasks/main.yml index f60833f..c5a388f 100644 --- a/roles/vim_user/tasks/main.yml +++ b/roles/vim_user/tasks/main.yml @@ -4,7 +4,7 @@ name: - vim-X11 - the_silver_searcher - state: latest + state: present when: ansible_facts['os_family'] == "RedHat" - name: Install vim (Debian based) @@ -20,6 +20,7 @@ file: path: ~/.vim/autoload state: directory + mode: '0755' - name: Install vim Plug get_url: @@ -30,12 +31,15 @@ copy: src: dotfiles/vimrc dest: "~/.vimrc" + mode: preserve + changed_when: false - name: "Set vim colorscheme" ansible.builtin.lineinfile: path: "~/.vimrc" regexp: "^colorscheme" - line: "colorscheme base16-{{theme}}" + line: "colorscheme base16-{{ theme }}" + changed_when: false #- name: "Set vim lightline colorscheme" # ansible.builtin.lineinfile: diff --git a/run_play.sh b/run_play.sh index 5b26f68..895f572 100755 --- a/run_play.sh +++ b/run_play.sh @@ -16,9 +16,7 @@ function print_fail_and_exit() { echo "======> Running ${TARGET_PLAY}" -# Install Dependencies -ansible-galaxy collection install community.general -ansible-galaxy install hurricanehrndz.rustup +./install-ansible-modules.sh # Run Playbook ANSIBLE_CONFIG=$(pwd)/ansible.cfg JUNIT_OUTPUT_DIR="/tmp/artifacts" ansible-playbook ${PLAYBOOK} || print_fail_and_exit