|
| 1 | +- name: Install Nushell |
| 2 | + when: "'nu' not in ansible_facts.packages" |
| 3 | + vars: |
| 4 | + gpg_key_tmp_file: /tmp/nushell.gpg.key |
| 5 | + gpg_key_file: /etc/apt/keyrings/fury-nushell.gpg |
| 6 | + block: |
| 7 | + - name: Install dependencies |
| 8 | + ansible.builtin.apt: |
| 9 | + name: gpg |
| 10 | + update_cache: true |
| 11 | + |
| 12 | + - name: Download GPG key |
| 13 | + ansible.builtin.get_url: |
| 14 | + url: "https://apt.fury.io/nushell/gpg.key" |
| 15 | + dest: "{{ gpg_key_tmp_file }}" |
| 16 | + mode: "0644" |
| 17 | + |
| 18 | + - name: Convert GPG key to keyring format |
| 19 | + ansible.builtin.command: |
| 20 | + cmd: "gpg --dearmor -o {{ gpg_key_file }} {{ gpg_key_tmp_file }}" |
| 21 | + args: |
| 22 | + creates: "{{ gpg_key_file }}" |
| 23 | + |
| 24 | + - name: Remove temporary GPG key |
| 25 | + ansible.builtin.file: |
| 26 | + name: "{{ gpg_key_tmp_file }}" |
| 27 | + state: absent |
| 28 | + |
| 29 | + - name: Add Nushell repository to sources list |
| 30 | + ansible.builtin.apt_repository: |
| 31 | + repo: "deb [signed-by={{ gpg_key_file }}] https://apt.fury.io/nushell/ /" |
| 32 | + filename: fury |
| 33 | + |
| 34 | + - name: Install |
| 35 | + ansible.builtin.apt: |
| 36 | + name: nushell |
| 37 | + update_cache: true |
| 38 | + |
| 39 | + - name: Check if ~/.bashrc exists |
| 40 | + ansible.builtin.stat: |
| 41 | + path: "/home/{{ ansible_user }}/.bashrc" |
| 42 | + register: bashrc_stat |
| 43 | + |
| 44 | + - name: Check if ~/.profile exists |
| 45 | + ansible.builtin.stat: |
| 46 | + path: "/home/{{ ansible_user }}/.profile" |
| 47 | + register: profile_stat |
| 48 | + |
| 49 | + - name: Check if ~/.bash_logout exists |
| 50 | + ansible.builtin.stat: |
| 51 | + path: "/home/{{ ansible_user }}/.bash_logout" |
| 52 | + register: bash_logout_stat |
| 53 | + |
| 54 | + - name: Copy /etc/skel/.bashrc to ~/.bashrc |
| 55 | + ansible.builtin.copy: |
| 56 | + src: "/etc/skel/.bashrc" |
| 57 | + dest: "/home/{{ ansible_user }}/.bashrc" |
| 58 | + when: not bashrc_stat.stat.exists |
| 59 | + become_user: "{{ ansible_user }}" |
| 60 | + |
| 61 | + - name: Copy /etc/skel/.profile to ~/.profile |
| 62 | + ansible.builtin.copy: |
| 63 | + src: "/etc/skel/.profile" |
| 64 | + dest: "/home/{{ ansible_user }}/.profile" |
| 65 | + when: not profile_stat.stat.exists |
| 66 | + become_user: "{{ ansible_user }}" |
| 67 | + |
| 68 | + - name: Copy /etc/skel/.bash_logout to ~/.bash_logout |
| 69 | + ansible.builtin.copy: |
| 70 | + src: "/etc/skel/.bash_logout" |
| 71 | + dest: "/home/{{ ansible_user }}/.bash_logout" |
| 72 | + when: not bash_logout_stat.stat.exists |
| 73 | + become_user: "{{ ansible_user }}" |
| 74 | + |
| 75 | + - name: Ensure Nushell startup |
| 76 | + ansible.builtin.blockinfile: |
| 77 | + path: "/home/{{ ansible_user }}/.bashrc" |
| 78 | + insertafter: EOF |
| 79 | + block: | |
| 80 | + # Start Nushell for interactive sessions |
| 81 | + if [ -n "$PS1" ]; then |
| 82 | + if command -v nu &> /dev/null; then |
| 83 | + exec nu |
| 84 | + fi |
| 85 | + fi |
| 86 | + become_user: "{{ ansible_user }}" |
0 commit comments