From 069c4aa49e852fb79047d8a58a6634eacecc3905 Mon Sep 17 00:00:00 2001 From: Matthew Stobbs Date: Fri, 14 Feb 2025 22:52:53 -0700 Subject: [PATCH] adding tests - stat doesn't work on remote, need to figure out a workaround --- meta/main.yml | 4 +--- tasks/addpkg.yml | 14 ++++++++++---- tasks/go.yml | 3 +++ tasks/main.yml | 5 ----- tests/Containerfile | 17 +++++++++++++++++ tests/inventory | 2 -- tests/inventory.yml | 7 +++++++ tests/pubkey | 1 + tests/test.yml | 7 ++++++- 9 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 tests/Containerfile delete mode 100644 tests/inventory create mode 100644 tests/inventory.yml create mode 100644 tests/pubkey diff --git a/meta/main.yml b/meta/main.yml index ca8f837..4e5a550 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -28,6 +28,4 @@ galaxy_info: - package - software -dependencies: - - ansible.builtin - - community.general +dependencies: [] diff --git a/tasks/addpkg.yml b/tasks/addpkg.yml index 27b4f2d..111855a 100644 --- a/tasks/addpkg.yml +++ b/tasks/addpkg.yml @@ -5,21 +5,27 @@ path: "{{ role_path }}/tasks/pkgs/{{ pkg }}.yml" register: stat_pkg +- name: Dump stat_pkg + ansible.builtin.debug: + var: stat_pkg + - name: "Check if specialized configuration exists for {{ pkg }}" - when: - - stat_pkg.exists ansible.builtin.stat: path: "{{ role_path }}/tasks/config/{{ pkg }}.yml" register: stat_config +- name: Dump stat_config + ansible.builtin.debug: + var: stat_config + - name: "Load specialized configuration if it exists for {{ pkg }}" when: - - stat_config.exists + - stat_config.stat.exists ansible.builtin.include_tasks: file: "config/{{ pkg }}.yml" - name: "Add include task for {{ pkg }}" when: - - stat_pkg.exists + - stat_pkg.stat.exists ansible.builtin.include_tasks: file: "pkgs/{{ pkg }}.yml" diff --git a/tasks/go.yml b/tasks/go.yml index 3506bbd..3532985 100644 --- a/tasks/go.yml +++ b/tasks/go.yml @@ -1,6 +1,9 @@ --- - name: Install go packages become: "{{ archive_become }}" + environment: + GOBIN: "{{ paths.bin }}" + PATH: "{{ paths.go }}/bin:$PATH" ansible.builtin.command: creates: "{{ paths.bin }}/{{ pkg.bin }}" cmd: diff --git a/tasks/main.yml b/tasks/main.yml index 56fc4b5..cc50ba4 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -28,8 +28,6 @@ ansible.builtin.include_tasks: file: addpkg.yml - - - name: Install sys_pkgs list using system package manager become: "{{ sys_pkg_become }}" ansible.builtin.package: @@ -79,9 +77,6 @@ loop: "{{ go_pkgs | unique }}" loop_control: loop_var: pkg - environment: - GOBIN: "{{ paths.bin }}" - PATH: "{{ paths.go }}/bin:$PATH" ansible.builtin.include_tasks: file: go.yml diff --git a/tests/Containerfile b/tests/Containerfile new file mode 100644 index 0000000..2bad7a8 --- /dev/null +++ b/tests/Containerfile @@ -0,0 +1,17 @@ +FROM fedora:41 +LABEL PROJECT "ansible_role_package" +LABEL MAINTAINER "Matthew Stobbs " + +RUN useradd -d /home/ansible -m -G wheel ansible +RUN dnf install -y openssh-server python3-paramiko python3-libdnf5 +EXPOSE 22 + +USER ansible +WORKDIR /home/ansible +RUN mkdir /home/ansible/.ssh +COPY ./pubkey /home/ansible/.ssh/authorized_keys + +USER root +RUN echo "ansible ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/sudoers +RUN ssh-keygen -A +ENTRYPOINT /usr/sbin/sshd -D diff --git a/tests/inventory b/tests/inventory deleted file mode 100644 index 878877b..0000000 --- a/tests/inventory +++ /dev/null @@ -1,2 +0,0 @@ -localhost - diff --git a/tests/inventory.yml b/tests/inventory.yml new file mode 100644 index 0000000..dd14dfb --- /dev/null +++ b/tests/inventory.yml @@ -0,0 +1,7 @@ +test: + hosts: + localhost: + ansible_ssh_host: 127.0.0.1 + ansible_ssh_port: 2222 + ansible_ssh_user: ansible + ansible_ssh_extra_args: "-o StrictHostKeyChecking=no" diff --git a/tests/pubkey b/tests/pubkey new file mode 100644 index 0000000..ea6ad18 --- /dev/null +++ b/tests/pubkey @@ -0,0 +1 @@ +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAAxfDLK7wu1ITTMV8gIzImO+KkXsjByvN7gYebqb5e+ stobbsm@ed25591 diff --git a/tests/test.yml b/tests/test.yml index 7a3ea63..4cff583 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -2,4 +2,9 @@ - hosts: localhost remote_user: root roles: - - ansible_role_package + - role: ansible_role_package + vars: + use_local: false + packages: + - air + - ansible-language-server