diff --git a/.github/workflows/ansible.yml b/.github/workflows/ansible.yml index 78f413b..cfa6e47 100644 --- a/.github/workflows/ansible.yml +++ b/.github/workflows/ansible.yml @@ -99,7 +99,11 @@ jobs: - name: Run Ansible Playbook if: ${{ inputs.ansible_verbose == false }} run: ansible-playbook -i inventory site.yml - + + - name: Show ansible facte + if: ${{ inputs.ansible_verbose == true }} + run: ansible all -i inventory -m ansible.builtin.setup + - name: Run Ansible Playbook (verbose) if: ${{ inputs.ansible_verbose == true }} run: ansible-playbook -i inventory -vvvv site.yml diff --git a/host_vars/localhost.yml b/host_vars/localhost.yml new file mode 100644 index 0000000..c7a02ee --- /dev/null +++ b/host_vars/localhost.yml @@ -0,0 +1,7 @@ +all: + hosts: + localhost: + hostname: hostname1 + fqdn: hostname1.domain.tld + username: user001 + dns1: 10.0.0.1 diff --git a/tasks/configuration/main.yml b/tasks/configuration/main.yml index 5472c2a..1c4c1eb 100644 --- a/tasks/configuration/main.yml +++ b/tasks/configuration/main.yml @@ -1,10 +1,39 @@ --- - -- name: Set the machine FQDN - when: ansible_fqdn is defined and ansible_fqdn | length <= 32 +- name: Set the machine hostname + when: hostname is defined and hostname | length <= 32 become: true ansible.builtin.hostname: - name: "{{ ansible_facts['fqdn'] }}" + name: "{{ hostname }}" + +- name: Set the machine hostname and fqdn + become: true + ansible.builtin.lineinfile: + path: /etc/hosts + regexp: '^127\.0\.1\.1' + line: "127.0.1.1 {{ fqdn }} {{ hostname }}" + create: true + mode: "0644" + +- name: Create new user + become: true + ansible.builtin.user: + name: "{{ username }}" + shell: /bin/bash + create_home: true + state: present + +- name: Read current DNS servers + ansible.builtin.command: + cmd: resolvectl dns {{ ansible_facts['default_ipv4']['interface'] }} + register: current_dns + changed_when: false + +- name: Configure DNS via systemd-resolved + become: true + ansible.builtin.command: + cmd: resolvectl dns {{ ansible_facts['default_ipv4']['interface'] }} {{ dns1 }} + when: dns1 not in current_dns.stdout + changed_when: true - name: Set timezone to Europe/Amsterdam become: true @@ -35,7 +64,7 @@ - name: Check if SSH private key already exists ansible.builtin.find: - paths: "/home/{{ ansible_facts.user_id }}/.ssh" + paths: "/home/{{ ansible_facts['user_id'] }}/.ssh" file_type: file patterns: - "id_*" diff --git a/tasks/disk/main.yml b/tasks/disk/main.yml index 556eeb9..edf841c 100644 --- a/tasks/disk/main.yml +++ b/tasks/disk/main.yml @@ -42,8 +42,7 @@ - name: Skip disk partitioning ansible.builtin.meta: end_play when: - - in_pipeline | bool - or single_root_disk + - single_root_disk - name: Ensure all packages are up to date become: true diff --git a/tasks/docker/main.yml b/tasks/docker/main.yml index 61a28e8..4daeaa8 100644 --- a/tasks/docker/main.yml +++ b/tasks/docker/main.yml @@ -189,7 +189,9 @@ path: "/home/{{ ansible_facts['user_id'] }}/.bashrc" line: "export DOCKER_HOST=unix:///run/user/{{ ansible_facts['user_uid'] }}/docker.sock" state: present - register: bashrc_docker_host_check + mode: "0644" + create: true +# register: bashrc_docker_host_check ignore_errors: true changed_when: false @@ -201,14 +203,14 @@ # ignore_errors: true # changed_when: false - - name: Ensure DOCKER_HOST is set in .bashrc - ansible.builtin.lineinfile: - path: /home/{{ ansible_facts['user_id'] }}/.bashrc - line: "export DOCKER_HOST=unix:///run/user/{{ ansible_facts['user_uid'] }}/docker.sock" - state: present - create: true - mode: "0644" - when: bashrc_docker_host_check.rc != 0 +# - name: Ensure DOCKER_HOST is set in .bashrc +# ansible.builtin.lineinfile: +# path: /home/{{ ansible_facts['user_id'] }}/.bashrc +# line: "export DOCKER_HOST=unix:///run/user/{{ ansible_facts['user_uid'] }}/docker.sock" +# state: present +# create: true +# mode: "0644" +# when: bashrc_docker_host_check.rc != 0 - name: Check if lingering is enabled for the user ansible.builtin.command: loginctl show-user {{ ansible_facts['user_id'] }} --property=Linger diff --git a/tasks/ubuntu2404.yml b/tasks/ubuntu2404.yml index de56d68..1cb55a4 100644 --- a/tasks/ubuntu2404.yml +++ b/tasks/ubuntu2404.yml @@ -4,7 +4,7 @@ msg: "Running tasks for Ubuntu 24.04" - name: Disk Configuration - when: ubtu24_run_task_disk + when: ubtu24_run_task_disk and not in_pipeline | bool ansible.builtin.import_tasks: disk/main.yml tags: - disk