This is a solution to ansible problems, and also a cheat sheet for the future if you remember working with ansible.
Just go to any directory and you can run bash setup.sh
.
It will also be useful if you will disassemble the scripts, and change, and see how it will work.
Also you can watch ansible course on youtube by this link
- Debian GNU/Linux 11 (bullseye)
- Docker version 20.10.16, build aa7e414
- ansible [core 2.12.6]
Versions of applications under which the scripts worked
You can parse the scripts in this order
- ansible-hello
- ansible-playbook link to apt, service
- ansible-basics link to loop, jinja2
- ansible-template link to jinja2, copy, file, template
- ansible-apps link to upstream in nginx
- ansible-roles link to roles in ansible
- ansible-vault link to vault in ansible
These commands were often used in the script. I wrote explanations to them.
A command that deletes all containers which are called local-vps-....
and have any characters after instead of a dot. Try running the command that is inside the brackets to see how it works.
docker container rm $(sudo docker container ps -a | grep -o local-vps-....) -f
The command launches a container with certain ports, and to which you can connect via ssh. Here is:
-d
- nameddetach
which, after launching the container, exits from its console--rm
- remove which, removes container after stopping it.--name "CONTAINER_NAME"
- The--name
parameter that sets theCONTAINER_NAME
name to the created container. Using the name it is easy to manage the container.-p OUTSIDE_PORT:INSIDE_PORT
- param-p
translates the container'sINSIDE_PORT
port to the computer'sOUTSIDE_PORT
. The question will appear, why did I write twice? The first parameter -p is used for nginx server translation. And the second parameter -p is used to simply open the port, which is also used forssh
connection.nginx:mainline
- name ofimage
by which the docker container is created. It should be last parametr for docker. Why? After name of image we writes arguments, which sends to image or container as arguments. For example, here isatlekbai/local-vps
image takes 1 argument. It is port for opening ssh port in container.
V_PORT_SSH=2222
V_PORT_NGINX=2422
docker run -d --rm --name local-vps-$V_PORT_NGINX -p $V_PORT_NGINX:80 -p $V_PORT_SSH:$V_PORT_SSH atlekbai/local-vps $V_PORT_SSH
Connection to the device via the V_PORT_SSH
(which equal to value which you set. Ex: 2222) port.
Default password to the container is
password
.
-p PORT
- params using for try to connect host in portPORT
.root@127.0.0.1
- is last param where writesusername
before symbol@
, andhost
value which equal toIP
.
ssh -p $V_PORT_SSH root@127.0.0.1
The command after which you can connect to the device without a password. Try entering the command above, after this command.
-p PORT
- params using for try to connect host in portPORT
.-f
- force, which enters the data and immediately proceeds to enter thepassword
.root@127.0.0.1
- is last param where writesusername
before symbol@
, andhost
value which equal toIP
.
ssh-copy-id -p $V_PORT_SSH -f root@127.0.0.1