rundeck ansible module - No matched nodes - ansible

system: centos 6.8 x86_64 , ansible-2.1 , rundeck-2.6.8
Batix/rundeck-ansible-plugin v1.3.0
rundeck runs on the same ansible controller host, and i just want to run the playbooks from rundeck interface.
su rundeck -c "ansible all -m ping" , works well, but when i try to run playbooks from rundeck there's an error:
Execution failed: 10: No matched nodes: MultiNodeSelector{nodenames=[localhost]}
in the jobs the node selection is "Execute locally", on the second option "Dispatch to Nodes" there's no hosts on the list. the hosts specified in the ansible playbooks, so i don't raelly need to specify it to rundeck, am i missing something here? rundeck should run the playbooks on the same host, and the ansible will deploy to the remote systems.
Thanks,
Nir.

Rundeck keeps its own internal inventory of the hosts, separate from Ansible. The plugin gives you a Resource Model Source to have Rundeck use your Ansible inventory to scan for nodes and populate the Rundeck inventory. You then configure your Rundeck job against the Rundeck inventory.
The plugin uses the defaults, so if you store your inventory in a different place than /etc/ansible/hosts on the Rundeck system, you will need to pass that as a parameter to the Resource Model Source like so:
Another solution would be to create a Rundeck job that merely acts as a wrapper for calling ansible or ansible-playbook and put that as a workflow step:
cd <your ansible dir>
. env/bin/activate # we use virtualenv
export ANSIBLE_CONFIG=/var/lib/rundeck/.ansible.cfg
ansible-playbook -i inventory -l "$RD_OPTION_LIMIT" $RD_OPTION_ANSIBLE_OPTS playbooks/$RD_OPTION_PLAYBOOK
Something like this wouldn't require the rundeck-ansible-plugin as you can configure the Rundeck job options to suit your Ansible argument needs.

Related

What is Ansible equivalent to Salt's top file?

I'm trying to merge from Salt to Ansible.
What is Ansible equivalent to Salt's top file?
In Ansible you build inventory, put your hosts into groups and then you run playbooks, that will bring your hosts to the desired state (e.g. ensure that software is installed, files are present, etc) on those groups. Note that there is no agent software with Ansible, it uses SSH to do things on remote hosts,

Running Ansible setup module without an ansible.cfg

I want to run the ansible setup module, by declaring a specific host.
I am using Windows 10 machine , with windows subsystem for linux where ansible is installed.
I can run the setup module when using localhost, ie:
ansible localhost -m setup
I can run it when using the ansible.cfg file I use from one virtual environment, against a virtual machine ie:
ansible TestVm -m setup
In another virtual environment i have installed ansible without setting up an ansible.cfg file, and my hosts.yml file is in the windows (not the WSL filesystem).
No matter which directory i switch, I cannot run the setup module using for instance:
ansible -i inventory -m setup
.
Is there a way to run setup without a configuration file and if yes what part of the call am i missing?
Try this:
ansible all -i inventory -m setup
Where the inventory is a directory with at least the hosts.yml file.
And this an example of hosts.yml
all:
hosts:
192.168.2.9:
192.168.2.3:
192.168.2.4:
Also before any of these you must have added pywinrm:
pip install pywinrm

adding remote N number of hosts to AWX

Installed Ansible AWX on CentOS 7 without docker. Want to add remote linux hosts(without password) to AWX and run play books and get the results. How to do it? Can any one help. One or two hosts I can add it in web page. How to add 100 remote hosts to AWX. Is there any AWX back end scripting is there to add N number of remote hosts to AWX? Thanks.
Create inventory file in git. Add it to projects in AWX. Create inventory with source as inventory project in AWX.
Your ssh keys will have to be stored in awx credentials.
Create inventory with credentials via web interface.
Sign in hosts with AWX via ssh.
ssh user#hostname
Sign in container awx_tasks
docker exec -it awx_task sh
Create or copy file with hosts ip/hostname
# cat hosts.ini
10.0.0.1
10.0.0.2
#
Add multiple hosts from file to inventory
awx-manage inventory_import \
--inventory-name my-inventory \
--source hosts.ini
Worked in my case, AWX 17.0.1

