diff --git a/playbooks/mosh.yml b/playbooks/mosh.yml new file mode 100644 index 0000000..469014e --- /dev/null +++ b/playbooks/mosh.yml @@ -0,0 +1,6 @@ +--- +- name: Manage and configure mosh + hosts: "{{ mosh_hosts | default('mosh', true) }}" + become: "{{ mosh_become | default(true) }}" + roles: + - role: finallycoffee.base.mosh diff --git a/roles/mosh/README.md b/roles/mosh/README.md new file mode 100644 index 0000000..a852f56 --- /dev/null +++ b/roles/mosh/README.md @@ -0,0 +1,4 @@ +# `finallycoffee.base.mosh` + +Installs [`mosh`](https://mosh.org/#), a remote 'mobile shell' which supports +roaming and re-uses SSH for the authentication layer. diff --git a/roles/mosh/defaults/main/main.yml b/roles/mosh/defaults/main/main.yml new file mode 100644 index 0000000..c7f912f --- /dev/null +++ b/roles/mosh/defaults/main/main.yml @@ -0,0 +1,2 @@ +--- +mosh_state: present diff --git a/roles/mosh/defaults/main/packages.yml b/roles/mosh/defaults/main/packages.yml new file mode 100644 index 0000000..8a3f56e --- /dev/null +++ b/roles/mosh/defaults/main/packages.yml @@ -0,0 +1,15 @@ +--- +mosh_debian_packages: + - "mosh" + - "openssh-server" +mosh_fedora_packages: + - "mosh" + - "openssh-server" +mosh_archlinux_packages: + - "mosh" + - "openssh" + +mosh_packages: + debian: "{{ mosh_debian_packages }}" + fedora: "{{ mosh_fedora_packages }}" + archlinux: "{{ mosh_archlinux_packages }}" diff --git a/roles/mosh/tasks/install.yml b/roles/mosh/tasks/install.yml new file mode 100644 index 0000000..d0cfdff --- /dev/null +++ b/roles/mosh/tasks/install.yml @@ -0,0 +1,30 @@ +--- +- name: Ensure mosh is {{ mosh_state }} (dnf) + ansible.builtin.dnf: + name: "{{ mosh_packages[_key] }}" + state: "{{ mosh_state }}" + when: + - ansible_facts['pkg_mgr'] in ['dnf', 'dnf5'] + - _key in mosh_packages.keys() + vars: + _key: "{{ ansible_distribution | lower }}" + +- name: Ensure mosh is {{ mosh_state }} (apt) + ansible.builtin.apt: + package: "{{ mosh_packages[_key] }}" + state: "{{ mosh_state }}" + when: + - ansible_facts['pkg_mgr'] in ['apt'] + - _key in mosh_packages.keys() + vars: + _key: "{{ ansible_distribution | lower }}" + +- name: Ensure mosh is {{ mosh_state }} (pacman) + community.general.pacman: + name: "{{ mosh_packages[_key] }}" + state: "{{ mosh_state }}" + when: + - ansible_facts['pkg_mgr'] in ['pacman'] + - _key in mosh_packages.keys() + vars: + _key: "{{ ansible_distribution | lower }}" diff --git a/roles/mosh/tasks/main.yml b/roles/mosh/tasks/main.yml new file mode 100644 index 0000000..4f03219 --- /dev/null +++ b/roles/mosh/tasks/main.yml @@ -0,0 +1,11 @@ +--- +- name: Ensure 'mosh_state' is valid + ansible.builtin.fail: + msg: >-2 + Invalid state '{{ mosh_state }}' for 'mosh_state'! + Allowed states are {{ mosh_states | join(', ') }}. + when: mosh_state not in mosh_states + +- name: Ensure mosh is {{ mosh_state }} + ansible.builtin.include_tasks: + file: "install.yml" diff --git a/roles/mosh/vars/main.yml b/roles/mosh/vars/main.yml new file mode 100644 index 0000000..4f073f7 --- /dev/null +++ b/roles/mosh/vars/main.yml @@ -0,0 +1,4 @@ +--- +mosh_states: + - "present" + - "absent"