Closed MartynKeigher closed 3 years ago
Hi @MartynKeigher
We'll get this resolved. Can you please share with me the contents of your .env file. Also, tell me, this Ubuntu-VM that you're using, how is it running? There will be an additional step that you will need if this is a remote system (i.e. one you access remotely via ip).
Thanks
To give a bit more context as you asked me to elaborate. In the Docker Compose file, we have entries such as the following -
services:
ubuntu-c:
hostname: ubuntu-c
container_name: ubuntu-c
image: spurin/diveintoansible:ansible
ports:
- ${UBUNTUC_PORT_SSHD}:22
- ${UBUNTUC_PORT_TTYD}:7681
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- ${CONFIG}:/config
- ${ANSIBLE_HOME}/shared:/shared
- ${ANSIBLE_HOME}/ubuntu-c/ansible:/home/ansible
- ${ANSIBLE_HOME}/ubuntu-c/root:/root
networks:
- diveinto.io
Note how these are using the environment variables of ${CONFIG} and ${ANSIBLE_HOME}, these variables are read from the .env file.
What should happen, if it's working as expected. When the lab environment starts, it will mount those volumes accordingly with directories on your local system. This in turn, presents the config directory to the container as /config, this folder has details of what users etc to create.
When the container image starts up, if the /config directory exists, it reads the data in here and creates users (like the ansible user, along with a password).
If the /config mount isn't working as expected, when it starts up, it doesn't create the ansible user.
Let's take a look at the .env file and see if we can work out what is wrong.
Cheers
Something else worth adding ... as you're running in a VM rather than your local system, you may be seeing a nuance of Docker where for example, it's running as root and then it's trying to access config from a user directory. As well as seeing your .env file, it will be useful if you can share with me how you're running the docker-compose up. Am confident we'll be able to get this working by the way :) :)
OK - I got it to work and it was 100%... permissions! Naturally... lol!
Instead of pulling your content down, I manually created the 4 config files, the docker-compose & the .env
I also made slight changes to the docker-compose (volume & network properties) and now it works like a champ!
Here is my working copy of the docker-compose:
version: "3"
services:
ubuntu-c:
hostname: ubuntu-c
container_name: ubuntu-c
image: spurin/diveintoansible:ansible
ports:
- ${UBUNTUC_PORT_SSHD}:22
- ${UBUNTUC_PORT_TTYD}:7681
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- $PWD/config:/config
- $PWD/home/shared:/shared
- $PWD/home/ubuntu-c/ansible:/home/ansible
- $PWD/home/ubuntu-c/root:/root
networks:
- ansible
ubuntu1:
hostname: ubuntu1
container_name: ubuntu1
image: spurin/diveintoansible:ubuntu
ports:
- ${UBUNTU1_PORT_SSHD}:22
- ${UBUNTU1_PORT_TTYD}:7681
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- $PWD/config:/config
- $PWD/home/shared:/shared
- $PWD/home/ubuntu1/ansible:/home/ansible
- $PWD/home/ubuntu1/root:/root
networks:
- ansible
ubuntu2:
hostname: ubuntu2
container_name: ubuntu2
image: spurin/diveintoansible:ubuntu
ports:
- ${UBUNTU2_PORT_SSHD}:22
- ${UBUNTU2_PORT_TTYD}:7681
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- $PWD/config:/config
- $PWD/home/shared:/shared
- $PWD/home/ubuntu2/ansible:/home/ansible
- $PWD/home/ubuntu2/root:/root
networks:
- ansible
ubuntu3:
hostname: ubuntu3
container_name: ubuntu3
image: spurin/diveintoansible:ubuntu
ports:
- ${UBUNTU3_PORT_SSHD}:22
- ${UBUNTU3_PORT_TTYD}:7681
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- $PWD/config:/config
- $PWD/home/shared:/shared
- $PWD/home/ubuntu3/ansible:/home/ansible
- $PWD/home/ubuntu3/root:/root
networks:
- ansible
centos1:
hostname: centos1
container_name: centos1
image: spurin/diveintoansible:centos
#image: spurin/diveintoansible:centos-sshd-2222
ports:
- ${CENTOS1_PORT_SSHD}:22
#- ${CENTOS1_PORT_SSHD}:2222
- ${CENTOS1_PORT_TTYD}:7681
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- $PWD/config:/config
- $PWD/home/shared:/shared
- $PWD/home/centos1/ansible:/home/ansible
- $PWD/home/centos1/root:/root
networks:
- ansible
centos2:
hostname: centos2
container_name: centos2
image: spurin/diveintoansible:centos
ports:
- ${CENTOS2_PORT_SSHD}:22
- ${CENTOS2_PORT_TTYD}:7681
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- $PWD/config:/config
- $PWD/home/shared:/shared
- $PWD/home/centos2/ansible:/home/ansible
- $PWD/home/centos2/root:/root
networks:
- ansible
centos3:
hostname: centos3
container_name: centos3
image: spurin/diveintoansible:centos
ports:
- ${CENTOS3_PORT_SSHD}:22
- ${CENTOS3_PORT_TTYD}:7681
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- $PWD/config:/config
- $PWD/home/shared:/shared
- $PWD/home/centos3/ansible:/home/ansible
- $PWD/home/centos3/root:/root
networks:
- ansible
# Docker in Docker
#
# Usage: on host that wishes to use docker
#
# sudo apt-get update
# sudo apt -y install docker.io
# export DOCKER_HOST=tcp://docker:2375
# docker ps -a
#
docker:
hostname: docker
container_name: docker
image: spurin/diveintoansible:dind
privileged: yes
volumes:
- $PWD/home/shared:/shared
networks:
- ansible
portal:
hostname: portal
container_name: portal
image: spurin/diveintoansible:portal
environment:
- NGINX_ENTRYPOINT_QUIET_LOGS=1
- LOCALHOST_OVERRIDE=10.10.58.102
depends_on:
- centos1
- centos2
- centos3
- ubuntu1
- ubuntu2
- ubuntu3
ports:
- "1000:80"
networks:
- ansible
networks:
ansible:
external: false
NOTE: My $PWD
is /home/martyn/docker/ansible-lab
I left all commented-out lines in place (in docker-compose.yml) as I don't know if they have some relevance for later on in the course, and there is my .env file:
# sshd ports
UBUNTUC_PORT_SSHD=2221
UBUNTU1_PORT_SSHD=2222
UBUNTU2_PORT_SSHD=2223
UBUNTU3_PORT_SSHD=2224
CENTOS1_PORT_SSHD=2225
CENTOS2_PORT_SSHD=2226
CENTOS3_PORT_SSHD=2227
# ttyd (web terminal) ports
UBUNTUC_PORT_TTYD=7681
UBUNTU1_PORT_TTYD=7682
UBUNTU2_PORT_TTYD=7683
UBUNTU3_PORT_TTYD=7684
CENTOS1_PORT_TTYD=7685
CENTOS2_PORT_TTYD=7686
CENTOS3_PORT_TTYD=7687
With these in place, it doesn't look like I need to do the 'extra steps required' on linux.
With all that said.. I do appreciate the quick response to my issue, but for now, all seems to be working just fine... and now I move forward with the course!
Thanks so much!
://mk
Hey @MartynKeigher
Interesting approach on the $PWD! I like it :-) :-) Will actually give this a try on the other operating systems to see if they honour it, might make things easier for people in general.
Great to see that you already have the LOCALHOST_OVERRIDE. Hope you enjoy the course and any other issues, just ping me. Depending on when you built your lab first, I updated Ansible yesterday to 4.1.0, docker-compose pull, will pull the latest one if you don't have it.
Thanks!
I like the fact that you keep this content up-to-date even after the initial course (on Udemy) was published!
I just started the course (pulled images) today... like 15 mins ago! Here is what I am seeing in ubuntu-c...
Is this what you are expecting? (I also pasted this image here to confirm my initial issue really is resolved!)
Thanks @MartynKeigher
Appreciate your comments, it's my aim to keep the course content up-to date going forward. I've put in some time in the background in creating an automated test framework which is under the 'tests' branch of the diveintoansible-lab, if this branch is run it essentially runs 161 tests at the moment, checking the lab etc and also that all of the playbooks execute without deprecation warnings.
Your environment is spot on by the way, the ansible --version is showing what is known as 'ansible-core'
If you run -
pip3 freeze | grep ansible
You'll see Ansible 4.1.0 (the current PyPi release) and core of 2.11.2 (which is the latest also).
Best Regards
James
Yup! Confirmed!
Cheers bud!
FYI: The $PWD/config
& $PWD/home
approach would remove the need for users to change the username from 'James' & would be one less thing for you to worry about... and support! ;p
Enjoy the rest of your weekend!
://mk
Thanks @MartynKeigher
Yep, I'm going to give the $PWD approach a try across the different platforms. I originally created the examples for 3 operating systems (Windows/Linux/Mac) but have found with variants being used, there are more ... for example
Linux as Ubuntu, Linux as Fedora/Arch (where it uses cgroups v2) Windows with WSL1, Windows with WSL2, Windows with WSL2 + Ubuntu as the Subsystem Mac x86, Mac M1
I'm pretty confident that the approach you've used will work well on Linux/Mac, it's the Windows variants that have the /mnt/c/users syntax which I'll need to verify. Fingers crossed as this will be a big win, will push it as a course update if it works out!
Thanks again for your time on this and, for teaching me about the $PWD! Enjoy the course and weekend!
Hey,
I have the containers up and running (to a degree)... one thing I have noticed is that during the
docker-compose up
phase, i'm not seeing the creation of the sub-folders in the ansible-lab (parent) directory. (I can confirm I have the initial lab-files (form the repo) in my home directory.I am running my docker instance on an Ubuntu 20.04 VM, and in the read me, specifically in the 'Extra step for Linux users' section you state...
Would you mind elaborating on this for me please? I have ran the chown command, locally (on my Ubuntu VM), but there is no 'ansible' local user there. I also swapped out the name 'ansible' for my own local username , but ... there is no '/shared/' folder to perform the action on? - I need a little more clarity on this part please?
Also.. maybe related, maybe not.. but when I try to log into ubuntu-c with ansible\password, it says the password is wrong. Is this expected?
Thanks. ://mk