rundeck-plugins / ansible-plugin

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

Rundeck does not understand the host defined in ansible inventory #147

Open davistran86 opened 7 years ago

davistran86 commented 7 years ago

Hi guys, Can you guys help me how to get rundeck to work with ansible ?

I have success added nodes to rundeck using ansible inventory file, but the job I created running a simple ping module (job with Ansible module), I only got this warning:

[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: Could not match supplied host pattern, ignoring: all
[WARNING]: provided hosts list is empty, only localhost is available
[WARNING]: Could not match supplied host pattern, ignoring: aavn-laptop25
[WARNING]: No hosts matched, nothing to do

As you can see rundeck knows my node (aavn-latop25) but ignore it.

DerekTBrown commented 7 years ago

Is "execute locally" selected in the job options? You need to set it to delegate to remote hosts.

davistran86 commented 7 years ago

Hi @DerekTBrown , if i choose "execute locally" I got errors:

01:39:16 | 192.168.92.130 |   | com.dtolabs.rundeck.core.NodesetEmptyException: No matched nodes: MultiNodeSelector{nodenames=[192.168.92.130]}
-- | -- | -- | --
01:39:16 |   |   | at com.dtolabs.rundeck.core.execution.workflow.NodeFirstWorkflowExecutor.validateNodeSet(NodeFirstWorkflowExecutor.java:418)
01:39:16 |   |   | at com.dtolabs.rundeck.core.execution.workflow.NodeFirstWorkflowExecutor.executeWorkflowImpl(NodeFirstWorkflowExecutor.java:90)
01:39:16 |   |   | at com.dtolabs.rundeck.core.execution.workflow.BaseWorkflowExecutor.executeWorkflow(BaseWorkflowExecutor.java:226)
01:39:16 |   |   | at com.dtolabs.rundeck.core.execution.WorkflowExecutionServiceThread.runWorkflow(WorkflowExecutionServiceThread.java:76)
01:39:16 |   |   | at com.dtolabs.rundeck.core.logging.LoggingManagerImpl$MyPluginLoggingManager.runWith(LoggingManagerImpl.java:120)
01:39:16 |   |   | at com.dtolabs.rundeck.core.execution.WorkflowExecutionServiceThread.run(WorkflowExecutionServiceThread.java:67)
01:39:16 |   |   | Exception: class com.dtolabs.rundeck.core.NodesetEmptyException: No matched nodes: MultiNodeSelector{nodenames=[192.168.92.130]}
01:39:16 |   |   | No matched nodes: MultiNodeSelector{nodenames=[192.168.92.130]}

192.168.92.130 is my rundeck server I thought I should choose "Dispatch to Nodes" and select the node that defined in ansible inventory ? because if choose "execute locally" so where should I put the hosts in ansible inventory ?

DerekTBrown commented 7 years ago

You are correct- it should be on "dispatch to nodes", but that is a common mistake which produces this output.

Can you post the configuration for the Ansible Inventory Resource in the project?

davistran86 commented 7 years ago

Hi @DerekTBrown , my inventory:

[laptop]
aavn-laptop25 ansible_host=192.168.10.10 ansible_user=xxx ansible_password=xxx

Is it correct ? rundeck can get host info from this inventory

DerekTBrown commented 7 years ago

That is your Ansible inventory, not the actual rundeck resource. In your Rundeck Project, go to settings, and find the configuration for your resource model. It needs to be set to the Ansible Inventory model, with a path to that inventory.

davistran86 commented 7 years ago

hi @DerekTBrown , yes, I already used Ansible Resource Model and put the path to my inventory file.

#Thu Sep 14 13:19:35 ICT 2017
#edit below
project.description=
project.disable.executions=false
project.disable.schedule=false
project.jobs.gui.groupExpandLevel=1
project.name=Ansible-Ping
project.nodeCache.delay=30
project.nodeCache.enabled=true
project.ssh-authentication=privateKey
project.ssh-keypath=/var/lib/rundeck/.ssh/id_rsa
resources.source.1.config.ansible-become=false
resources.source.1.config.ansible-gather-facts=false
resources.source.1.config.ansible-ignore-errors=true
resources.source.1.config.ansible-inventory=/rundeck-ansible/hosts
resources.source.1.config.ansible-ssh-auth-type=password
resources.source.1.type=com.batix.rundeck.plugins.AnsibleResourceModelSourceFactory
service.FileCopier.default.provider=stub
service.NodeExecutor.default.provider=stub
enricomingardo commented 7 years ago

try to add: -i /rundeck-ansible/hosts in the "Extra Ansible arguments"

FANGXIANGQUAN commented 7 years ago

set your rundeck resource.xml file ,eg: <node name="test" ,this “test” must in ansible host .

DerekTBrown commented 7 years ago

@davistran86 @mkeller0815 I haven't been able to replicate this issue.

I do however, have a thought- what are the file permissions of your ansible inventory?

mkeller0815 commented 7 years ago

File permissions are OK. In my case rundeck is running as user ansible while the inventory file is owned by this user. As soon as I create as symlink from my local hosts files in /home/ansible/ansible/hosts to /etc/ansible/hosts everything works just fine. So I think it would help if the ansible process that is forked by rundeck gets at least the basedirectory of the configured ansible-hosts file for this project as working directory. If there's a correct ansible.cfg in the directory pointing to the correct inventory file then ansible should use it.

But much simpler should be that the ansible process is invoked with the option "-i" and the path to the configured hosts file from the node source model.

DerekTBrown commented 7 years ago

@mkeller0815 you are describing the current behavior of the plugin:

https://github.com/Batix/rundeck-ansible-plugin/blob/master/src/main/java/com/batix/rundeck/core/AnsibleRunner.java#L352

Also, per the latest release, you can specify the location of a valid ansible.cfg, and it is passed by environment variable.

zswanson commented 6 years ago

A difficulty that I've encountered is that if rundeck + ansible can't currently access a node (for any reason) it just drops it from the nodelist, without any explanation in the front-end. In my case it turned out that the incorrect ssh key was being passed, and I had to investigate the rundeck service.log to figure that out. Some sort of alert in the project setup would be great.

chuegel commented 5 years ago

I have the same issue. Its difficult if you have an inventory per project. The workaround proposed by @enricomingardo worked though

sarath9985 commented 5 years ago

@DerekTBrown can you help me out RUNDECK how to add nodes using ansible resource model.

my inventory file like this: /etc/ansible/hosts: 172.31.x.x

Ansible Resource Model Source Project NODE SOURCES like this Below ansible inventory File path: /etc/ansible/hosts Ansible config file path: /etc/ansible/ansible.cfg Gather Facts: Yes Ignore Host Discovery Errors: Yes SSH Authentication: privateKey SSH User: ec2-user SSH Key File path: /var/lib/rundeck/.ssh/ Use become previlege escalation.: Yes Privilege escalation method.: sudo Privilege escalation user: ec2-user

my rudeck project.properties file:

Thu Feb 14 12:36:46 UTC 2019

project.jobs.gui.groupExpandLevel=1 project.ssh-authentication=privateKey resources.source.1.config.ansible-config-file-path=/etc/ansible/ansible.cfg service.FileCopier.default.provider=stub resources.source.1.config.ansible-ignore-errors=true project.nodeCache.delay=30 project.nodeCache.enabled=true resources.source.1.config.ansible-inventory=/etc/ansible/hosts project.disable.executions=false project.ssh-command-timeout=0 resources.source.1.config.ansible-ssh-auth-type=privateKey resources.source.1.config.ansible-become-method=sudo resources.source.1.config.ansible-gather-facts=true project.description=Rundeck with Ansible project.ssh-keypath=/var/lib/rundeck/.ssh/id_rsa service.NodeExecutor.default.provider=stub resources.source.1.config.ansible-ssh-keypath=/var/lib/rundeck/.ssh/ project.name=Monty resources.source.1.config.ansible-ssh-user=ec2-user project.disable.schedule=false resources.source.1.config.ansible-disable-limit=false resources.source.1.config.ansible-become-user=ec2-user project.ssh-connect-timeout=0 resources.source.1.type=com.batix.rundeck.plugins.AnsibleResourceModelSourceFactory project.nodeCache.firstLoadSynch=true project.label=Monty resources.source.1.config.ansible-become=true

sarath9985 commented 5 years ago

@DerekTBrown resources.source.1.config.ansible-ssh-keypath=/var/lib/rundeck/.ssh/id_rsa. rundck having sudo permissions also

marzdgzmn commented 4 years ago

I have the same issue. All nodes in my ansible inventory file were added to rundeck and and it's listed there under node page.The workaround proposed by @enricomingardo worked.

SecT0uch commented 4 years ago

I have the same issue. I'm using 2 projects using 2 distincts host files, saying /etc/ansible/hosts-1 and /etc/ansible/hosts-2.

I'm unable to find the "Extra Ansible arguments" from @enricomingardo.

EDIT: Just found it. It's under Edit Nodes, while editing the source. But still not working. (working using ansible command)

sudheesh272 commented 4 years ago

I was able to fix this issue by setting the inventory in ansible.cfg file. I believe the problem is, by default it ansible will be looking into /etc/ansible/hosts only. In my case Im using gcp dynamic inventory file for rundeck inventory and same dynamic inventory file I configured as ansible inventory in ansible.cfg file. [defaults] inventory = /var/lib/rundeck/projects/demo1/ansible/inventory/gce.gcp.yml

This fixed my problem. Now im able to select the nodes in rundeck and ansible is properly executing the commands in the selected nodes.