Is it possible to call ansible or ansible-playbook directly on a target host using a script or ansible itself?

I need to know if it's possible to call / execute ansible playbooks from the target machine. I think i saw a vendor do it or at least something similar. they downloaded a script and it did ran the playbook.
if this is possible how would it be done?
my goal is to run ansible as a centralized server in aws to perform tasks in mulitple environments. most are behind firewalls, any reccomendations/thoughts would be appreciated.
Sure. If your host will install Ansible on target and feed it with all the playbooks the you can run it as any other executable. Should you do that is another story but technically there's no obstacle.
You can run ansible and ansible playbook as you would any other binary on the target's $PATH, so any tool that facilitates running remote commands would work.
Because you are in AWS, one way might be to use AWS System's Manager.
If you wanted to use Ansible itself to do this you could use the shell or command modules:
- hosts: target
become: false
gather_facts: false
tasks:
- name: ansible in ansible
command: ansible --version
- name: ansible-playbook in ansible
command: ansible-playbook --version
Though, as with any situation where you reach for the shell or command modules, you have to be vigilant to maintain playbook idempotency yourself.
If you're requirement is just the ability to execute Ansible commands remotely, you might look into AWX which is the upstream project for Red Hat's Ansible Tower. It wraps ansible in a nice user interface to allow you to trigger Ansible playbooks remotely and with nice-to-haves like RBAC.
If you're ok with executing tasks remotely over ssh take a look at Sparrowdo it has out of the box facilities to run bash scripts ( read ansible executable ) remotely from one master host to another. Or you can even use it to install all the ansible dependencies or whatever you need to do for your scope.

How to apply proxy and DNS settings to GNU/Linux Debian using configuration management tool such as Ansible

I'm new to configuration management tool.
I want to use Ansible.
I'd like to set proxy to several GNU/Linux Debian (in fact several Raspbian).
I'd like to append
export http_proxy=http://cache.domain.com:3128
to /home/pi/.bashrc
I also want to append
Acquire::http::Proxy "http://cache.domain.com:3128";
to /etc/apt.conf
I want to set DNS to IP X1.X2.X3.X4 creating a
/etc/resol.conf file with
nameserver X1.X2.X3.X4
What playbook file should I write ? How should I apply this playbook to my servers ?
Start by learning a bit about Ansible basics and familiarize yourself with playbooks. Basically you ensure you can SSH in to your Raspian machines (using keys) and that the user Ansible invokes on these machines can run sudo. (That's the hard bit.)
The easy bit is creating the playbook for the tasks at hand, and there are plenty of pointers to example playbooks in the documentation.
If you really want to add a line to a file or two, use the lineinfile module, although I strongly recommend you create templates for the files you want to push to your machines and use those with the template module. (lineinfile can get quite messy.)
I second jpmens. This is a very basic problem in Ansible, and a very good way to get started using the docs, tutorials and example playbooks.
However, if you're stuck or in a hurry, you can solve this like this (everything takes place on the "ansible master") :
Create a roles structure like this :
cd your_playbooks_directory
mkdir -p roles/pi/{templates,tasks,vars}
Now create roles/pi/tasks/main.yml :
- name: Adds resolv.conf
template: src=resolv.conf.j2 dest=/etc/resolv.conf mode=0644
- name: Adds proxy env setting to pi user
lineinfile: dest=~pi/.bashrc regexp="^export http_proxy" insertafter=EOF line="export http_proxy={{ http_proxy }}"
Then roles/pi/templates/resolv.conf.j2 :
nameserver {{ dns_server }}
then roles/pi/vars/main.yml :
dns_server: 8.8.8.8
http_proxy: http://cache.domain.com:3128
Now make a top-level playbook to apply roles, at your playbook root, and call it site.yml :
- hosts : raspberries
roles:
- { role: pi }
You can apply your playbook using :
ansible-playbook site.yml
assuming your machines are in the raspberries group.
Good luck.

Resources