From d9f7b43597a8683027b9b2bd59ab9ba78c8e810e Mon Sep 17 00:00:00 2001 From: Bastian Bowe Date: Mon, 8 Feb 2021 22:31:53 +0100 Subject: [PATCH] Allow testing this role with non-root user until https://github.com/geerlingguy/docker-ubuntu1804-ansible/pull/11 has been merged --- molecule/default/Dockerfile.j2 | 10 ++++++++++ molecule/default/converge.yml | 1 + molecule/default/molecule.yml | 7 +++++-- tasks/main.yml | 6 ++++++ 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 molecule/default/Dockerfile.j2 diff --git a/molecule/default/Dockerfile.j2 b/molecule/default/Dockerfile.j2 new file mode 100644 index 0000000..e4ed6b0 --- /dev/null +++ b/molecule/default/Dockerfile.j2 @@ -0,0 +1,10 @@ +FROM geerlingguy/{{ item.image }} +# Create `ansible` user with sudo permissions and membership in `DEPLOY_GROUP` +ENV ANSIBLE_USER=ansible SUDO_GROUP=sudo DEPLOY_GROUP=deployer +RUN set -xe \ + && groupadd -r ${ANSIBLE_USER} \ + && groupadd -r ${DEPLOY_GROUP} \ + && useradd -m -g ${ANSIBLE_USER} ${ANSIBLE_USER} \ + && usermod -aG ${SUDO_GROUP} ${ANSIBLE_USER} \ + && usermod -aG ${DEPLOY_GROUP} ${ANSIBLE_USER} \ + && sed -i "/^%${SUDO_GROUP}/s/ALL\$/NOPASSWD:ALL/g" /etc/sudoers \ No newline at end of file diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index cab603f..538e287 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -1,6 +1,7 @@ --- - name: Converge hosts: all + become: yes tasks: - name: Include this role diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 79591d4..fbfc71d 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -10,10 +10,13 @@ driver: ansible_connection: local platforms: - name: instance - image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2004}-ansible:latest" - pre_build_image: true + image: "docker-${MOLECULE_DISTRO:-ubuntu2004}-ansible:latest" provisioner: name: ansible log: True + inventory: + host_vars: + instance: + ansible_user: ansible verifier: name: ansible diff --git a/tasks/main.yml b/tasks/main.yml index 7788cbe..9f8abd6 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -28,6 +28,12 @@ recurse: no register: settings_sync_ext_find become: no +- name: Install additional packages in order to be able to run the extension installation below +# Might be obsolete with the official settings sync function + apt: + pkg: + - libx11-xcb1 + - libasound2 - name: Install code-settings-sync extension command: code --install-extension shan.code-settings-sync become: no