Skip to content

Commit 335dbe8

Browse files
committed
Add :edit:host-config task
1 parent 8285efe commit 335dbe8

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

.rkd/makefile.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,26 @@ tasks:
6666
"host":
6767
help: "Host name or group name"
6868
steps: ansible-playbook ./playbooks/encrypt-disks.yml --limit=$ARG_HOST -i inventory/hosts.cfg ${ARG_ARGS}
69+
70+
:node:edit:host-config:
71+
description: Edit an encrypted host_var file
72+
arguments:
73+
"host":
74+
help: "Host name or group name"
75+
steps: |
76+
inventory_path=./inventory/host_vars/${ARG_HOST}.yaml
77+
78+
if [[ ! -f "${inventory_path}" ]]; then
79+
echo " >> ${inventory_path} does not exist yet, creating - you will be prompted for password multiple times"
80+
touch "${inventory_path}"
81+
ansible-vault encrypt "${inventory_path}"
82+
83+
elif [[ "$(cat $inventory_path)" != *"ANSIBLE_VAULT"* ]]; then
84+
echo " >> ${inventory_path} is not an encrypted file, encrypting - you will be prompted for password multiple times"
85+
ansible-vault encrypt "${inventory_path}"
86+
fi
87+
88+
set -x;
89+
export EDITOR=${TEXT_EDITOR};
90+
ansible-vault edit "${inventory_path}"
91+
cd inventory && git add host_vars/${ARG_HOST}.yaml

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ With this combination you can divide access to multiple admins handling administ
106106
nano .env
107107
```
108108

109+
Editing inventory per host
110+
--------------------------
111+
112+
This command will automatically encrypt existing and new file using AES-256 with Ansible Vault.
113+
114+
```bash
115+
rkd :edit:host-config my-host.org
116+
```
117+
109118
Deploying
110119
---------
111120

0 commit comments

Comments
 (0)