rundeck-plugins / ansible-plugin

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

Can't get nodes from ansible #28

Closed Gmyras closed 8 years ago

Gmyras commented 8 years ago

Hello, I'm getting a similar error like the other issues.

ERROR ExceptionCatchingResourceModelSource: [ResourceModelSource: 2.com.batix.rundeck.AnsibleResourceModelSourceFactory (Ansible Resource Model Source), project: test]
com.dtolabs.rundeck.core.resources.ResourceModelSourceException: Error reading facts.
...
Caused by: java.nio.file.NoSuchFileException: /tmp/rundeck/ansible-hosts1781236957158666307/data
        at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)
        at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
        at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
        at sun.nio.fs.UnixFileSystemProvider.newDirectoryStream(UnixFileSystemProvider.java:427)
        at java.nio.file.Files.newDirectoryStream(Files.java:457)
        at com.batix.rundeck.AnsibleResourceModelSource.getNodes(AnsibleResourceModelSource.java:71)
        ... 90 more

I'm in AWS and using dynamic list script.

Rundeck user can run ansible fine.

  su rundeck -s /bin/bash -c "ansible all -m ping"

Also I tried to use a single node hosts ansible file.

  test01    ansible_ssh_host=10.0.0.100

Same result.

What can I check more to get it working?

lonoi commented 8 years ago

Hello. Im getting same error. Plugin v.1.2.3, rundeck 2.6.7, Ubuntu 14.04 In rundeck logs I have this:

...
com.dtolabs.rundeck.core.resources.ResourceModelSourceException: Error reading facts.
...
Caused by: java.nio.file.NoSuchFileException: /tmp/rundeck/ansible-hosts8239116568217565068/data
...

I tried: su rundeck -s /bin/bash -c "ansible-playbook /tmp/rundeck/ansible-hosts8239116568217565068/gather-hosts.yml" Got this:

...
TASK [file] ********************************************************************
fatal: [hostname.mydomain.com]: FAILED! => {"failed": true, "msg": "'tmpdir' is undefined"}
...

Also no "data" directory in /tmp/rundeck/ansible-hosts8239116568217565068/ in /tmp/rundeck/ansible-hosts8239116568217565068/ I have that odd directory $HOME/.ansible/ in /tmp/rundeck/ansible-hosts8823821777267040669/

Then I tried: su rundeck -s /bin/bash -c "ansible-playbook /tmp/rundeck/ansible-hosts8823821777267040669/gather-hosts.yml -e 'tmpdir=/tmp/rundeck/ansible-hosts8239116568217565068/'" And everything went fine, "data" directory was created in /tmp/rundeck/ansible-hosts8239116568217565068/.

Please provide any help.

frozenice commented 8 years ago

Can you please try the new v1.2.4? See the README on how to enable debugging!

lunawesley9 commented 8 years ago

I am using 1.2.4, i have the same issue.

lunawesley9 commented 8 years ago

the error is:

TASK [setup] *******************************************************************
fatal: [host1]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh.", "unreachable": true}
fatal: [host2]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh.", "unreachable": true}
        to retry, use: --limit @gather-hosts.retry

PLAY RECAP *********************************************************************
host1           : ok=0    changed=0    unreachable=1    failed=0
host2           : ok=0    changed=0    unreachable=1    failed=0

but when running ansible all -m ping all host are reachable. is it because rundeck is using rundeck user to run instead of root? or because of SSH keys issue? i have no idea how to fix it.

frozenice commented 8 years ago

@lunawesley9 Ansible needs to run under the rundeck user, see the README and see if the su command there works, if not you need to fix the permissions.

Gmyras commented 8 years ago

I had this error:

UNREACHABLE! => {"changed": false, "msg": "Authentication or permission failure. In some cases, you may have been able to authenticate and did not have permissions on the remote directory. Consider changing the remote temp path in ansible.cfg to a path rooted in \"/tmp\". Failed command was: ( umask 77 && mkdir -p \"echo $HOME/.ansible/tmp/ansible-tmp-1465291130.42-184715713825092\" && echo ansible-tmp-1465291130.42-184715713825092=\"echo $HOME/.ansible/tmp/ansible-tmp-1465291130.42-184715713825092\" ), exited with result 1", "unreachable": true} UNREACHABLE! => {"changed": false, "msg": "Authentication or permission failure. In some cases, you may have been able to authenticate and did not have permissions on the remote directory. Consider changing the remote temp path in ansible.cfg to a path rooted in \"/tmp\". Failed command was: ( umask 77 && mkdir -p \"echo $HOME/.ansible/tmp/ansible-tmp-1465291130.42-184715713825092\" && echo ansible-tmp-1465291130.42-184715713825092=\"echo $HOME/.ansible/tmp/ansible-tmp-1465291130.42-184715713825092\" ), exited with result 1", "unreachable": true}

And had to change the remote tmp dir in ansible config

lunawesley9 commented 8 years ago

@frozenice the node list cannot be retrieved unless i run the rundeckd as root

do i need to fix any ssh keys anywhere?

frozenice commented 8 years ago

@lunawesley9 Well Ansible is started under the same user that rundeck runs under, so you need to make sure Ansible can actually run successfully under the rundeck user. The README I linked above has some hints and also a command to test if it works (su) and that gives you some error details if it doesn't.

lunawesley9 commented 8 years ago

@frozenice I checked that it is successful in CLI?

[rundeck@localhost playbook]$ ansible all -m ping -u root
host1 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
host2 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
[rundeck@localhost playbook]$ vim setup.yml
frozenice commented 8 years ago

@lunawesley9 Does it also work without the -u root option? This option doesn't get added automatically by the plugin and you'd need to add it as an extra argument to jobs etc., if needed.

