rundeck-plugins / ansible-plugin

Ansible Integration for Rundeck
MIT License
331 stars 100 forks source link

username in Resource Model to connect via ssh #203

Open odg0318 opened 5 years ago

odg0318 commented 5 years ago

I set nodes source from json Resource Model as you can see in https://rundeck.org/2.11.6/man5/resource-json.html. username is described as below.

User name to connect to the node via SSH.

And the json is written as below

{
  "server1": {
    "hostname": "172.16.5.10",
    "nodename": "172.16.5.10",
    "username": "jenkins"
  },
  "server2": {
    "hostname": "172.16.5.20",
    "nodename": "172.16.5.20",
    "username": "ansible"
  }
}

And I set SSH user to ansible on Edit Configuration > Default Node Executor > Ansible Ad-Hoc Node Executor > SSH Connection > SSH User.

Under the environment, server1 cannot be accessed but server2 can be accessed. It seems that username in Resource Model is not used as ssh user.

How can I change an username used to connect via ssh?

Thanks

mcassaniti commented 5 years ago

Can you try using ansible-ssh-user instead of username? If it works correctly then that's great, but it's a bug at that rate.

odg0318 commented 5 years ago

@mcassaniti I tried using ansible-ssh-user but it doesn't work. But when I removed default ssh user in job setting, it woks well. Thanks.

mcassaniti commented 5 years ago

I'm going to re-open this as it is a bug. What should happen in the following order is:

  1. If SSH username is specified directly then use it
  2. If ansible-ssh-user is specified against the node then use it
  3. If username is specified against the node then use it

I don't believe that last case is being met. It seems to be a problem (partially) in PropertyResolver.java. Might need to add an alias somehow.

odg0318 commented 5 years ago

@mcassaniti I have a question of setting ssh username via ansible.

I want to change ansible-ssh-user when I execute a job.

I checked the following code. https://github.com/Batix/rundeck-ansible-plugin/blob/v2.1.3/src/main/java/com/batix/rundeck/core/AnsibleRunnerBuilder.java#L263 getSshUser() returns ssh username from a job config. To do that, I should set ansible-ssh-user, AnsibleDescribable.ANSIBLE_SSH_USER in code, when I execute a job. But I don't know how to set and pass ansible-ssh-user to a job via the following rundeck API. https://rundeck.org/docs/api/#running-a-job Parameters available to set belong to options. No parameter is found to pass ansible-ssh-user.

In codes, it seems available to set ansible-ssh-user when a job is executed.