Run the playbook
Follow these steps to run the playbook successful.
User- and Hostname
We will use Use the |
Requirements
-
Git
git clone https://somepi.ddns.net/gitea/gilex-dev/GisServer.git cd GisServer
-
Python venv
python3 -m venv ./.venv --system-site-packages source ./.venv/bin/activate pip3 install -r requirements.txt ansible-galaxy install -r requirements.yaml
Adding your host
-
Choose the inventory name used by ansible (this does not have to be the actual hostname)
export NEW_ANSIBLE_INV_NAME="testing-server-1"
-
Set hostname used by ansible
export NEW_ANSIBLE_HOST="test-host"
-
Set username used by ansible
export NEW_ANSIBLE_USER="manager"
.ssh-keygen -a 100 -t ed25519 -C "a comment" -f ~/.ssh/id_debian-gis ssh-keygen -a 100 -t ed25519 -C "another comment" -f ~/.ssh/id_publisher@$NEW_ANSIBLE_HOST ssh-copy-id -i ~/.ssh/id_debian-gis $NEW_ANSIBLE_USER@$NEW_ANSIBLE_HOST ssh-add ~/.ssh/id_debian-gis # optional, to remember key-phrase
-
Add the host to the inventory
nano inventory.yaml
(keep other entries)testing: # | production or any other group name hosts: test-host: # same as $NEW_ANSIBLE_HOST ansible_host: "{{ inventory_hostname }}" # or any address where the host is reachable ansible_user: # NEW_ANSIBLE_USER ansible_ssh_private_key_file: # ~/.ssh/id_$NEW_ANSIBLE_USER@$NEW_ANSIBLE_HOST
-
Create a directory for the host
mkdir host_vars/$NEW_ANSIBLE_HOST
-
Copy the basic config file
cp host_vars/variables.yaml.template host_vars/$NEW_ANSIBLE_HOST/variables.yaml
-
Create the vault to store passwords needed by ansible
ansible-vault encrypt host_vars/secrets.yaml.template --output host_vars/$NEW_ANSIBLE_HOST/secrets.yaml`
-
Edit the vault
ansible-vault edit host_vars/$NEW_ANSIBLE_HOST/secrets.yaml # Generate a new password for every entry (preferably A-z0-9 to avoid escape mishaps)
-
Add the host config to your
~/.ssh/config
file to allow a simple ssh connectionHost # e.g. $NEW_ANSIBLE_HOST HostName # $NEW_ANSIBLE_HOST User # $NEW_ANSIBLE_USER IdentityFile # ~/.ssh/id_$NEW_ANSIBLE_User@NEW_ANSIBLE_HOST IdentitiesOnly yes VisualHostKey yes
-
Clear env-var hostname
unset NEW_ANSIBLE_HOST
and userunset NEW_ANSIBLE_USER
-
Repeat for any other hosts you want to be managed by this playbook
Run ansible (finally)
If you don’t want to make any changes in host_vars/$NEW_ANSIBLE_HOST/variables.yaml
you can now run the playbook with the following command:
ansible-playbook playbooks/main.yaml --ask-vault-pass
# or store the vault password in variables/vault_password.txt (only for testing)
# ansible-playbook playbooks/main.yaml --vault-password-file variables/vault_password.txt
Don’t panic if the following tasks take long to complete the first time you run the playbook on a host:
-
Ensure valid apt cache and required tools are present
-
Ensure qgis-server is present