I’m using Ubuntu Linux
I have created an inventory file and I have put my own system IP address there.
I have written a playbook to install the nginx package.
I’m getting the following error:
false, msg" : Failed to connect to the host via ssh: connect to host myip : Connection refused, unreachable=true
How can I solve this?
2
Answers
You could use the
hosts
keyword with the valuelocalhost
Putting your host IP directly in your inventory treats your local machine as any other remote target. Although this can work, ansible will use the
ssh
connection plugin by default to reach your IP. If an ssh server is not installed/configured/running on your host it will fail (as you have experienced), as well as if you did not configure the needed credentials (ssh keys, etc.).You don’t need to (and in most common situations you don’t want to) declare
localhost
in your inventory to use it as it is implicit by default. The implicitlocalhost
uses thelocal
connection plugin which does not need ssh at all and will use the same user to run the tasks as the one running the playbook.For more information on connection plugins, see the current list
See @gary lopez answer for an example playbook to use
localhost
as target.