Change to inventory name, Fix hostname magic variable

This commit is contained in:
gilex-dev 2024-06-18 13:38:02 +02:00
parent 503e6cd61a
commit f2e219ddf4
Signed by: gilex-dev
GPG Key ID: 9A2BEC7B5188D2E3
2 changed files with 6 additions and 6 deletions

View File

@ -74,27 +74,27 @@ testing: # or production or any other sensible group name
ansible_ssh_private_key_file: # ~/.ssh/id_$NEW_ANSIBLE_USER@$NEW_ANSIBLE_HOST 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` . Create a directory for the host `mkdir host_vars/$NEW_ANSIBLE_INV_NAME`
. Copy the basic config file . Copy the basic config file
+ +
[,bash] [,bash]
---- ----
cp host_vars/variables.yaml.template host_vars/$NEW_ANSIBLE_HOST/variables.yaml cp host_vars/variables.yaml.template host_vars/$NEW_ANSIBLE_INV_NAME/variables.yaml
---- ----
. Create the vault to store passwords needed by ansible . Create the vault to store passwords needed by ansible
+ +
[,bash] [,bash]
---- ----
ansible-vault encrypt host_vars/secrets.yaml.template --output host_vars/$NEW_ANSIBLE_HOST/secrets.yaml ansible-vault encrypt host_vars/secrets.yaml.template --output host_vars/$NEW_ANSIBLE_INV_NAME/secrets.yaml
---- ----
. Edit the vault . Edit the vault
+ +
[,bash] [,bash]
---- ----
ansible-vault edit host_vars/$NEW_ANSIBLE_HOST/secrets.yaml ansible-vault edit host_vars/$NEW_ANSIBLE_INV_NAME/secrets.yaml
# Generate a new password for every entry (preferably A-z0-9 to avoid escape mishaps) # Generate a new password for every entry (preferably A-z0-9 to avoid escape mishaps)
---- ----
@ -116,7 +116,7 @@ Host # e.g. $NEW_ANSIBLE_HOST
=== Run ansible (finally) === 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: If you don't want to make any changes in `host_vars/$NEW_ANSIBLE_INV_NAME/variables.yaml` you can now run the playbook with the following command:
[,bash] [,bash]
---- ----
ansible-playbook playbooks/main.yaml --ask-vault-pass ansible-playbook playbooks/main.yaml --ask-vault-pass

View File

@ -1,3 +1,3 @@
--- ---
# you have to generate the SSH-keys yourself # you have to generate the SSH-keys yourself
publisher_ssh_keys: ["~/.ssh/id_publisher@{{ ansible_hostname }}.pub"] publisher_ssh_keys: ["~/.ssh/id_publisher@{{ ansible_host }}.pub"] # or {{ inventory_hostname }}