Browse Source

Merge pull request #2 from mr-karan/nomad

Nomad
pull/3/head
Karan Sharma 8 months ago
committed by GitHub
parent
commit
36b83f3666
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      .gitignore
  2. 43
      README.md
  3. 14
      TODO.md
  4. 4
      ansible/Makefile
  5. 0
      ansible/README.md
  6. 0
      ansible/ansible.cfg
  7. 9
      ansible/inventory.hydra
  8. 0
      ansible/inventory.sample
  9. 22
      ansible/playbook.yml
  10. 0
      ansible/roles/bootstrap-node/handlers/main.yml
  11. 0
      ansible/roles/bootstrap-node/tasks/apt.yml
  12. 0
      ansible/roles/bootstrap-node/tasks/hostname.yml
  13. 0
      ansible/roles/bootstrap-node/tasks/locale.yml
  14. 0
      ansible/roles/bootstrap-node/tasks/main.yml
  15. 0
      ansible/roles/bootstrap-node/tasks/node-exporter.yml
  16. 0
      ansible/roles/bootstrap-node/tasks/ssh.yml
  17. 0
      ansible/roles/bootstrap-node/tasks/timezone.yml
  18. 0
      ansible/roles/bootstrap-node/tasks/user.yml
  19. 14
      ansible/roles/bootstrap-node/templates/ssh-banner.j2
  20. 0
      ansible/roles/bootstrap-node/vars/main.yml
  21. 0
      ansible/roles/setup-docker/handlers/main.yml
  22. 0
      ansible/roles/setup-docker/tasks/main.yml
  23. 0
      ansible/roles/setup-docker/templates/daemon.json
  24. 0
      ansible/roles/setup-tailscale/handlers/main.yml
  25. 0
      ansible/roles/setup-tailscale/tasks/main.yml
  26. 2
      ansible/roles/viasite-ansible.zsh/.gitignore
  27. 4
      ansible/roles/viasite-ansible.zsh/.gitlab-ci.yml
  28. 16
      ansible/roles/viasite-ansible.zsh/.travis.yml
  29. 411
      ansible/roles/viasite-ansible.zsh/CHANGELOG.md
  30. 289
      ansible/roles/viasite-ansible.zsh/README.md
  31. 11
      ansible/roles/viasite-ansible.zsh/Vagrantfile
  32. 193
      ansible/roles/viasite-ansible.zsh/defaults/main.yml
  33. 28
      ansible/roles/viasite-ansible.zsh/install.sh
  34. 2
      ansible/roles/viasite-ansible.zsh/meta/.galaxy_install_info
  35. 29
      ansible/roles/viasite-ansible.zsh/meta/main.yml
  36. 49
      ansible/roles/viasite-ansible.zsh/molecule/default/molecule.yml
  37. 17
      ansible/roles/viasite-ansible.zsh/molecule/default/tests/test_default.py
  38. 4
      ansible/roles/viasite-ansible.zsh/molecule/resources/converge.yml
  39. 13
      ansible/roles/viasite-ansible.zsh/molecule/resources/prepare.yml
  40. 34
      ansible/roles/viasite-ansible.zsh/molecule/shared/molecule.yml
  41. 34
      ansible/roles/viasite-ansible.zsh/molecule/user/molecule.yml
  42. 16
      ansible/roles/viasite-ansible.zsh/molecule/user/prepare.yml
  43. 9
      ansible/roles/viasite-ansible.zsh/playbook.yml
  44. 31
      ansible/roles/viasite-ansible.zsh/scripts/generate-changelog
  45. 75
      ansible/roles/viasite-ansible.zsh/tasks/configure.yml
  46. 79
      ansible/roles/viasite-ansible.zsh/tasks/install.yml
  47. 18
      ansible/roles/viasite-ansible.zsh/tasks/main.yml
  48. 15
      ansible/roles/viasite-ansible.zsh/tasks/post-install.yml
  49. 173
      ansible/roles/viasite-ansible.zsh/templates/zshrc.j2
  50. 4
      ansible/roles/viasite-ansible.zsh/tests/vagrant.yml
  51. 15
      ansible/roles/viasite-ansible.zsh/vars/main.yml
  52. 166
      docs/SETUP.md
  53. BIN
      docs/calvin.jpg
  54. 0
      floyd/ansible/Makefile
  55. 36
      floyd/ansible/playbook.yml
  56. 23
      floyd/ansible/roles/gantsign.antigen/.editorconfig
  57. 25
      floyd/ansible/roles/gantsign.antigen/.gitattributes
  58. 297
      floyd/ansible/roles/gantsign.antigen/.gitignore
  59. 1
      floyd/ansible/roles/gantsign.antigen/.moleculew/ansible_version
  60. 1
      floyd/ansible/roles/gantsign.antigen/.moleculew/docker_lib_version
  61. 1
      floyd/ansible/roles/gantsign.antigen/.moleculew/molecule_version
  62. 1
      floyd/ansible/roles/gantsign.antigen/.moleculew/python_version
  63. 76
      floyd/ansible/roles/gantsign.antigen/.travis.yml
  64. 13
      floyd/ansible/roles/gantsign.antigen/.yamllint
  65. 21
      floyd/ansible/roles/gantsign.antigen/LICENSE
  66. 198
      floyd/ansible/roles/gantsign.antigen/README.md
  67. 15
      floyd/ansible/roles/gantsign.antigen/defaults/main.yml
  68. 4
      floyd/ansible/roles/gantsign.antigen/handlers/main.yml
  69. 2
      floyd/ansible/roles/gantsign.antigen/meta/.galaxy_install_info
  70. 33
      floyd/ansible/roles/gantsign.antigen/meta/main.yml
  71. 14
      floyd/ansible/roles/gantsign.antigen/molecule/centos/Dockerfile.j2
  72. 26
      floyd/ansible/roles/gantsign.antigen/molecule/centos/INSTALL.rst
  73. 29
      floyd/ansible/roles/gantsign.antigen/molecule/centos/molecule.yml
  74. 14
      floyd/ansible/roles/gantsign.antigen/molecule/debian_max/Dockerfile.j2
  75. 26
      floyd/ansible/roles/gantsign.antigen/molecule/debian_max/INSTALL.rst
  76. 29
      floyd/ansible/roles/gantsign.antigen/molecule/debian_max/molecule.yml
  77. 14
      floyd/ansible/roles/gantsign.antigen/molecule/debian_min/Dockerfile.j2
  78. 26
      floyd/ansible/roles/gantsign.antigen/molecule/debian_min/INSTALL.rst
  79. 29
      floyd/ansible/roles/gantsign.antigen/molecule/debian_min/molecule.yml
  80. 14
      floyd/ansible/roles/gantsign.antigen/molecule/default/Dockerfile.j2
  81. 26
      floyd/ansible/roles/gantsign.antigen/molecule/default/INSTALL.rst
  82. 26
      floyd/ansible/roles/gantsign.antigen/molecule/default/molecule.yml
  83. 68
      floyd/ansible/roles/gantsign.antigen/molecule/default/playbook.yml
  84. 16
      floyd/ansible/roles/gantsign.antigen/molecule/default/tests/console-setup.sh
  85. 272
      floyd/ansible/roles/gantsign.antigen/molecule/default/tests/test_role.py
  86. 14
      floyd/ansible/roles/gantsign.antigen/molecule/fedora/Dockerfile.j2
  87. 26
      floyd/ansible/roles/gantsign.antigen/molecule/fedora/INSTALL.rst
  88. 29
      floyd/ansible/roles/gantsign.antigen/molecule/fedora/molecule.yml
  89. 14
      floyd/ansible/roles/gantsign.antigen/molecule/opensuse/Dockerfile.j2
  90. 26
      floyd/ansible/roles/gantsign.antigen/molecule/opensuse/INSTALL.rst
  91. 29
      floyd/ansible/roles/gantsign.antigen/molecule/opensuse/molecule.yml
  92. 14
      floyd/ansible/roles/gantsign.antigen/molecule/ubuntu_max/Dockerfile.j2
  93. 26
      floyd/ansible/roles/gantsign.antigen/molecule/ubuntu_max/INSTALL.rst
  94. 29
      floyd/ansible/roles/gantsign.antigen/molecule/ubuntu_max/molecule.yml
  95. 14
      floyd/ansible/roles/gantsign.antigen/molecule/ubuntu_min/Dockerfile.j2
  96. 26
      floyd/ansible/roles/gantsign.antigen/molecule/ubuntu_min/INSTALL.rst
  97. 29
      floyd/ansible/roles/gantsign.antigen/molecule/ubuntu_min/molecule.yml
  98. 792
      floyd/ansible/roles/gantsign.antigen/moleculew
  99. 27
      floyd/ansible/roles/gantsign.antigen/tasks/configure-debian-console.yml
  100. 98
      floyd/ansible/roles/gantsign.antigen/tasks/configure.yml

3
.gitignore

@ -10,4 +10,5 @@ inventory
*.backup
*.env
AdGuardHome.yaml
.ci-vault-pass
.ci-vault-pass
consul-keys.txt

43
README.md