What exactly isn't working in Rundeck? See the README on how to enable debug mode, this might give you more information.

lunawesley9 commented 8 years ago

@frozenice but the root is the user in the remote host? and the ansible palybooks actually is :

- name: Task1
  hosts: host1
  user: root
  gather_facts: no

so the script will need to run as root anyway?

frozenice commented 8 years ago

@lunawesley9 Please try whatever you do in Rundeck with debug mode enabled (see README of this plugin) and post the complete log.

lunawesley9 commented 8 years ago

@frozenice all logs actually shows node not found and even in the GUI it isn't listing out any nodes. which log will have the node loading logs?

all logs are like this mentioning no valid nodes:

17:13:10    localhost       com.dtolabs.rundeck.core.NodesetEmptyException: No matched nodes: NodeSet{includes={name=.*, dominant=false, }}
17:13:10                at com.dtolabs.rundeck.core.execution.workflow.NodeFirstWorkflowStrategy.validateNodeSet(NodeFirstWorkflowStrategy.java:350)
17:13:10                at com.dtolabs.rundeck.core.execution.workflow.NodeFirstWorkflowStrategy.executeWorkflowImpl(NodeFirstWorkflowStrategy.java:88)
17:13:10                at com.dtolabs.rundeck.core.execution.workflow.BaseWorkflowStrategy.executeWorkflow(BaseWorkflowStrategy.java:182)
17:13:10                at com.dtolabs.rundeck.core.execution.WorkflowExecutionServiceThread.run(WorkflowExecutionServiceThread.java:55)
17:13:10            Exception: class com.dtolabs.rundeck.core.NodesetEmptyException: No matched nodes: NodeSet{includes={name=.*, dominant=false, }}
17:13:10            No matched nodes: NodeSet{includes={name=.*, dominant=false, }}
frozenice commented 8 years ago

@lunawesley9 You need to set a Java system property as per https://github.com/Batix/rundeck-ansible-plugin/#debugging - you should then restart Rundeck, which should re-import your nodes. After this, there should be some stuff in service.log (depends on your installation method).

lunawesley9 commented 8 years ago

@frozenice

the ssh seems failed to authenticate but when i use rundeck user to ssh in in CLI it is ok .

PLAYBOOK: gather-hosts.yml *****************************************************
1 plays in gather-hosts.yml

PLAY [all] *********************************************************************

TASK [setup] *******************************************************************
<host1> ESTABLISH SSH CONNECTION FOR USER: None
<host1> SSH: ansible.cfg set ssh_args: (-o)(ControlMaster=auto)(-o)(ControlPersist=60s)
<host1> SSH: ansible_password/ansible_ssh_pass not set: (-o)(KbdInteractiveAuthentication=no)(-o)(PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey)(-o)(PasswordAuthentication=no)
<host1> SSH: ANSIBLE_TIMEOUT/timeout set: (-o)(ConnectTimeout=10)
<host1> SSH: PlayContext set ssh_common_args: ()
<host1> SSH: PlayContext set ssh_extra_args: ()
<host1> SSH: found only ControlPersist; added ControlPath: (-o)(ControlPath=/var/lib/rundeck/.ansible/cp/ansible-ssh-%h-%p-%r)
<host1> SSH: EXEC ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/var/lib/rundeck/.ansible/cp/ansible-ssh-%h-%p-%r host1 '/bin/sh -c '"'"'( umask 22 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1465382248.38-233275575587618 `" && echo "` echo $HOME/.ansible/tmp/ansible-tmp-1465382248.38-233275575587618 `" )'"'"''
frozenice commented 8 years ago

Huh, is that all log output? There's no error.

But it doesn't seem right, either. The user is "None" and there is no reference to a keyfile. Something is strange with your Ansible config. Maybe the rundeck user is missing some environment variables or something like that?

Can you please try su rundeck -s /bin/bash -c "ansible all -m ping" as root? Don't switch the user to rundeck and run ansible there, but use this command as root, please.

lunawesley9 commented 8 years ago

@frozenice actually the SSH command auth fails. why isn't the command

ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/var/lib/rundeck/.ansible/cp/ansible-ssh-%h-%p-%r host1 '/bin/sh -c '"'"'( umask 22 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1465382248.38-233275575587618 `" && echo "` echo $HOME/.ansible/tmp/ansible-tmp-1465382248.38-233275575587618 `" )'"'"''

root@host1 but only host1 as the ansible playbook should be running as root in root host according to the script?

lunawesley9 commented 8 years ago

@frozenice su rundeck -s /bin/bash -c "ansible all -m ping" this fails, as my ansible script should login to remote hosts as root?

lunawesley9 commented 8 years ago

@frozenice

update. I got that fixed. sorry about that in ansible.cfg

# default user to use for playbooks if user is not specified
# (/usr/bin/ansible will use current user as default)
remote_user = root

i didn't enable it before --- it was fresh installation

thanks for your help and pointing the issue to ansible.cfg!

frozenice commented 8 years ago

No problem, glad you got it working. :)

Closing this issue now. If anyone still has a problem, please open a new issue including the debug output.

oevcil commented 5 months ago

I would very much like to have this issue reopened. I don't think it should be necessary to provide new logs here. Since this bug is still in Rundeck and is not really well documented in the manuals.

To be honest, I think it is a design flaw of the Rundeck application or i am stupid. Maybe I am wrong here, but then you can correct me here. I'm still relatively new to Rundeck and the documentation is unfortunately very unclear about this problem or doesn't even mention it. This could at least be changed.

@frozenice

frozenice commented 5 months ago

@oevcil I can't help you, because I'm not maintaining this plugin anymore (see README), sorry.

oevcil commented 5 months ago

@frozenice oh i am sorry. But thank you for the reply!