Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

290 migrate nix playbooks from ol7 to ubuntu #291

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
124 changes: 124 additions & 0 deletions playbooks/install_nix_ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
---

- name: Check whether Nix is already installed
hosts: login
become: true
tasks:
- name: Call the nix command to see if it is defined
shell: |
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
nix --version
ignore_errors: true
changed_when: false
register: nix_version_output
- name: Stop if Nix is installded
fail:
when: nix_version_output.rc == 0

# install nix
- name: Install Nix
hosts: login
become: true
tasks:
- include_role:
name: nix

- name: Create NFS share on login node
hosts: login
become: true
vars:
export_path: "/nix"
export_name: "nix"
local_path: "/nix"
tasks:
- include_role:
name: nfs-server

- name: Mount NFS share on all other nodes
hosts: controller, slurm_backup, compute
become: true
tasks:
- include_role:
name: nfs-client
vars:
local_path: "/nix"
export_host: "{{ hostvars[groups['login'][0]]['ansible_default_ipv4']['address'] }}"
options: ""
export_path: "/nix"

- name: Move nix.conf file
hosts: login
become: true
tasks:
- name: Move nix.conf file
command: mv /etc/nix/nix.conf /nix/nix.conf

- name: Add bash function for nix command
hosts: login
become: true
tasks:
- name: Add bash function
blockinfile:
path: /etc/bash.bashrc
block: |
nix-install() {
command="nix-env -iA nixpkgs.$1"
shift
for arg in "$@"; do
command+=" nixpkgs.$arg"
done
echo "$command"
eval "$command"
}

nix-remove() {
command="nix-env -e $1"
shift
for arg in "$@"; do
command+=" $arg"
done
echo "$command"
eval "$command"
}

nix-upgrade() {
command="nix-env -u $1"
shift
for arg in "$@"; do
command+=" $arg"
done
echo "$command"
eval "$command"
}

nix-list() {
command="nix-env -q"
eval "$command"
}

nix-search() {
command="nix-env -qaP $1"
eval "$command"
}
marker: "# {mark} NIX ANSIBLE MANAGED BLOCK"
state: present

- name: Set Nix environment variables
hosts: login
become: true
tasks:
- name: Set NIX_CONF_DIR environment variable
lineinfile:
path: /etc/bash.bashrc
line: export NIX_CONF_DIR=/nix
create: yes

- name: Add Nix binaries to path
hosts: controller, slurm_backup, compute
become: true
tasks:
- name: Add Nix binaries to /etc/bash.bashrc file
lineinfile:
path: /etc/bash.bashrc
line: export PATH=~/.nix-profile/bin:$PATH
create: yes
12 changes: 3 additions & 9 deletions playbooks/roles/cais-compute/tasks/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
- name: Install glog
vars:
package_name:
- libglog0v5
- libglog-dev
- libgoogle-glog-dev
package_state: latest
include_role:
name: safe_yum
Expand All @@ -25,20 +24,15 @@
- golang
- golang-go
- golang-doc
- vim-gocomplete
package_state: latest
include_role:
name: safe_yum
ignore_errors: true

- name: Install gcc
- name: Install dev tools
vars:
package_name:
- gcc
- g++
- gdb
- gfortran
- gcc-plugin-dev
- build-essential
package_state: latest
include_role:
name: safe_yum
Expand Down
File renamed without changes.
165 changes: 165 additions & 0 deletions playbooks/uninstall_nix_ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
---

- name: Remove nix daemon service
hosts: all
become: true
tasks:
- name: Gather service facts
service_facts:
- name: Stop nix daemon socket
systemd:
name: nix-daemon.socket
enabled: false
state: stopped
daemon_reload: true
- name: Stop nix daemon service
systemd:
name: nix-daemon.service
enabled: false
state: stopped
daemon_reload: true
when: "'nix-daemon.service' in services"
- name: Remove nix daemon socket unit file
file:
path: /etc/systemd/system/nix-daemon.socket
state: absent
- name: Remove nix daemon service unit file
file:
path: /etc/systemd/system/nix-daemon.service
state: absent
ignore_errors: true

- name: Remove configuration files
hosts: all
become: true
tasks:
- file:
path: /etc/tmpfiles.d/nix-daemon.conf
state: absent

- name: Unmount the /nix directory
hosts: all
become: true
tasks:
- name: Unmount
mount:
path: /nix
state: unmounted
- name: Remove references from /etc/fstab file
lineinfile:
path: /etc/fstab
state: absent
regexp: '\d{1,3}(\.\d{1,3}){3}:/nix /nix nfs defaults 0 0'

- name: Remove files and dirs created by Nix
hosts: all
become: true
tasks:
- name: Remove /nix dir
file:
path: /nix
state: absent
- name: Remove /var/run/nix
file:
path: /var/run/nix
state: absent
- name: Remove /etc/nix dir
file:
path: /etc/nix
state: absent
- name: Remove /etc/profile/nix.sh file
file:
path: /etc/profile/nix.sh
state: absent
- name: Remove ~root/.nix-profile dir
file:
path: ~root/.nix-profile
state: absent
- name: Remove ~root/.nix-defexpr dir
file:
path: ~root/.nix-defexpr
state: absent
- name: Remove ~root/.nix-channels
file:
path: ~root/.nix-channels
state: absent
- name: Remove ~/.nix-profile dir
file:
path: ~/.nix-profile
state: absent
- name: Remove ~/.nix-defexpr dir
file:
path: ~/.nix-defexpr
state: absent
- name: Remove ~/.nix-channels dir
file:
path: ~/.nix-channels
state: absent
- name: Remove /etc/profile.d/nix.sh
file:
path: /etc/profile.d/nix.sh
state: absent
- name: Remove /etc/bashrc.backup-before-nix
file:
path: /etc/bashrc.backup-before-nix
state: absent
- name: Remove /etc/zshrc.backup-before-nix
file:
path: /etc/zshrc.backup-before-nix
state: absent
- name: Remove /etc/zshrc.backup-before-nix
file:
path: /etc/zsh/zshrc.backup-before-nix
state: absent
- name: Remove /etc/bash.bashrc.backup-before-nix
file:
path: /etc/bash.bashrc.backup-before-nix
state: absent

- name: Remove build users and their group
hosts: all
become: true
tasks:
- name: Remove nixbld users
shell: |
for i in $(seq 1 32); do
userdel nixbld$i
done
- name: Remove nixbld group
shell: groupdel nixbld
ignore_errors: true

- name: Remove references to Nix
hosts: all
become: true
tasks:
- name: Remove line from /etc/bashrc file
lineinfile:
path: /etc/bashrc
state: absent
regexp: '^export NIX_CONF_DIR=/nix$'
- name: Remove line from /etc/bashrc file
lineinfile:
path: /etc/bashrc
state: absent
regexp: '# Nix.*|# End Nix'
- name: Remove line from /etc/bash.bashrc file
lineinfile:
path: /etc/bash.bashrc
state: absent
regexp: '# Nix.*|# End Nix'
- name: Remove line from /etc/bashrc file
lineinfile:
path: /etc/bashrc
state: absent
regexp: '^export PATH=~/.nix-profile/bin:\$PATH$'
- name: Remove line from /etc/bashrc file
lineinfile:
path: /etc/bashrc
state: absent
regexp: '^export PATH=/nix/var/nix/profiles/default/bin:\$PATH$'
- name: Remove bash functions
blockinfile:
path: /etc/bashrc
block: ""
marker: "# {mark} NIX ANSIBLE MANAGED BLOCK"