Slide 1
Most trusted JOB oriented professional program
DevOps Certified Professional (DCP)

Take your first step into the world of DevOps with this course, which will help you to learn about the methodologies and tools used to develop, deploy, and operate high-quality software.

Slide 2
DevOps to DevSecOps – Learn the evolution
DevSecOps Certified Professional (DSOCP)

Learn to automate security into a fast-paced DevOps environment using various open-source tools and scripts.

Slide 2
Get certified in the new tech skill to rule the industry
Site Reliability Engineering (SRE) Certified Professional

A method of measuring and achieving reliability through engineering and operations work – developed by Google to manage services.

Slide 2
Master the art of DevOps
Master in DevOps Engineering (MDE)

Get enrolled for the most advanced and only course in the WORLD which can make you an expert and proficient Architect in DevOps, DevSecOps and Site Reliability Engineering (SRE) principles together.

Slide 2
Gain expertise and certified yourself
Azure DevOps Solutions Expert

Learn about the DevOps services available on Azure and how you can use them to make your workflow more efficient.

Slide 3
Learn and get certified
AWS Certified DevOps Professional

Learn about the DevOps services offered by AWS and how you can use them to make your workflow more efficient.

previous arrow
next arrow

How to access Ansible remote machine using SSH user and key?

How to access Ansible remote machine using SSH user and key?

There are following ways, you can autheticte linux remote server using Ansible.

Method 1 – Password Less authentication
https://www.tecmint.com/ssh-passwordless-login-using-ssh-keygen-in-5-easy-steps/

If You want to automate this process using Ansible in mutiple machine, follow this
https://everythingshouldbevirtual.com/ansible-ssh-key-distribution-for-password-less-ssh/

Method 2 – SSH key file using command line

[code]ansible-playbook -i hosts playbook.yml –key-file=remote-access.pem -u ec2-user –become[/code]

Method 3 – SSH key file in the inventory file:

[code]myHost1 ansible_ssh_private_key_file=remote-access.pem ansible_user=ec2-user
myHost2 ansible_ssh_private_key_file=remote-access.pem ansible_user=ec2-user[/code]

Method 4 – SSH key file in the host_vars:

[code]# hosts_vars/myHost1.yml
ansible_ssh_private_key_file: ~/.ssh/mykey1.pem
ansible_user=ec2-user
# hosts_vars/myHost2.yml
ansible_ssh_private_key_file: ~/.ssh/mykey2.pem
ansible_user=ec2-user[/code]

Method 5 – SSH key file in the group_vars:

[code]# hosts_vars/myHost1.yml
ansible_ssh_private_key_file: ~/.ssh/mykey1.pem
ansible_user=ec2-user
# hosts_vars/myHost2.yml
ansible_ssh_private_key_file: ~/.ssh/mykey2.pem
ansible_user=ec2-user[/code]

Method 6 – SSH key file in the vars section of your play:

[code]- hosts: myHost
remote_user: ubuntu
vars_files:
– vars.yml
vars:
ansible_ssh_private_key_file: “{{ key1 }}”
tasks:
– name: Echo a hello message
command: echo hello[/code]

Method 7 – SSH key file in the ansible.cfg:

[code][defaults]
inventory: <YOUR INVENTORY>
remote_user = <YOUR USER>
private_key_file = <PATH TO KEY_FILE>[/code]

Rajesh Kumar
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x