This YAML script is designed to manage the configuration of an Apache2 server on a given host. It handles the configuration of all aspects related to the provided domain names.
Before using this script, ensure that you have ansible
installed on your machine and also have the root password
for the host where you want to configure Apache2. Additionally, make sure that the server has openssh-server
installed.
You can also do it with ssh keys
if you want,for that, you should read this file first.
- Look for the line containing the directive
PermitRootLogin
on the file/etc/ssh/sshd_config
. If it is commented out (starts with a #), remove the # symbol at the beginning of the line and set it to yes :PermitRootLogin yes
.
If the PermitRootLogin line is already present and set to no, change it to yes.
- Then, restart ssh server with
sudo sytemctl restart ssh
then you should be able to log in as the root user using SSH.
- Set your server's ip on the file
hosts
like this :
192.168.0.127
- Put all your domain names in the
domains
file:
www.example.com
abd.google.com
xyz.node.xyz
- You can launch the script with the following command if you use an SSH key to connect as root on the server and not with a root password
ansible-playbook -i hosts --private-key=your_private_ssh_key script.yaml
- If you have set a passphrase for the SSH keys:
ansible-playbook -i hosts --private-key=your_private_ssh_key --ask-pass script.yaml
# The --ask-pass option is added
- Replace
your_private_ssh_key
with your private key.
-
You need to install
sshpass
on your local machine (the machine from which you will run the script.yaml playbook) to enablepassword-based SSH authentication
. -
Make sure that the host's fingerprint is already configured. You can do this manually with the following command:
ssh <host>
#replace <host> with the IP address of the server
- Now you can run
script.yaml
with the following command :
ansible-playbook -i hosts script.yaml -k
- It will prompt for the
SSH pass
, which is the root password on the host (server).
Now you just need to configure a DNS server or add the following lines to the /etc/hosts
file on each machine from which you want to access the domain names:
#server domain
192.168.43.30 www.example.com
192.168.43.30 abd.google.com
192.168.43.30 xyz.node.xyz