Add NixOS
This commit is contained in:
+40
-3
@@ -2,20 +2,57 @@
|
||||
hosts: default
|
||||
vars:
|
||||
ansible_remote_tmp: /tmp
|
||||
no_touchy:
|
||||
- NixOS
|
||||
pre_tasks:
|
||||
- name: Pause for a moment in case we need cloud-init to finish
|
||||
ansible.builtin.pause:
|
||||
seconds: 20
|
||||
|
||||
- name: Help with debugging
|
||||
ansible.builtin.debug:
|
||||
msg: "Detected distro: {{ ansible_facts['distribution'] }}"
|
||||
|
||||
- name: get build time
|
||||
become: true
|
||||
ansible.builtin.copy:
|
||||
content: "{{ ansible_facts.date_time.date }} {{ ansible_facts.date_time.hour }}:{{ ansible_facts.date_time.minute }}"
|
||||
dest: /etc/vagrant_box_build_time
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
roles:
|
||||
- role: latest
|
||||
when:
|
||||
- ansible_facts.distribution not in no_touchy
|
||||
|
||||
- role: devroles.system.epel
|
||||
|
||||
- role: virtualbox
|
||||
when: packer_builder_type == 'virtualbox-iso'
|
||||
when:
|
||||
- packer_builder_type == 'virtualbox-iso'
|
||||
|
||||
- role: vmware
|
||||
when: packer_builder_type == 'vmware-iso'
|
||||
when:
|
||||
- packer_builder_type == 'vmware-iso'
|
||||
- ansible_facts.distribution not in no_touchy
|
||||
|
||||
- role: qemu
|
||||
when: packer_builder_type == 'qemu'
|
||||
when:
|
||||
- packer_builder_type == 'qemu'
|
||||
|
||||
- role: init
|
||||
when:
|
||||
- ansible_facts.distribution not in no_touchy
|
||||
|
||||
- role: locale
|
||||
when:
|
||||
- ansible_facts.distribution not in no_touchy
|
||||
|
||||
- role: vagrant
|
||||
when:
|
||||
- ansible_facts.distribution not in no_touchy
|
||||
|
||||
- role: cleanup
|
||||
when:
|
||||
- ansible_facts.distribution not in no_touchy
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
- name: Rebuild nixos
|
||||
become: true
|
||||
ansible.builtin.command: nixos-rebuild switch
|
||||
@@ -1,6 +1,43 @@
|
||||
- name: Load version information
|
||||
ansible.builtin.include_vars: "{{ item }}"
|
||||
loop:
|
||||
- "{{ role_path }}/vars/{{ ansible_facts['os_family'] }}.yml"
|
||||
- "{{ role_path }}/vars/{{ ansible_facts['distribution'] }}.yml"
|
||||
- "{{ role_path }}/vars/{{ ansible_facts['distribution'] }}_{{ ansible_facts['distribution_major_version'] }}.yml"
|
||||
- "{{ role_path }}/vars/{{ ansible_facts['distribution'] }}_{{ ansible_facts['distribution_version'] }}.yml"
|
||||
when: item is file
|
||||
|
||||
- name: Install qemu-guest-agent
|
||||
become: true
|
||||
ansible.builtin.package:
|
||||
name:
|
||||
- qemu-guest-agent
|
||||
state: present
|
||||
when: ansible_facts.distribution != 'NixOS'
|
||||
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
|
||||
- when: ansible_facts.distribution == 'NixOS'
|
||||
block:
|
||||
- name: Tell the configuration to pick up guest agent
|
||||
ansible.builtin.replace:
|
||||
path: /etc/nixos/configuration.nix
|
||||
regexp: "\\./hardware-configuration\\.nix"
|
||||
replace: |
|
||||
./hardware-configuration.nix
|
||||
./guest-agent.nix
|
||||
|
||||
- name: Create guest additions configuration
|
||||
ansible.builtin.copy:
|
||||
dest: /etc/nixos/guest-agent.nix
|
||||
owner: vagrant
|
||||
content: |
|
||||
{...}:
|
||||
{
|
||||
services.qemuGuest.enable = true;
|
||||
}
|
||||
notify: Rebuild nixos
|
||||
|
||||
@@ -13,15 +13,6 @@
|
||||
state: absent
|
||||
when: ansible_facts.pkg_mgr not in ['atomic_container']
|
||||
|
||||
- name: get build time
|
||||
become: true
|
||||
ansible.builtin.copy:
|
||||
content: "{{ ansible_facts.date_time.date }} {{ ansible_facts.date_time.hour }}:{{ ansible_facts.date_time.minute }}"
|
||||
dest: /etc/vagrant_box_build_time
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
|
||||
- name: create .ssh directory
|
||||
ansible.builtin.file:
|
||||
path: "{{ ansible_user_dir }}/.ssh"
|
||||
|
||||
@@ -7,56 +7,88 @@
|
||||
- "{{ role_path }}/vars/{{ ansible_facts['distribution'] }}_{{ ansible_facts['distribution_version'] }}.yml"
|
||||
when: item is file
|
||||
|
||||
- name: Install build deps for virtualbox addons
|
||||
become: true
|
||||
ansible.builtin.package:
|
||||
name: "{{ virtualbox_packages }}"
|
||||
state: present
|
||||
update_cache: true
|
||||
register: _pkg_install
|
||||
retries: 3
|
||||
until: _pkg_install is success
|
||||
|
||||
- name: Start services
|
||||
become: true
|
||||
ansible.builtin.service:
|
||||
name: "{{ item }}"
|
||||
state: started
|
||||
enabled: true
|
||||
loop: "{{ virtualbox_services }}"
|
||||
|
||||
- name: Run commands to install from ISO
|
||||
when: virtualbox_from_iso
|
||||
become: true
|
||||
- when: ansible_facts.distribution != 'NixOS'
|
||||
block:
|
||||
- name: Mount ISO file
|
||||
ansible.posix.mount:
|
||||
fstype: auto
|
||||
path: /mnt
|
||||
src: "{{ virtualbox_iso_location }}"
|
||||
state: mounted
|
||||
boot: false
|
||||
opts: loop
|
||||
- name: Install build deps for virtualbox addons
|
||||
become: true
|
||||
ansible.builtin.package:
|
||||
name: "{{ virtualbox_packages }}"
|
||||
state: present
|
||||
update_cache: true
|
||||
register: _pkg_install
|
||||
retries: 3
|
||||
until: _pkg_install is success
|
||||
|
||||
- name: Install additions
|
||||
ansible.builtin.shell: /mnt/VBoxLinuxAdditions.run install 2>&1 > /root/vbox_addon_install.log
|
||||
changed_when: false
|
||||
failed_when: _cmd.rc not in [0, 2]
|
||||
register: _cmd
|
||||
- name: Start services
|
||||
become: true
|
||||
ansible.builtin.service:
|
||||
name: "{{ item }}"
|
||||
state: started
|
||||
enabled: true
|
||||
loop: "{{ virtualbox_services }}"
|
||||
|
||||
- name: Unmount ISO file
|
||||
ansible.posix.mount:
|
||||
path: /mnt
|
||||
- name: Run commands to install from ISO
|
||||
when: virtualbox_from_iso
|
||||
become: true
|
||||
block:
|
||||
- name: Mount ISO file
|
||||
ansible.posix.mount:
|
||||
fstype: auto
|
||||
path: /mnt
|
||||
src: "{{ virtualbox_iso_location }}"
|
||||
state: mounted
|
||||
boot: false
|
||||
opts: loop
|
||||
|
||||
- name: Install additions
|
||||
ansible.builtin.shell: /mnt/VBoxLinuxAdditions.run install 2>&1 > /root/vbox_addon_install.log
|
||||
changed_when: false
|
||||
failed_when: _cmd.rc not in [0, 2]
|
||||
register: _cmd
|
||||
|
||||
- name: Unmount ISO file
|
||||
ansible.posix.mount:
|
||||
path: /mnt
|
||||
state: absent
|
||||
|
||||
- name: Remove packages
|
||||
become: true
|
||||
ansible.builtin.package:
|
||||
name: "{{ virtualbox_remove_packages | default([]) }}"
|
||||
state: absent
|
||||
when: virtualbox_remove_packages
|
||||
|
||||
- name: Remove file
|
||||
ansible.builtin.file:
|
||||
path: "{{ virtualbox_iso_location }}"
|
||||
state: absent
|
||||
|
||||
- name: Remove packages
|
||||
become: true
|
||||
ansible.builtin.package:
|
||||
name: "{{ virtualbox_remove_packages | default([]) }}"
|
||||
state: absent
|
||||
when: virtualbox_remove_packages
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
|
||||
- name: Remove file
|
||||
ansible.builtin.file:
|
||||
path: "{{ virtualbox_iso_location }}"
|
||||
state: absent
|
||||
- when: ansible_facts.distribution == 'NixOS'
|
||||
block:
|
||||
- name: Tell the configuration to pick up guest agent
|
||||
ansible.builtin.replace:
|
||||
path: /etc/nixos/configuration.nix
|
||||
regexp: "\\./hardware-configuration\\.nix"
|
||||
replace: |
|
||||
./hardware-configuration.nix
|
||||
./guest-agent.nix
|
||||
|
||||
- name: Create guest additions configuration
|
||||
ansible.builtin.copy:
|
||||
dest: /etc/nixos/guest-agent.nix
|
||||
owner: vagrant
|
||||
content: |
|
||||
{...}:
|
||||
{
|
||||
virtualisation.virtualbox.guest = {
|
||||
enable = true;
|
||||
x11 = false;
|
||||
};
|
||||
}
|
||||
notify: Rebuild nixos
|
||||
|
||||
Reference in New Issue
Block a user