So I started learning ansible curiously and the instructor told me to experiment some variables in inventory and I tried with my little knowledge
this is my inventory file
[newserver]
server1 ansible_host=54.208.201.158
server2 ansible_host=3.80.57.225
[newserver:vars]
ansible_user=ec2-user
ansible_ssh_private_key_file=/home/ec2-user/pem/safety.pem
and this is my playbook file reprctce.yml
---
- name: install nginx ( play name )
hosts: newserver
become: yes
tasks:
- name: install nginx ( task name )
yum:
name: nginx
state: latest
- name: install node ( task name )
yum:
name: nodejs
state: latest
- name: starting nginx (task name)
service:
name: nginx
state: started
when I started running these playbooks with ansible navigator it throws error as
fatal: [server1]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: no such identity: /home/ec2-user/pem/safety.pem: No such file or directory\r\[email protected]: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).", "unreachable": true}
fatal: [server2]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: no such identity: /home/ec2-user/pem/safety.pem: No such file or directory\r\[email protected]: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).", "unreachable": true}
but the fact is I double checked my ssh key file and it was absolutely correct.
I also tried with old fashioned ansible-playbook run command and the result is it actually made changes in second server and displays first server as a unreachable one and at this point I have really confused My guess is I could have done error in constructing inventory file , help me to find my error