16 Commits

Author SHA1 Message Date
98573c0066 Add moonlight role for Windows
Role installs the [Moonlight](https://moonlight-stream.org/) game
streaming client.
2022-11-20 21:51:08 +00:00
d95f1f7e32 Switch to Ansible for managing neovim plugins 2022-11-16 18:37:42 +00:00
7da67aaed0 Add labels for improve zsh role output 2022-11-11 17:27:16 +00:00
7ec59f8c52 Add sudo role for Unix systems 2022-11-07 14:38:50 +00:00
bebe6de7cd Set gdb config file based on installed version 2022-11-06 19:47:36 +00:00
08af0f00b6 Add CAD software to Windows playbook
The `autodesk-fusion360` and `prusiaslicer` roles are added to the
`Windows.yaml` playbook but disabled by default behind the
`install_cad_apps` flag. To enable them create a `~/.config/local.yaml`
file with the following:

```yaml
- import_playbook: local/Windows.yaml
  vars:
    install_cad_apps: true
```
2022-11-06 15:54:54 +00:00
3864c0f35d Add PrusaSlicer role for Windows 2022-11-06 15:31:02 +00:00
3218722fcb Add AutoDesk Fusion 360 role for Windows 2022-11-06 15:26:16 +00:00
1895f1561d Ensure $(hostname).local is in hosts file on WSL 2022-11-06 10:56:19 +00:00
cee0c443a3 Add gdb role for Debian 2022-11-05 20:05:48 +00:00
bb945190f8 Add readline role for Unix like systems 2022-11-04 12:53:20 +00:00
4f5a2e6333 Fix htop not setting become: true 2022-11-03 11:47:39 +00:00
833f9a25ef Add powertoys role for Windows 2022-10-31 23:26:07 +00:00
1fbdcdd487 Include jq, yq, and jp in relevant playbooks 2022-10-30 23:23:48 +00:00
9efb5d6c15 Add role for jp on macOS and Debian 2022-10-30 23:23:23 +00:00
d99657e3b8 Fix type in jq task comment 2022-10-30 23:23:04 +00:00
29 changed files with 341 additions and 22 deletions

View File

@@ -2,6 +2,9 @@
- hosts: localhost - hosts: localhost
roles: roles:
- role: sudo
when: ansible_user_id != "root"
- role: zsh - role: zsh
- role: neovim - role: neovim
- role: tmux - role: tmux
@@ -14,8 +17,12 @@
- role: fzf - role: fzf
- role: git - role: git
- role: htop - role: htop
- role: jp
- role: jq
- role: readline
- role: tidy - role: tidy
- role: tree - role: tree
- role: yq
- role: llvm - role: llvm
- role: nodejs - role: nodejs

View File

@@ -1,6 +1,9 @@
--- ---
- hosts: windows - hosts: windows
vars:
install_cad_apps: false
roles: roles:
- role: git - role: git
- role: powershell - role: powershell
@@ -12,6 +15,8 @@
- role: curl - role: curl
- role: fzf - role: fzf
- role: tree - role: tree
- role: jq
- role: yq
- role: llvm - role: llvm
- role: nodejs - role: nodejs
@@ -21,4 +26,10 @@
- role: autohotkey - role: autohotkey
- role: firefox - role: firefox
- role: obsidian - role: obsidian
- role: powertoys
- role: windows-terminal - role: windows-terminal
- role: autodesk-fusion360
when: install_cad_apps
- role: prusaslicer
when: install_cad_apps

View File

@@ -0,0 +1,8 @@
---
- assert:
that: ansible_os_family == "Windows"
- name: install chocolatey package
win_chocolatey:
name: autodesk-fusion360
state: latest

View File

@@ -0,0 +1,6 @@
---
- name: install apt package
become: true
apt:
name: gdb
state: latest

View File

@@ -0,0 +1,11 @@
---
- set_fact:
gdb_config_dir: '{{ansible_env.HOME}}/.config/gdb'
- name: create config directory
file:
path: '{{gdb_config_dir}}'
state: directory
- set_fact:
gdb_config_file: '{{gdb_config_dir}}/gdbinit'

34
roles/gdb/tasks/main.yaml Normal file
View File

@@ -0,0 +1,34 @@
---
- include_tasks: '{{ansible_os_family}}.yaml'
# gdb 11.1 introduced support for config files that respect the XDG base
# directory spec, handle the boths paths dependant on the gdb version install.
- name: get installed version
command: gdb --version
register: gdb_version_output
changed_when: false
- set_fact:
gdb_version: '{{gdb_version_output.stdout | regex_search("(\d+)\.(\d+)", "\1", "\2")}}'
- set_fact:
gdb_xdg_base_dir_check:
gdb_version[0] | int > 11 or (
gdb_version[0] | int == 11 and gdb_version[1] | int == 1
)
- set_fact:
gdb_config_file: '{{ansible_env.HOME}}/.gdbinit'
gdb_state_dir: '{{ansible_env.HOME}}/.local/state/gdb'
- when: gdb_xdg_base_dir_check
include_tasks: gdb-11.1-config.yaml
- name: create config file
template:
src: gdbinit
dest: '{{gdb_config_file}}'
- name: create state directory
file:
path: '{{gdb_state_dir}}'
state: directory

View File

@@ -0,0 +1,3 @@
# Enable saving command history
set history filename {{gdb_state_dir}}/history
set history save on

View File

@@ -1,5 +1,6 @@
--- ---
- name: install apt package - name: install apt package
become: true
apt: apt:
name: htop name: htop
state: latest state: latest

View File

@@ -0,0 +1,38 @@
---
- name: get latest github release
uri:
url: https://api.github.com/repos/jmespath/jp/releases/latest
register: latest
# TODO: Support arm64
- set_fact:
asset_query: '[?contains(name, `jp-darwin-amd64`)] | [0]'
assets: '{{latest.json.assets}}'
latest_version: '{{latest.json.tag_name}}'
jp_exe: '{{ansible_env.HOME}}/.local/bin/jp'
- name: check if already installed
stat:
path: '{{jp_exe}}'
register: jp_exe
- name: get installed version
when: jp_stat.stat.exists == True
command: '{{jp_exe}} --version'
register: jp_version_output
changed_when: false
- when: jp_stat.stat.exists == True
set_fact:
installed_version:
'{{jp_version_output.stdout.strip() | regex_replace("^.*(\d+\.\d+\.\d+).*$", "\1")}}'
- set_fact:
asset: '{{assets | to_json | from_json | json_query(asset_query)}}'
- name: download executable
when: installed_version is not defined or installed_version != latest_version
get_url:
url: '{{asset.browser_download_url}}'
dest: '{{jp_exe}}'
mode: +x

View File

@@ -0,0 +1,6 @@
---
- name: install apt package
become: true
apt:
name: jp
state: latest

4
roles/jp/tasks/main.yaml Normal file
View File

@@ -0,0 +1,4 @@
---
- assert:
that: ansible_os_family != "Windows"
- include_tasks: '{{ansible_os_family}}.yaml'

View File

@@ -0,0 +1,5 @@
---
- name: install chocolatey package
win_chocolatey:
name: moonlight-qt
state: latest

View File

@@ -0,0 +1,2 @@
---
- include_tasks: '{{ansible_os_family}}.yaml'

View File

@@ -4,4 +4,4 @@
name: neovim name: neovim
state: latest state: latest
- include_tasks: unix.yaml - include_tasks: Unix.yaml

View File

@@ -5,4 +5,4 @@
name: neovim name: neovim
state: latest state: latest
- include_tasks: unix.yaml - include_tasks: Unix.yaml

View File

@@ -0,0 +1,36 @@
---
- name: clone plugin repos
git:
repo: 'https://github.com/{{item.repo}}.git'
dest: '{{plugin_dir}}/{{item.mode | default("start")}}/{{item.repo | regex_replace("^.*\/(.*)$", "\1")}}'
version: '{{item.branch | default("HEAD")}}'
with_items: '{{plugins}}'
- name: get list of managed plugin paths
set_fact:
managed_plugins: >-
{{
managed_plugins | default([]) + [
plugin_dir + "/" +
item.mode | default("start") + "/" +
item.repo | regex_replace("^.*\/(.*)$", "\1")
]
}}
with_items: '{{plugins}}'
- name: find all installed plugin directories
find:
paths:
- '{{plugin_dir}}/start'
- '{{plugin_dir}}/opt'
file_type: directory
register: found_plugins
- name: remove found plugins which are not in the managed list
file:
path: '{{item.path}}'
state: absent
with_items: '{{found_plugins.files}}'
when: item.path not in managed_plugins
loop_control:
label: '{{item.path}}'

View File

@@ -0,0 +1,28 @@
---
- set_fact:
vim_config_dir: '{{ansible_env.HOME}}/.config/nvim'
- name: clone config repo
git:
repo: git@code.infektor.net:config/vim.git
dest: '{{vim_config_dir}}'
version: master
# TODO: - name: set repo email
- name: install pip packages
pip:
name: '{{neovim_pip_packages}}'
state: latest
extra_args: --user
- name: check for config repo tasks.yaml
stat:
path: '{{vim_config_dir}}/tasks.yaml'
register: config_repo_tasks
- when: config_repo_tasks.stat.exists
include_tasks: '{{vim_config_dir}}/tasks.yaml'
- when: plugin_dir is defined and plugins is defined
include_tasks: 'Unix-plugins.yaml'

View File

@@ -0,0 +1,36 @@
---
- name: clone plugin repos
win_git:
repo: 'https://github.com/{{item.repo}}.git'
dest: '{{plugin_dir}}/{{item.mode | default("start")}}/{{item.repo | regex_replace("^.*\/(.*)$", "\1")}}'
branch: '{{item.branch | default("HEAD")}}'
with_items: '{{plugins}}'
- name: get list of managed plugin paths
set_fact:
managed_plugins: >-
{{
managed_plugins | default([]) + [
plugin_dir + "/" +
item.mode | default("start") + "/" +
item.repo | regex_replace("^.*\/(.*)$", "\1")
]
}}
with_items: '{{plugins}}'
- name: find all start plugin directories
win_find:
paths:
- '{{plugin_dir}}/start'
- '{{plugin_dir}}/opt'
file_type: directory
register: found_plugins
- name: remove found plugins which are not in the managed list
win_file:
path: '{{item.path}}'
state: absent
with_items: '{{found_plugins.files}}'
when: item.path not in managed_plugins
loop_control:
label: '{{item.path}}'

View File

@@ -1,22 +1,28 @@
--- ---
- set_fact:
nvim_config_dir: '{{ansible_env.LOCALAPPDATA}}/nvim'
- name: install chocolatey packages - name: install chocolatey packages
win_chocolatey: win_chocolatey:
name: neovim name: neovim
state: latest state: latest
- set_fact:
vim_config_dir: '{{ansible_env.LOCALAPPDATA}}\nvim'
- name: clone config repo - name: clone config repo
win_git: win_git:
repo: git@code.infektor.net:config/vim.git repo: git@code.infektor.net:config/vim.git
dest: '{{nvim_config_dir}}' dest: '{{vim_config_dir}}'
version: master branch: master
# clone: false
update: true
- win_owner: - win_owner:
path: '{{nvim_config_dir}}' path: '{{vim_config_dir}}'
user: Benie user: Benie
recurse: true recurse: true
- assert:
that: False
# - TODO: neovim set repo email # - TODO: neovim set repo email
# win_git_config: # win_git_config:
# - TODO: neovim install pip packages # - TODO: neovim install pip packages
@@ -30,3 +36,27 @@
dest: '{{ansible_env.ProgramData}}/Microsoft/Windows/Start Menu/Programs/nvim-qt.lnk' dest: '{{ansible_env.ProgramData}}/Microsoft/Windows/Start Menu/Programs/nvim-qt.lnk'
icon: '{{ansible_env.ChocolateyToolsLocation}}/neovim/nvim-win64/bin/nvim-qt.exe,0' icon: '{{ansible_env.ChocolateyToolsLocation}}/neovim/nvim-win64/bin/nvim-qt.exe,0'
directory: '{{ansible_env.USERPROFILE}}' directory: '{{ansible_env.USERPROFILE}}'
- name: check for config repo tasks.yaml
win_stat:
path: '{{vim_config_dir}}/tasks.yaml'
register: config_repo_tasks
# TODO: this doesn't work for non localhost setups
# probably need to copy the tasks.yaml and plugins.yaml to the controller in a
# temporary directory then include them
- when: config_repo_tasks.stat.exists
fetch:
src: '{{vim_config_dir}}/tasks.yaml'
dest: vim_config_tasks.yaml
flat: true
- when: config_repo_tasks.stat.exists
include_tasks: vim_config_tasks.yaml
- when: ansible_os_family != "Windows" and
plugin_dir is defined and plugins is defined
include_tasks: 'Unix-plugins.yaml'
- when: ansible_os_family == "Windows" and
plugin_dir is defined and plugins is defined
include_tasks: 'Windows-plugins.yaml'

View File

@@ -1,14 +0,0 @@
---
- name: clone config repo
git:
repo: git@code.infektor.net:config/vim.git
dest: ~/.config/nvim
version: master
# TODO: - name: set repo email
- name: install pip packages
pip:
name: '{{neovim_pip_packages}}'
state: latest
extra_args: --user

View File

@@ -0,0 +1,8 @@
---
- assert:
that: ansible_os_family == 'Windows'
- name: install chocolatey package
win_chocolatey:
name: powertoys
state: present

View File

@@ -0,0 +1,8 @@
---
- assert:
that: ansible_os_family == "Windows"
- name: install chocolatey package
win_chocolatey:
name: prusaslicer
state: latest

View File

@@ -0,0 +1,5 @@
---
- name: create .inputrc config file
template:
src: inputrc
dest: '{{ansible_env.HOME}}/.inputrc'

View File

@@ -0,0 +1,11 @@
# Enable vi mode
set editing-mode vi
# Insert mode mappings
set keymap vi-insert
"\C-[": vi-movement-mode
# Change cursor shape on vi mode change
set show-mode-in-prompt on
set vi-cmd-mode-string "\1\e[2 q\2"
set vi-ins-mode-string "\1\e[6 q\2"

View File

@@ -0,0 +1,12 @@
---
- assert:
that: ansible_user_id != "root"
- name: create /etc/sudoers.d/{user} config file
become: true
template:
src: sudoers
dest: '/etc/sudoers.d/{{ansible_user_id}}'
owner: root
group: root
mode: '0440'

View File

@@ -0,0 +1 @@
{{ansible_user_id}} ALL=(ALL) NOPASSWD:ALL

View File

@@ -40,3 +40,21 @@
with_items: with_items:
- win_git.ps1 - win_git.ps1
- win_git.py - win_git.py
- name: read /etc/resolv.conf file contents
set_fact:
resolv_conf: '{{lookup("ansible.builtin.file", "/etc/resolv.conf")}}'
- name: get Windows host IP from /etc/resolv.conf
set_fact:
host_ip: '{{resolv_conf | regex_search("(\d+\.\d+\.\d+\.\d+)")}}'
- name: add $(hostname).local to /etc/hosts
become: true
lineinfile:
path: /etc/hosts
regexp: '^{{host_ip | replace(".", "\.")}}'
line: '{{host_ip}} {{ansible_hostname}}.local'
owner: root
group: root
mode: '0644'

View File

@@ -10,7 +10,7 @@
latest_version: '{{latest.json.tag_name[1:]}}' latest_version: '{{latest.json.tag_name[1:]}}'
yq_exe: '{{ansible_env.HOME}}/.local/bin/yq' yq_exe: '{{ansible_env.HOME}}/.local/bin/yq'
- name: check if alreayd installed - name: check if already installed
stat: stat:
path: '{{yq_exe}}' path: '{{yq_exe}}'
register: yq_stat register: yq_stat

View File

@@ -20,6 +20,8 @@
dest: ~/.config/zsh/zsh-syntax-highlighting dest: ~/.config/zsh/zsh-syntax-highlighting
- repo: https://github.com/zsh-users/zsh-completions.git - repo: https://github.com/zsh-users/zsh-completions.git
dest: ~/.config/zsh/zsh-completions dest: ~/.config/zsh/zsh-completions
loop_control:
label: '{{item.repo | regex_search("https://github.com/(.*)\.git$", "\1")}}'
- name: create directories - name: create directories
file: file:
@@ -59,6 +61,8 @@
dest: ~/.local/bin/cmake-uninstall dest: ~/.local/bin/cmake-uninstall
- src: ~/.config/zsh/$ - src: ~/.config/zsh/$
dest: ~/.local/bin/$ dest: ~/.local/bin/$
loop_control:
label: '{{item.dest}}'
- name: get absolute path - name: get absolute path
shell: command -v zsh shell: command -v zsh