First version

This commit is contained in:
SebClem 2022-11-20 18:55:05 +01:00
parent 18bed684c2
commit 4ea6ee162b
Signed by: sebclem
GPG Key ID: 5A4308F6A359EA50
10 changed files with 156 additions and 3 deletions

View File

@ -8,7 +8,16 @@ Any pre-requisites that may not be covered by Ansible itself or the role should
## Role Variables
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
```yaml
# antidote is installed per user so you need to specify the users to install it for
users:
- username: # The username of the user to install Antidote for
antidote_plugins:
- name: # The name of the library (e.g. oh-my-zsh or prezto) must be unique
kind:
branch:
path:
```
## Dependencies

3
ansible.cfg Normal file
View File

@ -0,0 +1,3 @@
[defaults]
roles_path = ../
stdout_callback = yaml

View File

@ -1,2 +1,7 @@
---
# defaults file for ${REPO_NAME_TITLE}
antidote_version: "1.6.4"
antidote_mirror: "https://github.com/mattmc3/antidote/archive/refs/tags/"
antidote_download_dir: "{{ x_ansible_download_dir | default(ansible_env.HOME + '/.ansible/tmp/downloads') }}"
users: []

54
tasks/configure.yml Normal file
View File

@ -0,0 +1,54 @@
---
- name: set default shell for users
become: yes
user:
name: "{{ user.username }}"
shell: /bin/zsh
when: user.antidote_plugins is defined
loop: "{{ users }}"
loop_control:
loop_var: user
label: "{{ user.username }}"
- name: write .antidoterc for users
become: yes
become_user: "{{ user.username }}"
template:
src: antidoterc.j2
dest: "~{{ user.username }}/.antidoterc"
mode: "u=rw,go=r"
when: user.antidote_plugins is defined
loop: "{{ users }}"
loop_control:
loop_var: user
label: "{{ user.username }}"
- name: write .zsh_plugins.txt for users
become: yes
become_user: "{{ user.username }}"
template:
src: zsh_plugins.txt.j2
dest: "~{{ user.username }}/.zsh_plugins.txt"
mode: "u=rw,go=r"
when: user.antidote_plugins is defined
loop: "{{ users }}"
loop_control:
loop_var: user
label: "{{ user.username }}"
- name: add .antidoterc to .zshrc
become: yes
become_user: "{{ user.username }}"
lineinfile:
path: "~/.zshrc"
line: "source ~/.antidoterc"
create: yes
mode: "u=rw,go=r"
when: user.antidote_plugins is defined
loop: "{{ users }}"
loop_control:
loop_var: user
label: "{{ user.username }}"
# - name: configure console for Debian family distributions
# include_tasks: configure-debian-console.yml
# when: ansible_os_family == 'Debian'

48
tasks/install.yml Normal file
View File

@ -0,0 +1,48 @@
---
- name: install dependencies
become: yes
package:
name:
- git
- zsh
- tar
- gzip
state: present
- name: create download directory
file:
path: "{{ antidote_download_dir }}"
state: directory
mode: "u=rwx,go=rx"
- name: download Antidote
get_url:
url: "{{ antidote_mirror }}/{{ antidote_filename }}"
dest: "{{ antidote_download_dir }}/{{ antidote_local_filename }}"
mode: "u=rw,go=r"
- name: create install directory
become: yes
become_user: "{{ username }}"
file:
path: "~{{ username }}/.antidote"
state: directory
mode: "u=rwx,go=rx"
loop: "{{ users | map(attribute='username') | list }}"
loop_control:
loop_var: username
- name: install Antidote
become: yes
unarchive:
src: "{{ antidote_download_dir }}/{{ antidote_local_filename }}"
remote_src: yes
dest: "~{{ username }}/.antidote"
extra_opts:
- "--strip-components=1"
creates: "~{{ username }}/.antidote/antidote.zsh"
owner: "{{ username }}"
mode: "go-w"
loop: "{{ users | map(attribute='username') | list }}"
loop_control:
loop_var: username

View File

@ -1,2 +1,4 @@
---
# tasks file for Ansible-Antidote-Role
- import_tasks: install.yml
- import_tasks: configure.yml

5
templates/antidoterc.j2 Normal file
View File

@ -0,0 +1,5 @@
{{ ansible_managed | comment }}
source ~{{ user.username }}/.antidote/antidote.zsh
antidote load

View File

@ -0,0 +1,6 @@
{{ ansible_managed | comment }}
{% for antidote_plugin in user.antidote_plugins %}
{{ antidote_plugin.name}}{% if 'kind' in antidote_plugin %} kind:{{antidote_plugin.kind}}{%endif%}{% if 'branch' in antidote_plugin %} branch:{{antidote_plugin.branch}}{%endif%}{% if 'path' in antidote_plugin %} path:{{antidote_plugin.path}}{% endif %}
{% endfor %}

View File

@ -2,4 +2,15 @@
- hosts: localhost
remote_user: root
roles:
- Ansible-Antidote-Role
- role: ansible-antidote-role
users:
- username: root
antidote_plugins:
- name: zsh-users/zsh-autosuggestions
# - name: zsh-users/zsh-syntax-highlighting
- name: zdharma-continuum/fast-syntax-highlighting
kind: defer
- name: zsh-users/zsh-completions
- name: ohmyzsh/ohmyzsh
path: lib/git.zsh
- name: romkatv/powerlevel10k

View File

@ -1,2 +1,12 @@
---
# vars file for Ansible-Antidote-Role
# The root folder of this antidote installation
antidote: "~/.antidote"
# File name for the Antigen redistributable installation file
antidote_filename: "v{{ antidote_version }}.tar.gz"
# Local file name for the Antigen redistributable installation file (needs to
# have the package name to avoid conflicts)
antidote_local_filename: "antidote-{{ antidote_version }}.tar.gz"