From 4ea6ee162b51646346336abade237be4f7215ffa Mon Sep 17 00:00:00 2001 From: SebClem Date: Sun, 20 Nov 2022 18:55:05 +0100 Subject: [PATCH] First version --- README.md | 11 +++++++- ansible.cfg | 3 ++ defaults/main.yml | 5 ++++ tasks/configure.yml | 54 ++++++++++++++++++++++++++++++++++++ tasks/install.yml | 48 ++++++++++++++++++++++++++++++++ tasks/main.yml | 4 ++- templates/antidoterc.j2 | 5 ++++ templates/zsh_plugins.txt.j2 | 6 ++++ tests/test.yml | 13 ++++++++- vars/main.yml | 10 +++++++ 10 files changed, 156 insertions(+), 3 deletions(-) create mode 100644 ansible.cfg create mode 100644 tasks/configure.yml create mode 100644 tasks/install.yml create mode 100644 templates/antidoterc.j2 create mode 100644 templates/zsh_plugins.txt.j2 diff --git a/README.md b/README.md index fd43647..0b8efc7 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..ea6634d --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,3 @@ +[defaults] +roles_path = ../ +stdout_callback = yaml \ No newline at end of file diff --git a/defaults/main.yml b/defaults/main.yml index b9f11b7..3870c02 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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: [] diff --git a/tasks/configure.yml b/tasks/configure.yml new file mode 100644 index 0000000..0d96ecd --- /dev/null +++ b/tasks/configure.yml @@ -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' diff --git a/tasks/install.yml b/tasks/install.yml new file mode 100644 index 0000000..0ee46cd --- /dev/null +++ b/tasks/install.yml @@ -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 diff --git a/tasks/main.yml b/tasks/main.yml index 892a420..f7c319a 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,2 +1,4 @@ --- -# tasks file for Ansible-Antidote-Role +- import_tasks: install.yml + +- import_tasks: configure.yml diff --git a/templates/antidoterc.j2 b/templates/antidoterc.j2 new file mode 100644 index 0000000..997334b --- /dev/null +++ b/templates/antidoterc.j2 @@ -0,0 +1,5 @@ +{{ ansible_managed | comment }} + +source ~{{ user.username }}/.antidote/antidote.zsh + +antidote load \ No newline at end of file diff --git a/templates/zsh_plugins.txt.j2 b/templates/zsh_plugins.txt.j2 new file mode 100644 index 0000000..9f3bcbb --- /dev/null +++ b/templates/zsh_plugins.txt.j2 @@ -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 %} \ No newline at end of file diff --git a/tests/test.yml b/tests/test.yml index cfefdf4..895b456 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -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 diff --git a/vars/main.yml b/vars/main.yml index 5134bf3..ddec48c 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -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"