cleanup redundant logic to initialize manta credentials
prakashsurya opened this issue · comments
In a few different scripts there exists logic like this:
log_must mkdir -p $HOME/.ssh
log_must chmod 700 $HOME/.ssh
log_must vault_read_manta_private_key > $HOME/.ssh/id_rsa
log_must chmod 400 $HOME/.ssh/id_rsa
log_must vault_read_manta_public_key > $HOME/.ssh/id_rsa.pub
log_must chmod 644 $HOME/.ssh/id_rsa
log_must test -d "$OPENZFSCI_DIRECTORY"
log_must cd "$OPENZFSCI_DIRECTORY/ansible"
log_must cat > inventory.txt <<EOF
$HOST ansible_ssh_user="$USER" ansible_ssh_pass="$PASS"
EOF
log_must cat > playbook.yml <<EOF
---
- hosts: localhost
tasks:
- wait_for:
host: $HOST
port: 22
state: started
timeout: 1800
EOF
log_must ansible-playbook -vvvv -i inventory.txt playbook.yml >&2
This is essentially copy/pasted into the scripts that need to interact with manta. We should remove the code duplication and instead have a shell library file that would provide a common function to perform this logic; then all scripts that needed to perform these steps would just use the function.
The same goes for the part that uses ansible to wait for port 22; rather than copy/pasting, we should have a way for the scripts to share this logic.