Managed Node in Azure

I provisioned a Red Hat Linux in Azure. When you provision a Linux host in Azure, the default user is azureuser. I would like to manage the host from the Ansible node on OCI. Here is the /etc/ansible/hosts file that I modified.

[jenkins]
jenkins.pub.ashburn.oraclevcn.com

[test]
ansibletest.westcentralus.cloudapp.azure.com

When I test the managed nodes, I get the following error.

ansibletest.westcentralus.cloudapp.azure.com | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).",
    "unreachable": true
}

This is because Ansible tries to access the host with the default user instead of azureuser. To specify a certain user to be used on the managed node, here is what you can do.

[jenkins]
jenkins.pub.ashburn.oraclevcn.com

[test]
ansibletest.westcentralus.cloudapp.azure.com ansible_user=azureuser

If you run the following commnad…

ansible-3 all -m ping

Output:

jenkins.pub.ashburn.oraclevcn.com | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}
ansibletest.westcentralus.cloudapp.azure.com | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}

This way, it uses azureuser to access the host in Azure.

Leave a Reply

Your email address will not be published.