@ -1,14 +1,41 @@
# Hydra
<!-- PROJECT LOGO -->
<br />
<p align="center">
<h2 align="center">hydra</h2>
<p align="center">
<i>Setup scripts for my homelab</i>
</p>
<img src="docs/calvin.jpg" alt="Calvin and Hobbes">
</p>
> Setup scripts for my home server setup named "Hydra"
---
## Overview
TODO.
- Single node [Nomad](https://www.nomadproject.io/) server for running workloads.
- [Consul](https://www.consul.io/) agent co-located for service discovery.
- [Ansible](https://www.ansible.com/) scripts to boostrap the node.
- [Terraform](https://www.terraform.io/) modules for managing the following services:
- Nomad jobs
- Cloudflare DNS
- DigitalOcean Infra
- [Tailscale VPN](https://tailscale.com/) for connectivity to internal services.
- [Caddy](https://tailscale.com/) as a reverse proxy for all web services.
## Services Hosted
## Services Running
- Pihole + Unbound
- Tailscale for networking
- Gitea
- Bookstack
- [Pihole](https://pi-hole.net/)
- [Gitea](https://gitea.io/)
- [Shynet](https://github.com/milesmcc/shynet)
- [Joplin Sync Server](https://github.com/laurent22/joplin/tree/dev/packages/server)
## Blog Posts
Here's a collection of posts I've written which shows how Hydra has evolved over the years:
- **23 April 2020**: [Home Server Updates](https://mrkaran.dev/posts/home-server-updates/)
- **22 September 2019**: [Home Server Setup](https://mrkaran.dev/posts/home-server-setup/)
## Setup Instructions
Visit [SETUP.md](./docs/SETUP.md) for following instructions on setting up Nomad and Consul.

14
TODO.md

@ -0,0 +1,14 @@
## Baby Steps
- [x] Setup Tailscale in Floyd/Gilmour.
- [x] Configure Nomad and Consul to bind on Tailscale Address.
- [x] Deploy Caddy as a Nomad Job which
- [x] binds to 80/443 on host
- [x] mounts the cert directory
- [x] template file (caddy.tpl)
- [x] Configure `nomad.mrkaran.dev` and `consul.mrkaran.dev`.
- [x] Create Terraform module for running workloads as Nomad jobs.
## Hands on by deploying more workloads
- [x] Deploy `shynet.mrkaran.dev`

4
ansible/Makefile

@ -0,0 +1,4 @@
.PHONY: run
run:
ansible-playbook playbook.yml -i inventory --extra-vars "hosts=hydra"

0
floyd/ansible/README.md → ansible/README.md

0
floyd/ansible/ansible.cfg → ansible/ansible.cfg

9
ansible/inventory.hydra

@ -0,0 +1,9 @@
[hydra:children]
floyd
[floyd]
floyd ansible_ssh_host=floyd ansible_ssh_user=karan ansible_ssh_port=22 remote_ssh_user=karan
[floyd:vars]
username=karan
github_ssh_key_url=https://github.com/mr-karan.keys

0
floyd/ansible/inventory.sample → ansible/inventory.sample

22
ansible/playbook.yml

@ -0,0 +1,22 @@
---
- hosts: all
roles:
- role: bootstrap-node
tags:
- bootstrap
- role: setup-docker
become: true
tags:
- docker
- role: setup-tailscale
become: yes
tags:
- tailscale
- role: viasite-ansible.zsh
become: yes
tags:
- zsh

0
floyd/ansible/roles/bootstrap-node/handlers/main.yml → ansible/roles/bootstrap-node/handlers/main.yml

0
floyd/ansible/roles/bootstrap-node/tasks/apt.yml → ansible/roles/bootstrap-node/tasks/apt.yml

0
floyd/ansible/roles/bootstrap-node/tasks/hostname.yml → ansible/roles/bootstrap-node/tasks/hostname.yml

0
floyd/ansible/roles/bootstrap-node/tasks/locale.yml → ansible/roles/bootstrap-node/tasks/locale.yml

0
floyd/ansible/roles/bootstrap-node/tasks/main.yml → ansible/roles/bootstrap-node/tasks/main.yml

0
floyd/ansible/roles/bootstrap-node/tasks/node-exporter.yml → ansible/roles/bootstrap-node/tasks/node-exporter.yml

0
floyd/ansible/roles/bootstrap-node/tasks/ssh.yml → ansible/roles/bootstrap-node/tasks/ssh.yml

0
floyd/ansible/roles/bootstrap-node/tasks/timezone.yml → ansible/roles/bootstrap-node/tasks/timezone.yml

0
floyd/ansible/roles/bootstrap-node/tasks/user.yml → ansible/roles/bootstrap-node/tasks/user.yml

14
floyd/ansible/roles/bootstrap-node/templates/ssh-banner.j2 → ansible/roles/bootstrap-node/templates/ssh-banner.j2

@ -1,8 +1,8 @@
********************************************************************
* Welcome to Hydra! The HomeLab Server. *
* *
* This system is for the use of authorized users only. Usage of *
* this system may be monitored and recorded by system personnel. *
* *
********************************************************************
********************************************************************************
* Welcome to {{ansible_hostname}}! The Hydra HomeLab Server. *
* *
* This system is for the use of authorized users only. Usage of *
* this system may be monitored and recorded by system personnel. *
* *
********************************************************************************

0
floyd/ansible/roles/bootstrap-node/vars/main.yml → ansible/roles/bootstrap-node/vars/main.yml

0
floyd/ansible/roles/setup-docker/handlers/main.yml → ansible/roles/setup-docker/handlers/main.yml

0
floyd/ansible/roles/setup-docker/tasks/main.yml → ansible/roles/setup-docker/tasks/main.yml

0
floyd/ansible/roles/setup-docker/templates/daemon.json → ansible/roles/setup-docker/templates/daemon.json

0
floyd/ansible/roles/setup-tailscale/handlers/main.yml → ansible/roles/setup-tailscale/handlers/main.yml

0
floyd/ansible/roles/setup-tailscale/tasks/main.yml → ansible/roles/setup-tailscale/tasks/main.yml

2
ansible/roles/viasite-ansible.zsh/.gitignore

@ -0,0 +1,2 @@
.molecule
00aptproxy

4
ansible/roles/viasite-ansible.zsh/.gitlab-ci.yml

@ -0,0 +1,4 @@
---
test:
script:
- molecule test --all

16
ansible/roles/viasite-ansible.zsh/.travis.yml

@ -0,0 +1,16 @@
---
language: python
python: "2.7"
sudo: required
services:
- docker
before_install:
- docker --version
install:
- pip install molecule docker
script:
- molecule test --all
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

411
ansible/roles/viasite-ansible.zsh/CHANGELOG.md

@ -0,0 +1,411 @@
# [master](https://github.com/viasite-ansible/ansible-role-zsh/compare/v3.2.6...v) (2020-05-01)
### Bug Fixes
* configurable zsh_fzf_path variable and change $HOME/.bin to $HOME/bin ([5b9ab7a](https://github.com/viasite-ansible/ansible-role-zsh/commit/5b9ab7a))
* extending of PATH not just rewrite ([6c2fdd7](https://github.com/viasite-ansible/ansible-role-zsh/commit/6c2fdd7)), closes [#14](https://github.com/viasite-ansible/ansible-role-zsh/issues/14)
### Features
* fzf path should be /usr/local/bin only in shared scenarios, otherwise it should be installed in local user home ([e3ada98](https://github.com/viasite-ansible/ansible-role-zsh/commit/e3ada98))
## [3.2.5](https://github.com/viasite-ansible/ansible-role-zsh/compare/v3.2.4...v3.2.5) (2019-03-14)
### Bug Fixes
* check commands in in check mode ([030bc1f](https://github.com/viasite-ansible/ansible-role-zsh/commit/030bc1f)), closes [#31](https://github.com/viasite-ansible/ansible-role-zsh/issues/31)
## [3.2.4](https://github.com/viasite-ansible/ansible-role-zsh/compare/v3.2.3...v3.2.4) (2019-03-14)
### Bug Fixes
* correct run in check mode ([9f6d88b](https://github.com/viasite-ansible/ansible-role-zsh/commit/9f6d88b)), closes [#31](https://github.com/viasite-ansible/ansible-role-zsh/issues/31)
## [3.2.3](https://github.com/viasite-ansible/ansible-role-zsh/compare/v3.2.2...v3.2.3) (2018-11-21)
### Bug Fixes
* add POWERLEVEL9K_CONTEXT_REMOTE colors same as POWERLEVEL9K_CONTEXT_DEFAULT ([6794785](https://github.com/viasite-ansible/ansible-role-zsh/commit/6794785))
* don't use paths like ~user in config ([40150ec](https://github.com/viasite-ansible/ansible-role-zsh/commit/40150ec))
* freeze zdharma/fast-syntax-highlighting at v1.2 ([1765bff](https://github.com/viasite-ansible/ansible-role-zsh/commit/1765bff))
* unquote path ([3677d78](https://github.com/viasite-ansible/ansible-role-zsh/commit/3677d78))
### Features
* shared installation for many users, zsh_shared ([0bdba8e](https://github.com/viasite-ansible/ansible-role-zsh/commit/0bdba8e))
* zsh_aliases ([2770ec3](https://github.com/viasite-ansible/ansible-role-zsh/commit/2770ec3))
## [3.2.2](https://github.com/viasite-ansible/ansible-role-zsh/compare/v3.2.1...v3.2.2) (2018-06-13)
### Bug Fixes
* upgrade fzf 0.17.3 -> 0.17.4 ([98a0569](https://github.com/viasite-ansible/ansible-role-zsh/commit/98a0569))
## [3.2.1](https://github.com/viasite-ansible/ansible-role-zsh/compare/v3.2.0...v3.2.1) (2018-05-01)
### Features
* Midnight Commander Solarized Dark skin ([0017e34](https://github.com/viasite-ansible/ansible-role-zsh/commit/0017e34))
# [3.2.0](https://github.com/viasite-ansible/ansible-role-zsh/compare/v3.1.2...v3.2.0) (2018-01-11)
### Bug Fixes
* alias 'suser' ([ba34e57](https://github.com/viasite-ansible/ansible-role-zsh/commit/ba34e57))
* update fzf to 0.6.11 ([385dc9d](https://github.com/viasite-ansible/ansible-role-zsh/commit/385dc9d))
* upgrade fzf 0.16.11 -> 0.17.3 ([1a08ef2](https://github.com/viasite-ansible/ansible-role-zsh/commit/1a08ef2))
### Features
* install.sh for current user ([a7c998e](https://github.com/viasite-ansible/ansible-role-zsh/commit/a7c998e))
## [3.1.2](https://github.com/viasite-ansible/ansible-role-zsh/compare/v3.1.1...v3.1.2) (2017-06-21)
### Features
* add viasite-ansible/zsh-ansible-server bundle ([3c990b2](https://github.com/viasite-ansible/ansible-role-zsh/commit/3c990b2))
## [3.1.1](https://github.com/viasite-ansible/ansible-role-zsh/compare/v3.1.0...v3.1.1) (2017-06-14)
### Bug Fixes
* update fzf to 0.16.8 ([0e7b913](https://github.com/viasite-ansible/ansible-role-zsh/commit/0e7b913))
### Features
* add systemd bundle ([40c34d0](https://github.com/viasite-ansible/ansible-role-zsh/commit/40c34d0))
# [3.1.0](https://github.com/viasite-ansible/ansible-role-zsh/compare/v3.0.3...v3.1.0) (2017-05-27)
### Features
* add github-*, fzf-insert-* widgets (ytet5uy4/fzf-widgets update) ([23a7e9c](https://github.com/viasite-ansible/ansible-role-zsh/commit/23a7e9c))
## [3.0.3](https://github.com/viasite-ansible/ansible-role-zsh/compare/v3.0.2...v3.0.3) (2017-05-27)
### Bug Fixes
* update ytet5uy4/[email protected] ([58965f1](https://github.com/viasite-ansible/ansible-role-zsh/commit/58965f1))
## [3.0.2](https://github.com/viasite-ansible/ansible-role-zsh/compare/v3.0.1...v3.0.2) (2017-05-26)
### Bug Fixes
* switch antigen branch from develop to master ([6141a02](https://github.com/viasite-ansible/ansible-role-zsh/commit/6141a02))
### Features
* disable zsh share history (unsetopt share_history) ([de0b5ae](https://github.com/viasite-ansible/ansible-role-zsh/commit/de0b5ae)), closes [#16](https://github.com/viasite-ansible/ansible-role-zsh/issues/16)
## [3.0.1](https://github.com/viasite-ansible/ansible-role-zsh/compare/v3.0.0...v3.0.1) (2017-05-14)
### Bug Fixes
* idempotence and correct `antigen reset` ([44bd345](https://github.com/viasite-ansible/ansible-role-zsh/commit/44bd345))
### Features
* upgrade to antigen v2 ([a85cc77](https://github.com/viasite-ansible/ansible-role-zsh/commit/a85cc77)), closes [#12](https://github.com/viasite-ansible/ansible-role-zsh/issues/12)
## [2.1.8](https://github.com/viasite-ansible/ansible-role-zsh/compare/v2.1.7...v2.1.8) (2017-05-13)
### Bug Fixes
* make working command conditions on clean centos ([71399b8](https://github.com/viasite-ansible/ansible-role-zsh/commit/71399b8)), closes [#8](https://github.com/viasite-ansible/ansible-role-zsh/issues/8)
## [2.1.7](https://github.com/viasite-ansible/ansible-role-zsh/compare/v2.1.6...v2.1.7) (2017-05-13)
### Bug Fixes
* replace popstas/zsh-command-time to native powerlevel9k segment ([24e3480](https://github.com/viasite-ansible/ansible-role-zsh/commit/24e3480)), closes [#13](https://github.com/viasite-ansible/ansible-role-zsh/issues/13)
### Features
* hide host and/or user on local machine (powerlevel9k 0.6 feature) ([12630d4](https://github.com/viasite-ansible/ansible-role-zsh/commit/12630d4)), closes [#15](https://github.com/viasite-ansible/ansible-role-zsh/issues/15)
## [2.1.6](https://github.com/viasite-ansible/ansible-role-zsh/compare/v2.1.5...v2.1.6) (2017-04-26)
### Bug Fixes
* skip early compinit execute on Ubuntu ([f581c7b](https://github.com/viasite-ansible/ansible-role-zsh/commit/f581c7b)), closes [#9](https://github.com/viasite-ansible/ansible-role-zsh/issues/9)
### Features
* add docker widgets from updated ytet5uy4/fzf-widgets ([ee84bf3](https://github.com/viasite-ansible/ansible-role-zsh/commit/ee84bf3))
## [2.1.5](https://github.com/viasite-ansible/ansible-role-zsh/compare/v2.1.4...v2.1.5) (2017-04-25)
### Bug Fixes
* make condition for disable command-not-found for macOS ([d789633](https://github.com/viasite-ansible/ansible-role-zsh/commit/d789633)), closes [#7](https://github.com/viasite-ansible/ansible-role-zsh/issues/7)
## [2.1.4](https://github.com/viasite-ansible/ansible-role-zsh/compare/v2.1.3...v2.1.4) (2017-04-23)
### Bug Fixes
* support check `command` exists for zsh_antigen_bundles_extras ([b6e4284](https://github.com/viasite-ansible/ansible-role-zsh/commit/b6e4284))
### Features
* add fzf-kill-process to ytet5uy4/fzf-widgets ([8bc9e93](https://github.com/viasite-ansible/ansible-role-zsh/commit/8bc9e93))
* add viasite/drall, viasite/server-scripts bundles ([74d3451](https://github.com/viasite-ansible/ansible-role-zsh/commit/74d3451))
## [2.1.3](https://github.com/viasite-ansible/ansible-role-zsh/compare/v2.1.2...v2.1.3) (2017-04-21)
### Features
* add viasite/drupal-scripts bundle for drs ([7371bde](https://github.com/viasite-ansible/ansible-role-zsh/commit/7371bde))
## [2.1.2](https://github.com/viasite-ansible/ansible-role-zsh/compare/v2.1.1...v2.1.2) (2017-04-19)
### Bug Fixes
* removed debian plugin from zsh_antigen_bundles ([ddb600e](https://github.com/viasite-ansible/ansible-role-zsh/commit/ddb600e)), closes [#6](https://github.com/viasite-ansible/ansible-role-zsh/issues/6)
## [2.1.1](https://github.com/viasite-ansible/ansible-role-zsh/compare/v2.1.0...v2.1.1) (2017-04-16)
### Bug Fixes
* HIST_STAMPS, COMPLETION_WAITING_DOTS don't work if it before antigen apply ([4093191](https://github.com/viasite-ansible/ansible-role-zsh/commit/4093191))
* provision role for root on macOS ([2d1f939](https://github.com/viasite-ansible/ansible-role-zsh/commit/2d1f939))
### Features
* zsh-users/zsh-syntax-highlighting -> zdharma/fast-syntax-highlighting ([ff3542f](https://github.com/viasite-ansible/ansible-role-zsh/commit/ff3542f))
# [2.1.0](https://github.com/viasite-ansible/ansible-role-zsh/compare/v2.0.4...v2.1.0) (2017-04-08)
### Bug Fixes
* role broken on 'Check commands exists' when skipped ([0676934](https://github.com/viasite-ansible/ansible-role-zsh/commit/0676934))
### Features
* new widget: fzf-git-delete-branches, add --exact to insert-history ([15d22a4](https://github.com/viasite-ansible/ansible-role-zsh/commit/15d22a4)), closes [ytet5uy4/fzf-widgets#2](https://github.com/ytet5uy4/fzf-widgets/issues/2)
## [2.0.4](https://github.com/viasite-ansible/ansible-role-zsh/compare/v2.0.3...v2.0.4) (2017-04-03)
### Bug Fixes
* hotkeys with bundle dependency don't enabled if bundle was dict ([4187981](https://github.com/viasite-ansible/ansible-role-zsh/commit/4187981))
### Features
* add copy-earlier-word to widgets ([ec4382b](https://github.com/viasite-ansible/ansible-role-zsh/commit/ec4382b))
* zsh_hotkeys_extras variable for custom hotkeys ([e7e8b25](https://github.com/viasite-ansible/ansible-role-zsh/commit/e7e8b25))
## [2.0.3](https://github.com/viasite-ansible/ansible-role-zsh/compare/v2.0.2...v2.0.3) (2017-04-03)
### Bug Fixes
* add debian jessie to platforms ([995c601](https://github.com/viasite-ansible/ansible-role-zsh/commit/995c601))
* move TERM var above theme, for zsh 4.3 ([7030837](https://github.com/viasite-ansible/ansible-role-zsh/commit/7030837))
* zsh, disable autosuggestions for zsh 4.3 ([76521c9](https://github.com/viasite-ansible/ansible-role-zsh/commit/76521c9))
## [2.0.2](https://github.com/viasite-ansible/ansible-role-zsh/compare/v2.0.1...v2.0.2) (2017-04-02)
### Bug Fixes
* fzf install for macOS ([ce924e6](https://github.com/viasite-ansible/ansible-role-zsh/commit/ce924e6))
* remove composer plugin from defaults ([7dd8aa3](https://github.com/viasite-ansible/ansible-role-zsh/commit/7dd8aa3))
* zsh-syntax-highlighting loaded on zsh 4.3.10 ([6062c8d](https://github.com/viasite-ansible/ansible-role-zsh/commit/6062c8d))
## [2.0.1](https://github.com/viasite-ansible/ansible-role-zsh/compare/v2.0.0...v2.0.1) (2017-04-02)
### Bug Fixes
* remove zsh_check_commands, now it calculates dynamically ([84c36ca](https://github.com/viasite-ansible/ansible-role-zsh/commit/84c36ca))
### Features
* zsh_antigen_bundles_extras for custom bundles ([0e2ac6a](https://github.com/viasite-ansible/ansible-role-zsh/commit/0e2ac6a)), closes [#5](https://github.com/viasite-ansible/ansible-role-zsh/issues/5)
# [2.0.0](https://github.com/viasite-ansible/ansible-role-zsh/compare/v1.1.6...v2.0.0) (2017-04-02)
### Bug Fixes
* change antigen version to `master` for idempotency ([dee73e8](https://github.com/viasite-ansible/ansible-role-zsh/commit/dee73e8))
* check for fzf installed any way ([d5f8aae](https://github.com/viasite-ansible/ansible-role-zsh/commit/d5f8aae))
* don't install tmux if plugin enabled, but enable plugin if tmux installed ([640ab24](https://github.com/viasite-ansible/ansible-role-zsh/commit/640ab24))
* install.sh tested on ubuntu and debian ([bcb9112](https://github.com/viasite-ansible/ansible-role-zsh/commit/bcb9112))
* merge install-* files, use `package` module ([a2f89b9](https://github.com/viasite-ansible/ansible-role-zsh/commit/a2f89b9))
* powerlevel9k correct load on zsh 4.3 ([ce2f629](https://github.com/viasite-ansible/ansible-role-zsh/commit/ce2f629))
* white color in phpstorm solarized dark terminal ([422f99c](https://github.com/viasite-ansible/ansible-role-zsh/commit/422f99c))
### Features
* add naive RedHat support ([102080b](https://github.com/viasite-ansible/ansible-role-zsh/commit/102080b))
* antigen plugin manager ([80f4eab](https://github.com/viasite-ansible/ansible-role-zsh/commit/80f4eab))
* junegunn/fzf replaced with more functional ytet5uy4/fzf-widgets ([ffd2d6e](https://github.com/viasite-ansible/ansible-role-zsh/commit/ffd2d6e))
* load plugin only if command exists in system or if custom `when` is true ([e9288c2](https://github.com/viasite-ansible/ansible-role-zsh/commit/e9288c2)), closes [#2](https://github.com/viasite-ansible/ansible-role-zsh/issues/2)
* zero-knowledge install.sh, docs ([d145b59](https://github.com/viasite-ansible/ansible-role-zsh/commit/d145b59))
* zsh_hotkeys with bundle dependency ([cbacc3d](https://github.com/viasite-ansible/ansible-role-zsh/commit/cbacc3d)), closes [#4](https://github.com/viasite-ansible/ansible-role-zsh/issues/4)
## [1.1.5](https://github.com/viasite-ansible/ansible-role-zsh/compare/v1.1.4...v1.1.5) (2017-03-09)
### Bug Fixes
* backup .zshrc ([81e5650](https://github.com/viasite-ansible/ansible-role-zsh/commit/81e5650))
## [1.1.4](https://github.com/viasite-ansible/ansible-role-zsh/compare/v1.1.3...v1.1.4) (2017-03-08)
### Features
* zsh_autosuggestions_bind_key_2 ([368fb68](https://github.com/viasite-ansible/ansible-role-zsh/commit/368fb68))
## [1.1.3](https://github.com/viasite-ansible/ansible-role-zsh/compare/v1.1.2...v1.1.3) (2017-03-08)
### Bug Fixes
* vcs color foreground black on any color scheme ([2d0d102](https://github.com/viasite-ansible/ansible-role-zsh/commit/2d0d102))
## [1.1.2](https://github.com/viasite-ansible/ansible-role-zsh/compare/v1.1.1...v1.1.2) (2017-03-06)
### Bug Fixes
* cannot bind to an empty key sequence for 'zsh_autosuggestions_bind_key' ([94074fa](https://github.com/viasite-ansible/ansible-role-zsh/commit/94074fa))
* idempotence when update git from root to user ([092dbcc](https://github.com/viasite-ansible/ansible-role-zsh/commit/092dbcc))
* macos permissions ([232c0a9](https://github.com/viasite-ansible/ansible-role-zsh/commit/232c0a9))
* remove zsh-highlighting on --tags configure ([802fcba](https://github.com/viasite-ansible/ansible-role-zsh/commit/802fcba))
## [1.1.1](https://github.com/viasite-ansible/ansible-role-zsh/compare/v1.1.0...v1.1.1) (2017-03-05)
### Bug Fixes
* workaround for zsh-users/zsh-syntax-highlighting[#286](https://github.com/viasite-ansible/ansible-role-zsh/issues/286) ([372633b](https://github.com/viasite-ansible/ansible-role-zsh/commit/372633b))
# [1.1.0](https://github.com/viasite-ansible/ansible-role-zsh/compare/v1.0.0...v1.1.0) (2017-03-05)
### Bug Fixes
* transfer ownership from popstas to viasite ([b898fe0](https://github.com/viasite-ansible/ansible-role-zsh/commit/b898fe0))
### Features
* rewrite: switch to powerlevel9k and per user files ([9ef2300](https://github.com/viasite-ansible/ansible-role-zsh/commit/9ef2300))
* rewrite: switch to powerlevel9k and per user files ([69ddc67](https://github.com/viasite-ansible/ansible-role-zsh/commit/69ddc67))
* rewrite: switch to powerlevel9k and per user files ([fa99913](https://github.com/viasite-ansible/ansible-role-zsh/commit/fa99913))
# [1.0.0](https://github.com/viasite-ansible/ansible-role-zsh/compare/1c12b96...v1.0.0) (2017-02-23)
### Bug Fixes
* setup other user than ansible_remote_user ([1c12b96](https://github.com/viasite-ansible/ansible-role-zsh/commit/1c12b96))

289
ansible/roles/viasite-ansible.zsh/README.md

@ -0,0 +1,289 @@
[![Build Status](https://travis-ci.org/viasite-ansible/ansible-role-zsh.svg?branch=master)](https://travis-ci.org/viasite-ansible/ansible-role-zsh)
Tested on Debian 10, Ubuntu 16.04, Ubuntu 18.04, Ubuntu 20.04, macOS 10.12, CentOS 8.
**For upgrade from viasite-ansible.zsh 1.x, 2.x to 3.0 see [below](#upgrade).**
## Zero-knowledge install:
If you using Ubuntu or Debian and not familiar with Ansible, you can just execute [install.sh](install.sh) on target machine:
```
curl https://raw.githubusercontent.com/viasite-ansible/ansible-role-zsh/master/install.sh | bash
```
It will install pip3, ansible and setup zsh for root and current user.
Then [configure terminal application](#configure-terminal-application).
## Includes:
- zsh
- [antigen](https://github.com/zsh-users/antigen)
- [oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh)
- [powerlevel9k theme](https://github.com/bhilburn/powerlevel9k)
- [zsh-autosuggestions](https://github.com/zsh-users/zsh-autosuggestions)
- [zsh-syntax-highlighting](https://github.com/zsh-users/zsh-syntax-highlighting)
- [unixorn/autoupdate-antigen.zshplugin](https://github.com/unixorn/autoupdate-antigen.zshplugin)
- [ytet5uy4/fzf-widgets](https://github.com/ytet5uy4/fzf-widgets)
- [urbainvaes/fzf-marks](https://github.com/popstas/urbainvaes/fzf-marks)
## Features
- customize powerlevel9k theme prompt segments and colors
- default colors tested with solarized dark and default grey terminal in putty
- add custom prompt elements from yml
- custom zsh config with `~/.zshrc.local` or `/etc/zshrc.local`
- load `/etc/profile.d` scripts
- install only plugins that useful for your machine. For example, plugin `docker` will not install if you have not Docker
## 1.5 mins demo
![1.5 mins demo](https://github.com/popstas/popstas.github.io/blob/master/images/2017-03/ansible-role-zsh-demo.gif?raw=true)
## Color schemes
![colors demo](https://github.com/popstas/popstas.github.io/blob/master/images/2017-03/ansible-role-zsh-colors.gif?raw=true)
## Midnight Commander Solarized Dark skin
If you using Solarized Dark scheme and `mc`, you should want to install skin, then set `zsh_mc_solarized_skin: yes`
## Demo install in Vagrant
You can test work of role before install in real machine.
Just execute `vagrant up`, then `vagrant ssh` for enter in virtual machine.
Note: you cannot install vagrant on VPS like Digital Ocean or in Docker. Use local machine for it.
[Download](https://www.vagrantup.com/downloads.html) and install vagrant for your operating system.
## Install for real machine
Zero-knowledge install: see [above](#zero-knowledge-install).
### Manual install
0. [Install Ansible](http://docs.ansible.com/ansible/intro_installation.html).
For Ubuntu:
``` bash
sudo apt update
sudo apt install python3-pip -y
sudo pip3 install ansible
```
1. Download role:
```
ansible-galaxy install viasite-ansible.zsh --force
```
2. Write playbook or use [playbook.yml](playbook.yml):
```
- hosts: all
vars:
zsh_antigen_bundles_extras:
- nvm
- joel-porquet/zsh-dircolors-solarized
zsh_autosuggestions_bind_key: "^U"
roles:
- viasite-ansible.zsh
```
3. Provision playbook:
```
ansible-playbook -i "localhost," -c local -K playbook.yml
```
If you want to provision role for root user on macOS, you should install packages manually:
```
brew install zsh git wget
```
It will install zsh environment for ansible remote user. If you want to setup zsh for other users,
you should define variable `zsh_user`:
Via playbook:
```
- hosts: all
roles:
- { role: viasite-ansible.zsh, zsh_user: otheruser }
- { role: viasite-ansible.zsh, zsh_user: thirduser }
```
Or via command:
```
ansible-playbook -i hosts zsh.yml -e zsh_user=otheruser
```
4. Install fzf **without shell extensions**, [download binary](https://github.com/junegunn/fzf-bin/releases)
or `brew install fzf` for macOS.
Note: I don't use `tmux-fzf` and don't tested work of it.
## Multiuser shared install
If you have 10+ users on host, probably you don't want manage tens of configurations and thousands of files.
In this case you can deploy single zsh config and include it to all users.
It causes some limitations:
- Users have read only access to zsh config
- Users cannot disable global enabled bundles
- Possible bugs such cache write permission denied
- Possible bugs with oh-my-zsh themes
For install shared configuration you should set `zsh_shared: yes`.
Configuration will install to `/usr/share/zsh-config`, then you just can include to user config:
``` bash
source /usr/share/zsh-config/.zshrc
```
You can still provision custom configs for several users.
## Configure
You should not edit `~/.zshrc`!
Add your custom config to `~/.zshrc.local` (per user) or `/etc/zshrc.local` (global).
`.zshrc.local` will never touched by ansible.
### Configure terminal application
1. Download [powerline fonts](https://github.com/powerline/fonts), install font that you prefer.
You can see screenshots [here](https://github.com/powerline/fonts/blob/master/samples/All.md).
2. Set color scheme.
Personaly, I prefer Solarized Dark color sceme, Droid Sans Mono for Powerline in iTerm and DejaVu Sans Mono in Putty.
#### iTerm
Profiles - Text - Change Font - select font "for Powerline"
Profiles - Colors - Color Presets... - select Solarized Dark
#### Putty
Settings - Window - Appearance - Font settings
You can download [Solarized Dark for Putty](https://github.com/altercation/solarized/tree/master/putty-colors-solarized).
#### Gnome Terminal
gnome-terminal have built-in Solarized Dark, note that you should select both background color scheme and palette scheme.
### Hotkeys
You can view hotkeys in [defaults/main.yml](defaults/main.yml), `zsh_hotkeys`.
Sample hotkey definitions:
``` yaml
- { hotkey: '^r', action: 'fzf-history' }
# with dependency of bundle
- { hotkey: '`', action: autosuggest-accept, bundle: zsh-users/zsh-autosuggestions }
```
Useful to set `autosuggest-accept` to <kbd>`</kbd> hotkey, but it conflicts with Midnight Commander (break Ctrl+O subshell).
You can add your custom hotkeys without replace default hotkeys with `zsh_hotkeys_extras` variable:
``` yaml
zsh_hotkeys_extras:
- { hotkey: '^[^[[D', action: backward-word } # alt+left
- { hotkey: '^[^[[C', action: forward-word } # alt+right
# Example <Ctrl+.><Ctrl+,> inserts 2nd argument from end of prev. cmd
- { hotkey: '^[,', action: copy-earlier-word } # ctrl+,
```
### Aliases
You can use aliases for your command with easy deploy.
Aliases config mostly same as hotkeys config:
``` yaml
zsh_aliases:
- { alias: 'dfh', action: 'df -h | grep -v docker' }
# with dependency of bundle and without replace default asiases
- zsh_aliases_extra
- { alias: 'dfh', action: 'df -h | grep -v docker', bundle: }
```
#### Default hotkeys from plugins:
- <kbd>&rarr;</kbd> - accept autosuggestion
- <kbd>Ctrl+Z</kbd> - move current application to background, press again for return to foreground
- <kbd>Ctrl+G</kbd> - jump to bookmarked directory. Use `mark` in directory for add to bookmarks
- <kbd>Ctrl+R</kbd> - show command history
- <kbd>[email protected]</kbd> - show all fzf-widgets
- <kbd>[email protected],C</kbd> - fzf-change-dir, press fast!
- <kbd>Ctrl+\\</kbd> - fzf-change-recent-dir
- <kbd>[email protected],G</kbd> - fzf-change-repository
- <kbd>[email protected],F</kbd> - fzf-edit-files
- <kbd>[email protected],.</kbd> - fzf-edit-dotfiles
- <kbd>[email protected],S</kbd> - fzf-exec-ssh (using your ~/.ssh/config)
- <kbd>[email protected],G,A</kbd> - fzf-git-add-file
- <kbd>[email protected],G,B</kbd> - fzf-git-checkout-branch
- <kbd>[email protected],G,D</kbd> - fzf-git-delete-branches
## Configure bundles
You can check default bundles in [defaults/main.yml](defaults/main.yml#L37).
If you like default bundles, but you want to add your bundles, use `zsh_antigen_bundles_extras` variable (see example playbook above).
If you want to remove some default bundles, you should use `zsh_antigen_bundles` variable.
Format of list matches [antigen](https://github.com/zsh-users/antigen#antigen-bundle). All bellow variants valid:
``` yaml
- docker # oh-my-zsh plugin
- zsh-users/zsh-autosuggestions # plugin from github
- zsh-users/[email protected] # plugin from github with fixed version
- ~/projects/zsh/my-plugin --no-local-clone # plugin from local directory
```
Note that bundles can use conditions for load. There are two types of conditions:
1. Command conditions. Just add `command` to bundle:
``` yaml
- { name: docker, command: docker }
- name: docker-compose
command: docker-compose
```
Bundles `docker` and `docker-compose` will be added to config only if commands exists on target system.
2. When conditions. You can define any ansible conditions as you define in `when` in tasks:
``` yaml
# load only for zsh >= 4.3.17
- name: zsh-users/zsh-syntax-highlighting
when: "{{ zsh_version is version_compare('4.3.17', '>=') }}"
# load only for macOS
- { name: brew, when: "{{ ansible_os_family != 'Darwin' }}" }
```
Note: you should wrap condition in `"{{ }}"`
## Upgrade
viasite-ansible.zsh v3.0 introduces antigen v2.0, it don't have backward compatibility to antigen 1.x.
I don't spent much time for smooth upgrade, therefore you probably should do some manual actions:
if powerlevel9k prompt don't loaded after provision role, you should execute `antigen reset`.
After reopen shell all should be done.
### Downgrade to antigen v1
Antigen v2 much faster (up to 2x more faster startup), but if something went wrong, you can downgrade to antigen v1,
see note for zsh 4.3 users below.
### For users with zsh 4.x
Antigen v2 not work on zsh < 5.0, if you use zsh 4.x, please add to you playbook:
``` yaml
zsh_antigen_version: v1.4.1
```
## Known bugs
### `su username` caused errors
See [antigen issue](https://github.com/zsh-users/antigen/issues/136).
If both root and su user using antigen, you should use `su - username` in place of `su username`.
Or you can use bundled alias `suser`.
Also, you can try to fix it, add to `~/.zshrc.local`:
```
alias su='su -'
```
But this alias can break you scripts, that using `su`.

11
ansible/roles/viasite-ansible.zsh/Vagrantfile

@ -0,0 +1,11 @@
$VM_BOX = 'bento/ubuntu-16.04'
Vagrant.configure('2') do |config|
config.vm.box = $VM_BOX
config.vm.provision "ansible" do |ansible|
ansible.extra_vars = { ansible_ssh_user: 'vagrant', vagrant: true, zsh_user: 'vagrant' }
ansible.sudo = true
ansible.playbook = 'tests/vagrant.yml'
end
end

193
ansible/roles/viasite-ansible.zsh/defaults/main.yml

@ -0,0 +1,193 @@
---
zsh_user: "{{ ansible_user_id }}"
# .zshrc config
zsh_hist_stamps: yyyy-mm-dd
zsh_share_history: no
zsh_update_interval: 30 # set 0 for disable autoupdates
zsh_editor: vim
zsh_term: xterm-256color
zsh_mc_solarized_skin: no
zsh_path:
- "{{ zsh_fzf_path }}"
- /usr/local/sbin
- /usr/local/bin
- /usr/sbin
- /usr/bin
- /sbin
- /bin
- /usr/games
- /usr/local/games
zsh_load_etc_profile: yes
fzf_widgets: ytet5uy4/fzf-widgets
zsh_antigen_version: master
zsh_fzf_version: 0.17.4
zsh_antigen_bundles:
- { name: command-not-found, when: "{{ ansible_os_family != 'Darwin' }}" } # too slow on OSX
- { name: brew, command: brew }
- { name: docker, command: docker }
- { name: docker-compose, command: docker-compose }
- fancy-ctrl-z
- git-extras
- gnu-utils
- { name: httpie, command: http }
- { name: golang, command: go }
- { name: gulp, command: gulp }
- { name: helm, command: helm }
- { name: kubectl, command: kubectl }
- { name: pip, command: pip }
- { name: rake, command: rake }
- { name: symfony2, command: symfony }
- { name: systemd, command: systemctl }
- python
- { name: tmux, command: tmux }
- { name: vagrant, command: vagrant }
- { name: viasite/drall, command: drall }
- { name: viasite/drupal-scripts, command: drs }
- { name: viasite/server-scripts, command: dbdump }
- { name: viasite-ansible/zsh-ansible-server, command: ansible-deploy }
- zsh_reload
# on zsh 4.3.10 autosuggestions breaks multiline commands with \
- { name: zsh-users/zsh-autosuggestions, when: "{{ zsh_version is version_compare('5.0', '>=') }}" }
- popstas/zsh-command-time
- { name: unixorn/autoupdate-antigen.zshplugin, when: "{{ zsh_update_interval > 0 }}" }
- urbainvaes/fzf-marks # replaces jump plugin, mark, jump and Ctrl+G
- "{{ fzf_widgets }}"
# must be last, don't work on zsh < 4.3.17
#- { name: zsh-users/zsh-syntax-highlighting, when: "{{ zsh_version | default(false) is version_compare('4.3.17', '>=') }}" }
# bug with text paste in fast-syntax-highlighting v1.21, see https://github.com/zdharma/fast-syntax-highlighting/issues/30
- { name: zdharma/[email protected], when: "{{ zsh_version is version_compare('4.3.17', '>=') }}" }
zsh_antigen_bundles_extras: []
# useful for deploy many zsh users at host, without duplicate and without write access
zsh_shared: no
zsh_change_user_shell: yes
zsh_antigen_theme: "bhilburn/powerlevel9k powerlevel9k"
zsh_hotkeys:
# home & end keys work
- { hotkey: '\e[1~', action: beginning-of-line }
- { hotkey: '\e[4~', action: end-of-line }
# fzf-widgets
- { hotkey: '^@' , action: fzf-select-widget, bundle: "{{ fzf_widgets }}" }
- { hotkey: '^@.' , action: fzf-edit-dotfiles, bundle: "{{ fzf_widgets }}" }
- { hotkey: '^@c', action: fzf-change-directory, bundle: "{{ fzf_widgets }}" }
- { hotkey: '^@f', action: fzf-edit-files, bundle: "{{ fzf_widgets }}" }
- { hotkey: '^@k', action: fzf-kill-processes, bundle: "{{ fzf_widgets }}" }
- { hotkey: '^@s', action: fzf-exec-ssh, bundle: "{{ fzf_widgets }}" }
- { hotkey: '^\' , action: fzf-change-recent-directory, bundle: "{{ fzf_widgets }}" }
- { hotkey: '^r', action: fzf-insert-history, bundle: "{{ fzf_widgets }}" }
- { hotkey: '^xf', action: fzf-insert-files, bundle: "{{ fzf_widgets }}" }
- { hotkey: '^xd', action: fzf-insert-directory, bundle: "{{ fzf_widgets }}" }
# fzf-widgets: Git
- { hotkey: '^@g', action: fzf-select-git-widget, bundle: "{{ fzf_widgets }}" }
- { hotkey: '^@ga', action: fzf-git-add-files, bundle: "{{ fzf_widgets }}" }
- { hotkey: '^@gc', action: fzf-git-change-repository, bundle: "{{ fzf_widgets }}" }
- { hotkey: '^@gco', action: fzf-git-checkout-branch, bundle: "{{ fzf_widgets }}" }
- { hotkey: '^@gd', action: fzf-git-delete-branches, bundle: "{{ fzf_widgets }}" }
# fzf-widgets: GitHub
- { hotkey: '^@gh', action: fzf-select-github-widget, bundle: "{{ fzf_widgets }}" }
- { hotkey: '^@ghi', action: fzf-github-show-issue, bundle: "{{ fzf_widgets }}" }
- { hotkey: '^@ghe', action: fzf-github-edit-issue, bundle: "{{ fzf_widgets }}" }
- { hotkey: '^@gho', action: fzf-github-open-issue, bundle: "{{ fzf_widgets }}" }
- { hotkey: '^@ghc', action: fzf-github-close-issue, bundle: "{{ fzf_widgets }}" }
- { hotkey: '^@ghco', action: fzf-github-comment-issue, bundle: "{{ fzf_widgets }}" }
# fzf-widgets: Docker
- { hotkey: '^@d', action: fzf-select-docker-widget, bundle: "{{ fzf_widgets }}" }
- { hotkey: '^@dk', action: fzf-docker-kill-containers, bundle: "{{ fzf_widgets }}" }
- { hotkey: '^@dl', action: fzf-docker-logs-container, bundle: "{{ fzf_widgets }}" }
- { hotkey: '^@dr', action: fzf-docker-remove-containers, bundle: "{{ fzf_widgets }}" }
- { hotkey: '^@dri', action: fzf-docker-remove-images, bundle: "{{ fzf_widgets }}" }
- { hotkey: '^@drv', action: fzf-docker-remove-volumes, bundle: "{{ fzf_widgets }}" }
- { hotkey: '^@dsa', action: fzf-docker-start-containers, bundle: "{{ fzf_widgets }}" }
- { hotkey: '^@dso', action: fzf-docker-stop-containers, bundle: "{{ fzf_widgets }}" }
# autosuggestions
- { hotkey: '{{ zsh_autosuggestions_bind_key }}', action: autosuggest-accept, bundle: zsh-users/zsh-autosuggestions }
- { hotkey: '{{ zsh_autosuggestions_bind_key_2 }}', action: autosuggest-accept, bundle: zsh-users/zsh-autosuggestions }
zsh_hotkeys_extras: []
# only single quotes allowed in action
zsh_aliases:
- { alias: 'apt-update-list-upgrade', action: 'apt update && apt upgrade --dry-run | grep Inst | sort | fzf && apt upgrade' }
- { alias: 'dfh', action: 'df -h | grep -v docker' }
- { alias: 'ubuntu-release', action: 'lsb_release -a' }
- { alias: '', action: '' }
# zsh-autosuggestions
zsh_autosuggestions_max_length: 15
zsh_autosuggestions_bind_key: ""
zsh_autosuggestions_bind_key_2: ""
# fzf
zsh_fzf_path: "$HOME/bin"
zsh_fzf_height: "100%"
zsh_fzf_reverse: yes
zsh_fzf_border: no
zsh_fzf_ctrl_r_opts: '--exact'
# command-time
zsh_command_time_min_seconds: 3
zsh_command_time_echo: ""
# powerlevel9k
zsh_powerlevel9k_left_prompt:
- context
- dir
zsh_powerlevel9k_right_prompt:
- status
- background_jobs
- vcs
- command_execution_time
- time
zsh_powerlevel_custom_elements:
- name: command_time
command: "zsh_command_time"
background: "248"
foreground: "000"
zsh_powerlevel9k_hide_host_on_local: yes
zsh_powerlevel9k_always_show_context: no # hide hostname and username from prompt on local machine
zsh_powerlevel9k_always_show_user: no # hide username from prompt on local machine
zsh_powerlevel9k_prompt_on_newline: no
zsh_powerlevel9k_shorten_dir_length: 3
zsh_powerlevel9k_status_verbose: 0
# dir (context) colors
zsh_powerlevel9k_context_default_foreground: "255" # white
zsh_powerlevel9k_context_default_background: "024" # blue
zsh_powerlevel9k_context_root_foreground: "255" # white
zsh_powerlevel9k_context_root_background: "124" # red
zsh_powerlevel9k_dir_foreground: "255" # white
zsh_powerlevel9k_dir_background: "240" # gray
zsh_powerlevel9k_dir_etc_foreground: "{{ zsh_powerlevel9k_dir_foreground }}"
zsh_powerlevel9k_dir_etc_background: "{{ zsh_powerlevel9k_dir_background }}"
zsh_powerlevel9k_dir_path_highlight_foreground: "{{ zsh_powerlevel9k_dir_foreground }}"
zsh_powerlevel9k_dir_path_highlight_background: "{{ zsh_powerlevel9k_dir_background }}"
# vcs colors
zsh_powerlevel9k_vcs_foreground: "232" # about black on any palette
zsh_powerlevel9k_vcs_clean_background: "100" # dirty green
zsh_powerlevel9k_vcs_modified_background: "094" # orange
zsh_powerlevel9k_vcs_untracked_background: "094" # orange
# command execution time
zsh_powerlevel9k_command_execution_time_foreground: "000"
zsh_powerlevel9k_command_execution_time_background: "248"

28
ansible/roles/viasite-ansible.zsh/install.sh

@ -0,0 +1,28 @@
#!/usr/bin/env bash
set -eu
title() {
local color='\033[1;37m'
local nc='\033[0m'
printf "\n${color}$1${nc}\n"
}
title "Install pip and Ansible"
sudo apt update
sudo apt install python3-pip -y
sudo pip3 install ansible
title "Install viasite-ansible.zsh"
ansible-galaxy install viasite-ansible.zsh --force
title "Download playbook to /tmp/zsh.yml"
curl https://raw.githubusercontent.com/viasite-ansible/ansible-role-zsh/master/playbook.yml > /tmp/zsh.yml
title "Provision playbook for root"
ansible-playbook -i "localhost," -c local -b /tmp/zsh.yml
title "Provision playbook for $(whoami)"
ansible-playbook -i "localhost," -c local -b /tmp/zsh.yml --extra-vars="zsh_user=$(whoami)"
title "Finished! Please, restart your shell."
echo ""

2
ansible/roles/viasite-ansible.zsh/meta/.galaxy_install_info

@ -0,0 +1,2 @@
install_date: Mon Feb 8 11:41:50 2021
version: v3.3.2

29
ansible/roles/viasite-ansible.zsh/meta/main.yml

@ -0,0 +1,29 @@
---
galaxy_info:
author: Stanislav Popov
company: Viasite
description: oh-my-zsh with powerlevel9k theme, fzf and other plugins
license: MIT
min_ansible_version: 2.0
platforms:
- name: Ubuntu
versions:
- trusty
- xenial
- name: Debian
versions:
- squeeze
- wheezy
- jessie
- name: EL
versions:
- 7
- name: MacOSX
versions:
- 10.12
galaxy_tags:
- system
- shell
- user
- zsh
dependencies: []

49
ansible/roles/viasite-ansible.zsh/molecule/default/molecule.yml

@ -0,0 +1,49 @@
---
driver:
name: docker
platforms:
- name: ansible-role-zsh-debian-10
image: geerlingguy/docker-debian10-ansible
pre_build_image: true
- name: ansible-role-zsh-1604
image: geerlingguy/docker-ubuntu1604-ansible
pre_build_image: true
- name: ansible-role-zsh-1804
image: geerlingguy/docker-ubuntu1804-ansible
pre_build_image: true
- name: ansible-role-zsh-2004
image: geerlingguy/docker-ubuntu2004-ansible
pre_build_image: true
- name: ansible-role-zsh-centos-8
image: geerlingguy/docker-centos8-ansible
#driver:
# name: vagrant
# provider:
# name: virtualbox
#platforms:
# - name: xenial64
# box: bento/ubuntu-16.04
#verifier:
# name: testinfra
provisioner:
name: ansible
playbooks:
prepare: ../resources/prepare.yml
converge: ../resources/converge.yml
inventory:
group_vars:
all:
zsh_user: root
zsh_mc_solarized_skin: yes
zsh_antigen_bundles_extras:
- { name: test/in-list, when: true }
- { name: test/not-in-list, when: false }
- { name: test/command-exists, command: zsh }
- { name: test/command-not-exists, command: not-exists-commanddd }

17
ansible/roles/viasite-ansible.zsh/molecule/default/tests/test_default.py

@ -0,0 +1,17 @@
import os
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
def test_bundles_when(host):
c = host.file('/root/.zshrc').content
assert 'test/in-list' in c
assert 'test/not-in-list' not in c
def test_bundles_command(host):
c = host.file('/root/.zshrc').content
assert 'test/command-exists' in c
assert 'test/command-not-exists' not in c

4
ansible/roles/viasite-ansible.zsh/molecule/resources/converge.yml

@ -0,0 +1,4 @@
---
- hosts: all
roles:
- ansible-role-zsh

13
ansible/roles/viasite-ansible.zsh/molecule/resources/prepare.yml

@ -0,0 +1,13 @@
---
- name: Prepare
hosts: all
gather_facts: False
tasks:
- name: apt-proxy
copy:
content: "Acquire::http::Proxy \"{{ lookup('env', 'APT_PROXY') }}\"; Acquire::https::Proxy \"false\";"
dest: /etc/apt/apt.conf.d/01proxy
failed_when: False
- name: Update apt cache
package:
update_cache: yes

34
ansible/roles/viasite-ansible.zsh/molecule/shared/molecule.yml

@ -0,0 +1,34 @@
---
scenario:
name: shared
driver:
name: docker
platforms:
- name: ansible-role-zsh-debian-10
image: geerlingguy/docker-debian10-ansible
pre_build_image: true
- name: ansible-role-zsh-1604
image: geerlingguy/docker-ubuntu1604-ansible
pre_build_image: true
- name: ansible-role-zsh-1804
image: geerlingguy/docker-ubuntu1804-ansible
pre_build_image: true
- name: ansible-role-zsh-2004
image: geerlingguy/docker-ubuntu2004-ansible
pre_build_image: true
- name: ansible-role-zsh-centos-8
image: geerlingguy/docker-centos8-ansible
provisioner:
name: ansible
playbooks:
prepare: ../resources/prepare.yml
converge: ../resources/converge.yml
inventory:
group_vars:
all:
zsh_shared: yes

34
ansible/roles/viasite-ansible.zsh/molecule/user/molecule.yml

@ -0,0 +1,34 @@
---
scenario:
name: user
driver:
name: docker
platforms:
- name: ansible-role-zsh-debian-10
image: geerlingguy/docker-debian10-ansible
pre_build_image: true
- name: ansible-role-zsh-1604
image: geerlingguy/docker-ubuntu1604-ansible
pre_build_image: true
- name: ansible-role-zsh-1804
image: geerlingguy/docker-ubuntu1804-ansible
pre_build_image: true
- name: ansible-role-zsh-2004
image: geerlingguy/docker-ubuntu2004-ansible
pre_build_image: true
- name: ansible-role-zsh-centos-8
image: geerlingguy/docker-centos8-ansible
provisioner:
name: ansible
playbooks:
prepare: prepare.yml
converge: ../resources/converge.yml
inventory:
group_vars:
all:
zsh_user: testuser

16
ansible/roles/viasite-ansible.zsh/molecule/user/prepare.yml

@ -0,0 +1,16 @@
---
- name: Prepare
hosts: all
gather_facts: False
tasks:
- name: apt-proxy
copy:
content: "Acquire::http::Proxy \"{{ lookup('env', 'APT_PROXY') }}\"; Acquire::https::Proxy \"false\";"
dest: /etc/apt/apt.conf.d/01proxy
failed_when: False
- name: create testuser
user:
name: testuser
home: /home/testuser
shell: /bin/bash

9
ansible/roles/viasite-ansible.zsh/playbook.yml

@ -0,0 +1,9 @@
---
- hosts: all
vars:
# your extra bundles here
zsh_antigen_bundles_extras: []
# your variables here
zsh_autosuggestions_bind_key: "^U"
roles:
- viasite-ansible.zsh

31
ansible/roles/viasite-ansible.zsh/scripts/generate-changelog

@ -0,0 +1,31 @@
#!/bin/bash
HELP="
1. If github branch exists,
rename origin to origin_origin,
rename copy github to origin.
2. Generate CHANGELOG.md
3. Reverts all branch operations at step 1
"
IS_BRANCH_RENAME=$(git remote | grep -c github)
# 1.
if [ "$IS_BRANCH_RENAME" = "1" ]; then
git remote rename origin origin_origin
git remote rename github origin
fi
# 2.
conventional-changelog -p angular -o CHANGELOG.md -r 0
sed -i.bak 's/# \[\]/# [master]/g' CHANGELOG.md
rm CHANGELOG.md.bak
git add CHANGELOG.md
# 3.
if [ "$IS_BRANCH_RENAME" = "1" ]; then
git remote rename origin github
git remote rename origin_origin origin
fi

75
ansible/roles/viasite-ansible.zsh/tasks/configure.yml

@ -0,0 +1,75 @@
---
- name: Check zsh version
shell: "set -o pipefail; zsh --version | cut -d ' ' -f2"
args:
executable: /bin/bash
register: zsh_register_version
check_mode: no
changed_when: false
tags: configure
- name: Set zsh_version variable
set_fact:
zsh_version: "{{ zsh_register_version.stdout }}"
- name: Merge bundles lists
set_fact:
zsh_antigen_bundles: "{{ zsh_antigen_bundles }} + {{ zsh_antigen_bundles_extras }}"
- name: Disable autoupdate if zsh_shared install
set_fact:
zsh_update_interval: 0
when: zsh_shared
- name: Check commands exists
shell: "command -v {{ item.command }} || which {{ item.command }}"
with_items: "{{ zsh_antigen_bundles }}"
failed_when: false
changed_when: false
check_mode: no
when: item.command is defined
register: zsh_register_commands_exists
- name: Merge hotkeys lists
set_fact:
zsh_hotkeys: "{{ zsh_hotkeys }} + {{ zsh_hotkeys_extras }}"
- name: Check antigen version
shell: |
set -o pipefail
cat "{{ zsh_antigen_path }}/antigen/VERSION" | tr -d 'v'
args:
executable: /bin/bash
register: zsh_register_antigen_version
changed_when: false
failed_when: false
check_mode: no
tags: configure
- name: Set zsh_antigen_installed_version variable
set_fact:
zsh_antigen_installed_version: "{{ zsh_register_antigen_version.stdout }}"
- name: Write .zshrc config
template:
src: zshrc.j2
dest: "{{ zsh_config }}"
owner: "{{ zsh_user }}"
group: "{{ zsh_user_group }}"
backup: yes
- name: Set zsh as default shell
user:
name: "{{ zsh_user }}"
shell: /bin/zsh
become: true
when: not zsh_shared and zsh_change_user_shell
- name: Add skip_global_compinit for disable early compinit call in Ubuntu
lineinfile:
regexp: "skip_global_compinit=1"
line: "skip_global_compinit=1"
dest: /etc/zsh/zshenv
state: present
when: ansible_distribution == 'Ubuntu'

79
ansible/roles/viasite-ansible.zsh/tasks/install.yml

@ -0,0 +1,79 @@
---
- name: Update package cache
package:
update_cache: yes
when: ansible_os_family != 'Darwin'
- name: Install zsh, git, wget
package:
name:
- zsh
- git
- wget
state: present
# brew don't work from root user on macOS
when: not (zsh_user == 'root' and ansible_os_family == 'Darwin')
- name: Clone antigen {{ zsh_antigen_version }}
git:
repo: https://github.com/zsh-users/antigen.git
dest: "{{ zsh_antigen_path }}/antigen"
version: "{{ zsh_antigen_version }}"
force: yes
become: yes
become_user: "{{ zsh_user }}"
register: zsh_register_antigen_clone
- name: Clone iwfmp/mc-solarized-skin
git:
repo: https://github.com/iwfmp/mc-solarized-skin.git
version: master
dest: "~{{ zsh_user }}/.mc/lib/mc-solarized"
force: yes
become: yes
become_user: "{{ zsh_user }}"
when: zsh_mc_solarized_skin and not zsh_shared
- name: Check fzf installed
command: which fzf
changed_when: false
failed_when: false
check_mode: no
register: zsh_register_fzf_command
- name: Set zsh_fzf_path to /usr/local/bin
set_fact:
zsh_fzf_path: /usr/local/bin
changed_when: false
when: zsh_shared
- name: Set zsh_fzf_path_absolute
set_fact:
zsh_fzf_path_absolute: "{{ zsh_fzf_path | replace('$HOME', '~' + zsh_user) }}"
changed_when: false
- name: Ensure users home binary folder is present
file:
path: "{{ zsh_fzf_path_absolute }}"
owner: "{{ zsh_user }}"
group: "{{ zsh_user_group }}"
mode: u=rwx,g=rwx,o=rx
state: directory
when: not zsh_shared
- name: "Download fzf to {{ zsh_fzf_path_absolute }}"
unarchive:
src: "{{ zsh_fzf_url }}"
dest: "{{ zsh_fzf_path_absolute }}"
remote_src: yes
creates: "{{ zsh_fzf_path_absolute }}/fzf"
when: zsh_register_fzf_command.rc == 1
- name: Set directory permissions
file:
name: "{{ zsh_antigen_path }}"
owner: "{{ zsh_user }}"
group: "{{ zsh_user_group }}"
recurse: yes
changed_when: false

18
ansible/roles/viasite-ansible.zsh/tasks/main.yml

@ -0,0 +1,18 @@
---
- include: install.yml
tags: [ zsh, install ]
- include: configure.yml
tags: [ zsh, configure ]
- include: post-install.yml
tags: [ zsh, install, post_install ]
- name: Reset antigen cache
command: "/bin/zsh -c 'source {{ zsh_config }}; antigen reset'"
become: yes
become_user: "{{ zsh_user }}"
changed_when: false
failed_when: false
tags: always

15
ansible/roles/viasite-ansible.zsh/tasks/post-install.yml

@ -0,0 +1,15 @@
---
- name: Reset antigen cache
command: "/bin/zsh -c 'source {{ zsh_config }}; antigen reset'"
become: yes
become_user: "{{ zsh_user }}"
changed_when: false
failed_when: false
# it will fail, but it install all bundles for user
- name: Update antigen bundles
command: "/bin/zsh -c 'source {{ zsh_config }}; antigen update'"
become: yes
become_user: "{{ zsh_user }}"
changed_when: false
failed_when: false

173
ansible/roles/viasite-ansible.zsh/templates/zshrc.j2

@ -0,0 +1,173 @@
# {{ ansible_managed }}
# zsh version: {{ zsh_version }}
# antigen version: {{ zsh_antigen_installed_version }}
export TERM="{{ zsh_term }}"
export EDITOR="{{ zsh_editor }}"
export PATH="$PATH:{{ zsh_path | join(":") }}"
HIST_STAMPS="{{ zsh_hist_stamps }}"
UPDATE_ZSH_DAYS="{{ zsh_update_interval }}"
COMPLETION_WAITING_DOTS="true"
# ADOTDIR="{{ zsh_antigen_path_compat }}"
{% if zsh_shared %}
ANTIGEN_AUTO_CONFIG=false # disable updates
_ANTIGEN_THEME_COMPAT=false # disable theme cache
{% endif %}
ANTIGEN_BUNDLES="{{ zsh_antigen_path_compat }}/bundles"
ANTIGEN_PLUGIN_UPDATE_DAYS="{{ zsh_update_interval }}"
ANTIGEN_SYSTEM_UPDATE_DAYS="{{ zsh_update_interval }}"
{% if zsh_mc_solarized_skin %}export MC_SKIN="$HOME/.mc/lib/mc-solarized/solarized.ini"{% endif %}
source "{{ zsh_antigen_path_compat }}/antigen/antigen.zsh"
antigen use oh-my-zsh
{% set bundles_enabled = [] %}
{% for bundle in zsh_antigen_bundles -%}
{%- if bundle is mapping -%}
{% set valid = true -%}
{% set command_not_exists = [] -%}
{%- if bundle.when is defined and not bundle.when -%}
{% set valid = false -%}
{% endif -%}
{% if bundle.command is defined -%}
{% for cmd in zsh_register_commands_exists.results -%}
{% if cmd.cmd is defined and cmd.rc != 0 and cmd.item.command == bundle.command -%}
{% if command_not_exists.append(1) %}{% endif -%}
{% endif -%}
{% endfor -%}
{% endif -%}
{% if valid and not command_not_exists %}
{%- if 'zsh-syntax-highlighting' in bundle.name or 'fast-syntax-highlighting' in bundle.name -%}
# will fixed in zsh-autosuggestion v0.4 - https://github.com/zsh-users/zsh-autosuggestions/pull/218
if (( ZSHRC_LOAD_ONCE++ == 0 )); then
antigen bundle {{ bundle.name }}
fi
{% else -%}
{% if bundles_enabled.append(bundle.name) %}{% endif -%}
antigen bundle {{ bundle.name }}
{% endif -%}
{% endif -%}
{%- else -%}
{% if bundles_enabled.append(bundle) %}{% endif -%}
antigen bundle {{ bundle }}
{% endif %}
{% endfor %}
POWERLEVEL9K_INSTALLATION_PATH=$ANTIGEN_BUNDLES/bhilburn/powerlevel9k/powerlevel9k.zsh-theme
antigen theme {{ zsh_antigen_theme }}
antigen apply
###
{% if not zsh_share_history %}
unsetopt share_history
{% endif %}
autoload -Uz copy-earlier-word
zle -N copy-earlier-word
# hotkeys
{% for hotkey in zsh_hotkeys %}
{% if hotkey.hotkey != '' and (hotkey.bundle is not defined or hotkey.bundle in bundles_enabled) %}
bindkey '{{ hotkey.hotkey }}' {{ hotkey.action }}
{% endif %}
{% endfor %}
# aliases
{% for alias in zsh_aliases %}
{% if alias.alias != '' and (alias.bundle is not defined or alias.bundle in bundles_enabled) %}
alias '{{ alias.alias }}'="{{ alias.action }}"
{% endif %}
{% endfor %}
# fzf
export FZF_TMUX=0
export FZF_DEFAULT_OPTS="{{ zsh_fzf_default_opts }}"
# fzf-widgets: fzf-change-reset-dir
{% if zsh_version is version_compare('5.0', '>=') -%}
autoload -Uz chpwd_recent_dirs cdr add-zsh-hook
add-zsh-hook chpwd chpwd_recent_dirs
{% endif %}
declare -p FZF_WIDGETS_OPTS > /dev/null 2>&1 && FZF_WIDGETS_OPTS[insert-history]="{{ zsh_fzf_ctrl_r_opts }}"
declare -p FZF_WIDGET_OPTS > /dev/null 2>&1 && FZF_WIDGET_OPTS[insert-history]="{{ zsh_fzf_ctrl_r_opts }}"
# zsh-autosuggestions
ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE={{ zsh_autosuggestions_max_length }}
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=240" # gray highlight
# powerlevel9k
POWERLEVEL9K_SHORTEN_DIR_LENGTH={{ zsh_powerlevel9k_shorten_dir_length }}
POWERLEVEL9K_STATUS_VERBOSE={{ zsh_powerlevel9k_status_verbose }}
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=({{ zsh_powerlevel9k_left_prompt | join(" ") }})
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=({{ zsh_powerlevel9k_right_prompt | join(" ") }})
{% if zsh_powerlevel9k_hide_host_on_local and zsh_user != 'root' %}DEFAULT_USER=$USER{% endif %}
POWERLEVEL9K_ALWAYS_SHOW_CONTEXT={{ zsh_powerlevel9k_always_show_context_bool }}
POWERLEVEL9K_ALWAYS_SHOW_USER={{ zsh_powerlevel9k_always_show_user_bool }}
{% if zsh_powerlevel_custom_elements is defined and zsh_powerlevel_custom_elements %}
{% for element in zsh_powerlevel_custom_elements %}
{% set prefix = "POWERLEVEL9K_CUSTOM_" + element.name | upper %}
{{ prefix }}="{{ element.command }}"
{{ prefix }}_BACKGROUND="{{ element.background }}"
{{ prefix }}_FOREGROUND="{{ element.foreground }}"
{% endfor %}
{% endif %}
# https://github.com/bhilburn/powerlevel9k#command_execution_time
POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD="{{ zsh_command_time_min_seconds }}"
POWERLEVEL9K_PROMPT_ON_NEWLINE={{ zsh_powerlevel9k_prompt_on_newline_bool }}
POWERLEVEL9K_RPROMPT_ON_NEWLINE=false
POWERLEVEL9K_PROMPT_ADD_NEWLINE=true
POWERLEVEL9K_CONTEXT_DEFAULT_FOREGROUND="{{ zsh_powerlevel9k_context_default_foreground }}"
POWERLEVEL9K_CONTEXT_DEFAULT_BACKGROUND="{{ zsh_powerlevel9k_context_default_background }}"
POWERLEVEL9K_CONTEXT_REMOTE_FOREGROUND="{{ zsh_powerlevel9k_context_default_foreground }}"
POWERLEVEL9K_CONTEXT_REMOTE_BACKGROUND="{{ zsh_powerlevel9k_context_default_background }}"
POWERLEVEL9K_CONTEXT_ROOT_FOREGROUND="{{ zsh_powerlevel9k_context_root_foreground }}"
POWERLEVEL9K_CONTEXT_ROOT_BACKGROUND="{{ zsh_powerlevel9k_context_root_background }}"
POWERLEVEL9K_DIR_DEFAULT_FOREGROUND="{{ zsh_powerlevel9k_dir_foreground }}"
POWERLEVEL9K_DIR_DEFAULT_BACKGROUND="{{ zsh_powerlevel9k_dir_background }}"
POWERLEVEL9K_DIR_HOME_FOREGROUND="{{ zsh_powerlevel9k_dir_foreground }}"
POWERLEVEL9K_DIR_HOME_BACKGROUND="{{ zsh_powerlevel9k_dir_background }}"
POWERLEVEL9K_DIR_HOME_SUBFOLDER_FOREGROUND="{{ zsh_powerlevel9k_dir_foreground }}"
POWERLEVEL9K_DIR_HOME_SUBFOLDER_BACKGROUND="{{ zsh_powerlevel9k_dir_background }}"
POWERLEVEL9K_DIR_ETC_FOREGROUND="{{ zsh_powerlevel9k_dir_etc_foreground }}"
POWERLEVEL9K_DIR_ETC_BACKGROUND="{{ zsh_powerlevel9k_dir_etc_background }}"
POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND="{{ zsh_powerlevel9k_dir_path_highlight_foreground }}"
POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BACKGROUND="{{ zsh_powerlevel9k_dir_path_highlight_background }}"
POWERLEVEL9K_VCS_CLEAN_BACKGROUND="{{ zsh_powerlevel9k_vcs_clean_background }}"
POWERLEVEL9K_VCS_MODIFIED_BACKGROUND="{{ zsh_powerlevel9k_vcs_modified_background }}"
POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND="{{ zsh_powerlevel9k_vcs_untracked_background }}"
POWERLEVEL9K_VCS_CLEAN_FOREGROUND="{{ zsh_powerlevel9k_vcs_foreground }}"
POWERLEVEL9K_VCS_MODIFIED_FOREGROUND="{{ zsh_powerlevel9k_vcs_foreground }}"
POWERLEVEL9K_VCS_UNTRACKED_FOREGROUND="{{ zsh_powerlevel9k_vcs_foreground }}"
POWERLEVEL9K_COMMAND_EXECUTION_TIME_FOREGROUND="{{ zsh_powerlevel9k_command_execution_time_foreground }}"
POWERLEVEL9K_COMMAND_EXECUTION_TIME_BACKGROUND="{{ zsh_powerlevel9k_command_execution_time_background }}"
# Aliases
alias suser='su -'
{% if zsh_load_etc_profile %}source /etc/profile{% endif %}
# user configs
[[ -r /etc/zsh/zshrc.local ]] && source /etc/zsh/zshrc.local
[[ -r "$HOME/.zshrc.local" ]] && source "$HOME/.zshrc.local"

4
ansible/roles/viasite-ansible.zsh/tests/vagrant.yml

@ -0,0 +1,4 @@
---
- hosts: all
roles:
- ../..

15
ansible/roles/viasite-ansible.zsh/vars/main.yml

@ -0,0 +1,15 @@
---
zsh_user_group: "{% if ansible_os_family == 'Darwin' %}staff{% else %}{{ zsh_user }}{% endif %}"
zsh_antigen_path: "{% if zsh_shared %}/usr/share/zsh-config{% else %}~{{ zsh_user }}/.antigen{% endif %}"
zsh_config: "{% if zsh_shared %}/usr/share/zsh-config/.zshrc{% else %}~{{ zsh_user }}/.zshrc{% endif %}"
zsh_antigen_path_compat: "{{ zsh_antigen_path | replace('~' + zsh_user, '$HOME') }}"
zsh_fzf_os: linux
zsh_fzf_arch: "{% if '64' in ansible_architecture %}amd64{% else %}386{% endif %}"
zsh_fzf_url: "https://github.com/junegunn/fzf-bin/releases/download/{{ zsh_fzf_version }}/fzf-{{ zsh_fzf_version }}-{{ zsh_fzf_os }}_{{ zsh_fzf_arch }}.tgz"
zsh_antigen_fzf_path: "{{ zsh_antigen_path }}/repos/https-COLON--SLASH--SLASH-github.com-SLASH-junegunn-SLASH-fzf.git"
zsh_fzf_default_opts: "--height {{ zsh_fzf_height }}{% if zsh_fzf_reverse %} --reverse{% endif %}{% if zsh_fzf_border %} --border{% endif %}"
zsh_powerlevel9k_prompt_on_newline_bool: "{% if zsh_powerlevel9k_prompt_on_newline %}true{% else %}false{% endif %}"
zsh_powerlevel9k_always_show_context_bool: "{% if zsh_powerlevel9k_always_show_context %}true{% else %}false{% endif %}"
zsh_powerlevel9k_always_show_user_bool: "{% if zsh_powerlevel9k_always_show_user %}true{% else %}false{% endif %}"

166
docs/SETUP.md

@ -0,0 +1,166 @@
# Nomad Cluster Setup
## Prerequisite
Before continuing with the setup for Nomad and Consul:
- Provision DO infra with Terraform.
- Run Ansible Playbook to boostrap the node.
### Setup Tailscale
Tailscale acts as a mesh layer between the server and worker nodes. Since the user's laptop/mobile also has a Tailscale agent running it makes it easy to deploy and browse Nomad/Consul Admin UIs as well.
```
sudo tailscale up
```
## Install Nomad
Follow the instructions from the [docs](https://www.nomadproject.io/docs/install).
```sh
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
sudo apt-get update && sudo apt-get install nomad
nomad -autocomplete-install
complete -C /usr/local/bin/nomad nomad
sudo mkdir --parents /opt/nomad
```
### Setup Nomad
Follow the instructions from the [docs](https://learn.hashicorp.com/tutorials/nomad/production-deployment-guide-vm-with-consul).
#### Systemd unit
```
# /etc/systemd/system/nomad.service
[Unit]
Description=Nomad
Documentation=https://www.nomadproject.io/docs
Wants=network-online.target
After=network-online.target
[Service]
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/usr/bin/nomad agent -config /etc/nomad.d
KillMode=process
KillSignal=SIGINT
LimitNOFILE=infinity
LimitNPROC=infinity
Restart=on-failure
RestartSec=2
StartLimitBurst=3
StartLimitIntervalSec=10
TasksMax=infinity
[Install]
WantedBy=multi-user.target
```
#### Configurations
All the config files are stored in `/etc/nomad.d`.
```hcl
data_dir = "/opt/nomad/data"
bind_addr = "{{ GetInterfaceIP \"tailscale0\" }}"
datacenter = "hydra"
server {
enabled = true
bootstrap_expect = 1
}
client {
enabled = true
options = {
"docker.volumes.enabled" = true,
"driver.raw_exec.enable" = "1"
}
host_network "tailscale" {
cidr = "100.119.138.27/32"
reserved_ports = "22"
}
}
consul {
address = "100.119.138.27:8500"
}
```
### Verification
Since we changed the `bind_addr` from `0.0.0.0`(default) to Tailscale IP we need to
configure `NOMAD_ADDRESS` env variable for CLI to configure the remote endpoint:
[Docs](https://www.nomadproject.io/docs/commands#remote-usage)
```sh
export NOMAD_ADDR=http://100.119.138.27:4646
```
Before proceeding ahead, make sure `nomad` is running:
```sh
$ nomad server members
Name Address Port Status Leader Protocol Build Datacenter Region
floyd.global 10.47.0.6 4648 alive true 2 1.0.3 hydra global
```
## Install Consul
```sh
sudo apt-get update && sudo apt-get install consul
consul -autocomplete-install
complete -C /usr/bin/consul consul
sudo mkdir --parents /opt/consul
```
## Setup Consul
### Generate Keys
```
consul keygen
```
The output of the above command is used in the config file.
### Configuration
All the config is stored in `/etc/consul.d`
```hcl
datacenter = "hydra"
data_dir = "/opt/consul/data"
encrypt = "<TOKEN>"
server = true
bootstrap_expect = 1
client_addr = "100.119.138.27"
bind_addr = "127.0.0.1"
ui = true
connect {
enabled = true