Question

Need example of Ansible ssh public and private key installation

In this tutorial https://www.digitalocean.com/community/tutorials/how-to-use-ansible-with-terraform-for-configuration-management

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: │ Error running command ‘ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -u root -i ‘137.184.135.14,’ --private-key ~/.ssh/id_ed25519 -e ‘pub_key=~/.ssh/id_ed25519.pub’ apache-install.yml’: exit status 2. Output: │ PLAY [apache-install] ********************************************************** │ │ TASK [Gathering Facts] ********************************************************* │ fatal: [137.184.135.14]: FAILED! => {“changed”: false, “module_stderr”: “Shared connection to 137.184.135.14 closed.\r\n”, “module_stdout”: “/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? https://stackoverflow.com/questions/29392369/ansible-ssh-private-key-in-source-control

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 “digitalocean_ssh_key” “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

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi there,

As this tutorial uses Terraform, what I could suggest is to follow the prerequisites on how to prepare all this up and mainly this tutorial here:

https://www.digitalocean.com/community/tutorials/how-to-use-terraform-with-digitalocean

It covers the SSH setup and configuration.

Hope that this helps. Best, Bobby