Need example of Ansible ssh public and private key installation

Posted September 26, 2021 171 views
Configuration ManagementAnsibleTerraform

In this tutorial

There is mention in ~/terraform-ansible/apache-install.yml
to use the public key as:
key: “{{ lookup(‘file’, pub_key) }}”

command = "ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -u root -i '${self.ipv4_address},' --private-key ${var.pvt_key} -e 'pub_key=${var.pub_key}' apache-install.yml"

However, I am getting this error, and I am unclear if the key path should be for my local or target directory? Am I declaring the path correctly? Could the example be improved?

│ Error running command 'ANSIBLEHOSTKEYCHECKING=False ansible-playbook -u root -i ',’ –private-key ~/.ssh/ided25519 -e 'pubkey=~/.ssh/’ apache-install.yml’: exit status 2. Output:
│ PLAY [apache-install] **********************************************************

│ TASK [Gathering Facts] *********************************************************
│ fatal: []: FAILED! => {“changed”: false, “modulestderr”: “Shared connection to closed.\r\n”, “modulestdout”: “/bin/sh: 1: /usr/bin/python: not found\r\n”, “msg”: “MODULE FAILURE\nSee stdout/stderr for the exact error”, “rc”: 127}
│ to retry, use: –limit @/mnt/ap/ap/terraform-ansible/apache-install.retry

Note that I see this from Stack Overflow, not sure if it is relevant?

I also am getting confused about keeping secrets vs storing things in the wrong places.

Could use an example .gitignore too

Also - for this digitalocean ssh key

data “digitaloceansshkey” “terraform” {
name = “terraform”

  • the “terraform” is the name in the DigitalOcean control panel name - not intuitive that it is not a local id_rsa name. Some more clarity in the example might be useful too.
Submit an answer

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!