From f46c445b8d7267ba51b9731efb6a883d00549649 Mon Sep 17 00:00:00 2001 From: Florian RICHER Date: Tue, 2 May 2023 18:25:49 +0200 Subject: [PATCH] Fix docker with ssh --- docker/Dockerfile | 9 ++------- docker/inventory.yaml | 9 ++++++--- docker/start | 2 +- playbook.yml | 4 ++++ 4 files changed, 13 insertions(+), 11 deletions(-) create mode 100644 playbook.yml diff --git a/docker/Dockerfile b/docker/Dockerfile index 87b416d..f474be0 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -3,13 +3,8 @@ FROM fedora:38 RUN dnf install openssh-server -y RUN ssh-keygen -A -v -RUN sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config -RUN sed -i 's/#PermitEmptyPasswords no/PermitEmptyPasswords no/' /etc/ssh/sshd_config -RUN sed -i 's/#PubkeyAuthentication yes/PubkeyAuthentication yes/' /etc/ssh/sshd_config - -RUN sed -i 's/#PermitRootLogin yes/PermitRootLogin yes/' /etc/ssh/sshd_config -RUN sed -i 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' /etc/pam.d/sshd -RUN echo 'root:root' | chpasswd +RUN useradd -m -G wheel test +RUN echo 'test:test' | chpasswd EXPOSE 22 CMD ["/usr/sbin/sshd", "-D", "-o", "ListenAddress=0.0.0.0"] \ No newline at end of file diff --git a/docker/inventory.yaml b/docker/inventory.yaml index d3ff1c3..a22a5eb 100644 --- a/docker/inventory.yaml +++ b/docker/inventory.yaml @@ -1,4 +1,7 @@ servers: - localhost: - ansibleConnection: ssh - ansibleUser: root \ No newline at end of file + hosts: + localhost: + ansible_connection: ssh + ansible_user: test + ansible_port: 1022 + ansible_become_password: test \ No newline at end of file diff --git a/docker/start b/docker/start index ebe1bde..b1b9a02 100755 --- a/docker/start +++ b/docker/start @@ -1,3 +1,3 @@ #!/bin/sh docker build -t ansible_test:latest docker/ -docker run --rm -d --name ansible_test --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:rw -v $HOME/.ssh/id_rsa.pub:/root/.ssh/authorized_keys:ro -p 1022:22 --cgroupns=host ansible_test:latest \ No newline at end of file +docker run --rm -d --name ansible_test --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:rw -v $HOME/.ssh/id_rsa.pub:/home/test/.ssh/authorized_keys:ro -p 1022:22 --cgroupns=host ansible_test:latest \ No newline at end of file diff --git a/playbook.yml b/playbook.yml new file mode 100644 index 0000000..a883eb2 --- /dev/null +++ b/playbook.yml @@ -0,0 +1,4 @@ +--- +- name: Install servers + hosts: servers + become: true