diff --git a/.gitignore b/.gitignore index 3151526..a37979f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ archlinux*.iso +archlive diff --git a/inventory b/inventory index fa2f998..75304a0 100644 --- a/inventory +++ b/inventory @@ -1,2 +1,2 @@ [localhost] -localhost ansible_python_interpreter=/usr/bin/python2 ansible_connection=local +localhost ansible_connection=local diff --git a/main.yml b/main.yml index fd7f3c6..f5b250b 100644 --- a/main.yml +++ b/main.yml @@ -3,10 +3,6 @@ connection: local roles: - - { role: archiso, tags: archiso, become: yes } - { role: libvirt, tags: libvirt } + - { role: archiso, tags: archiso, become: yes } - { role: vagrant, tags: vagrant } - -# install libvirt ebtables, etc, nfs -#plugin install vagrant libvirt -#nvram = "/usr/share/ovmf/x64/ovmf_code_x64.bin:/usr/share/ovmf/x64/ovmf_vars_x64.bin" diff --git a/roles/archiso/tasks/main.yml b/roles/archiso/tasks/main.yml index 4a598af..6db4ec9 100644 --- a/roles/archiso/tasks/main.yml +++ b/roles/archiso/tasks/main.yml @@ -20,79 +20,57 @@ dest: "{{ archiso_dir }}/archlive" become: yes -- name: Change airootfs size - lineinfile: - backrefs: yes - path: "{{ item }}" - regexp: '^(options(?!.*\bcow_spacesize=1G\b).*)$' - line: '\1 cow_spacesize=1G' - become: yes - with_items: - - "{{ archiso_dir }}/archlive/efiboot/loader/entries/archiso-x86_64-cd.conf" - - "{{ archiso_dir }}/archlive/efiboot/loader/entries/archiso-x86_64-usb.conf" - - name: Add ansible & git package lineinfile: - dest: "{{ archiso_dir }}/archlive/packages.x86_64" + path: "{{ archiso_dir }}/archlive/packages.x86_64" insertbefore: BOF state: present line: "{{ item }}" become: yes - with_items: + loop: - ansible - git - name: Git clone koaxiel git: + depth: 1 repo: "https://github.com/Koaxiel/koaxiel.git" dest: "{{ archiso_dir }}/archlive/airootfs/root/koaxiel/" -- name: Override dhcpcd@.service - copy: - content: | - [Service] - ExecStop= - ExecStop=/usr/bin/dhcpcd -k %I - dest: "{{ archiso_dir }}/archlive/airootfs/etc/systemd/system/dhcpcd@.service.d/override.conf" - become: yes - -- name: Change mirrorlist - lineinfile: - dest: "{{ archiso_dir }}/archlive/airootfs/root/customize_airootfs.sh" - line: "curl -o /etc/pacman.d/mirrorlist 'https://www.archlinux.org/mirrorlist/?country=FR&protocol=http&protocol=https&ip_version=4&ip_version=6&use_mirror_status=on'" - insertbefore: 'sed -i "s/#Server/Server/g" /etc/pacman.d/mirrorlist' - become: yes - -- name: Enable sshd - lineinfile: - dest: "{{ archiso_dir }}/archlive/airootfs/root/customize_airootfs.sh" - line: "systemctl enable sshd.service" - become: yes - -- name: Set root password +- name: Permit ssh with empty password lineinfile: - dest: "{{ archiso_dir }}/archlive/airootfs/root/customize_airootfs.sh" - line: "echo 'root:toto' | chpasswd" + path: "{{ archiso_dir }}/archlive/airootfs/etc/ssh/sshd_config" + insertafter: '#PermitEmptyPasswords no' + line: PermitEmptyPasswords yes become: yes -- name: Set locale.conf +- name: Install locale config copy: - src: files/locale.conf - dest: "{{ archiso_dir }}/archlive/airootfs/etc/locale.conf" + src: 'files/{{ item }}' + dest: '{{ archiso_dir }}/archlive/airootfs/etc/{{ item }}' become: yes + loop: + - locale.conf + - vconsole.conf -- name: Set vconsole - copy: - src: files/vconsole.conf - dest: "{{ archiso_dir }}/archlive/airootfs/etc/vconsole.conf" - become: yes +- name: Add mirrolist + get_url: + url: 'https://www.archlinux.org/mirrorlist/?country=FR&protocol=http&protocol=https&ip_version=4&ip_version=6&use_mirror_status=on' + dest: '{{ archiso_dir }}/archlive/airootfs/etc/pacman.d/mirrorlist' -- name: Add wpa_supplicant-wired.conf in root +- name: Add wpa_supplicant-wired.conf in root folder copy: src: files/wpa_supplicant-wired.conf dest: "{{ archiso_dir }}/archlive/airootfs/root/wpa_supplicant-wired.conf" become: yes - name: Build iso - command: "bash {{ archiso_dir }}/archlive/build.sh -v -w {{ archiso_dir }}/archlive/work -o {{ archiso_dir }}" + command: "mkarchiso -v -w {{ archiso_dir }}/archlive/work -o {{ archiso_dir }} {{ archiso_dir }}/archlive" + become: yes + +- name: Copy image to libvirt storage + copy: + src: '{{ item }}' + dest: '/var/lib/libvirt/images/archlinux.iso' + with_fileglob: '*.iso' become: yes diff --git a/roles/libvirt/tasks/main.yml b/roles/libvirt/tasks/main.yml index 5cb781b..9107307 100644 --- a/roles/libvirt/tasks/main.yml +++ b/roles/libvirt/tasks/main.yml @@ -2,19 +2,27 @@ # tasks file for libvirt - name: Install packages pacman: - name: [virt-manager, ovmf] + name: [virt-manager, edk2-ovmf, dnsmasq] state: present update_cache: yes become: yes -#- name: Install virt-manager -# -# -#- name: Add nvram qemu.conf -#- name: Change user for qemu.conf -# -#- name: Add user in libvirt group -# -# -# -# -#- name: Startd libvirt \ No newline at end of file + +- name: Add user to group libvirt + user: + name: '{{ ansible_user_id }}' + groups: libvirt + append: yes + become: yes + +- name: Start libvirt service + systemd: + name: libvirtd + enabled: yes + state: started + become: yes + +- name: Start virtlogd service + systemd: + name: virtlogd + state: started + become: yes diff --git a/roles/vagrant/files/Vagrantfile b/roles/vagrant/files/Vagrantfile index 2385712..78e25bd 100644 --- a/roles/vagrant/files/Vagrantfile +++ b/roles/vagrant/files/Vagrantfile @@ -1,7 +1,6 @@ Vagrant.configure("2") do |config| config.ssh.username = 'root' - config.ssh.password = 'toto' # Mount NFS folder config.vm.synced_folder '.', '/vagrant', type: "nfs", @@ -28,7 +27,6 @@ Vagrant.configure("2") do |config| # Reload the VM config.vm.provision :reload - # Run laptop_setup config.vm.provision "laptop", type: "ansible_local" do |ansible| ansible.inventory_path = "/vagrant/koaxiel/laptop_setup/inventory" @@ -44,14 +42,8 @@ Vagrant.configure("2") do |config| config.vm.define :archlinux do |archlinux| # Box name - # archlinux.vm.box = "archlinux" - # Domain Specific Options - # - # See README for more info. - # - # Options for libvirt vagrant provider. archlinux.vm.provider :libvirt do |libvirt| @@ -78,16 +70,13 @@ Vagrant.configure("2") do |config| # be stored. libvirt.storage_pool_name = "default" - # Set a prefix for the machines that's different than the project dir name. - #libvirt.default_prefix = '' - libvirt.memory = 2024 libvirt.cpus = 2 libvirt.cpu_mode = 'host-passthrough' libvirt.disk_bus = 'sata' - libvirt.storage :file, :device => :cdrom, :path => '/var/lib/libvirt/images/archlinux-2019.03.10-x86_64.iso' - libvirt.loader = '/usr/share/ovmf/x64/OVMF_CODE.fd' + libvirt.storage :file, :device => :cdrom, :path => '/var/lib/libvirt/images/archlinux.iso' + libvirt.loader = '/usr/share/edk2-ovmf/x64/OVMF_CODE.fd' libvirt.boot 'hd' libvirt.boot 'cdrom' diff --git a/roles/vagrant/tasks/main.yml b/roles/vagrant/tasks/main.yml index 7680a41..6b7a59a 100644 --- a/roles/vagrant/tasks/main.yml +++ b/roles/vagrant/tasks/main.yml @@ -7,21 +7,15 @@ update_cache: yes become: yes -# - name: Create folder +- name: Install vagran-libvirt and vagrant-reload plugin + command: VAGRANT_DISABLE_STRICT_DEPENDENCY_ENFORCEMENT=1 vagrant plugin install vagrant-libvirt vagrant-reload + args: + creates: '{{ ansible_user_dir }}/.vagrant.d/plugins.json' +- name: Add archlinux box + command: vagrant box add files/package.box --name archlinux + args: + creates: '{{ ansible_user_dir }}/.vagrant.d/boxes/archlinux/0/libvirt/box.img' +# - name: Create folder # - name: Create VagrantFile - - - -# - name: Install Vagrant plugins - -# vagrant plugin install - -# vagrant-libvirt -# vagrant-reload - - -# - name: Setup nfs - -# - name: Add Vagrant box \ No newline at end of file