Rundeck - problem with running commands/jobs with nodes defined in resource-yaml file - ansible

[SOLVED - answer in comments]
I am looking for a help. Maybe someone had this problem already or just have a idea what is going on and can advise? Much appreciated!
In Rundeck I've defined project with Ansible (via ansible plugin) set as a executor.
Within a project I've two resource models:
Ansible Resource Model Source (with Satellite set as dynamic inventory - all works as expected)
resourceyaml (which is not working)
Configuration for both resources is listed at the end of this post.
As said, I am struggling with nodes defined in yaml resource model -
node is visible in Nodes section, but whenever I am trying to execute a command or job against it, error is being throwed:
[WARNING]: Could not match supplied host pattern, ignoring: template
ERROR! Specified hosts and/or --limit does not match any hosts
Failed: AnsibleError: ERROR: Ansible execution returned with non zero code.
Execution failed: 116 in project Linux-Ansible: [Workflow result: , step failures: {1=Dispatch failed on 1 nodes: [template: AnsibleError: ERROR: Ansible execution returned with non zero code. + {dataContext=MultiDataContextImpl(map={}, base=null)} ]}, Node failures: {template=[AnsibleError: ERROR: Ansible execution returned with non zero code. + {dataContext=MultiDataContextImpl(map={}, base=null)} ]}, status: failed]
When I am executing ansible via cli with resourceyaml file set as inventory, I can see these warnings:
ansible -i /etc/ansible/hosts-rundeck-static.yml all --limit node001#domain.com -m shell -a id
[WARNING]: Skipping key (username) in group (template) as it is not a mapping, it is a <class 'ansible.parsing.yaml.objects.AnsibleUnicode'>
[WARNING]: Skipping key (description) in group (template) as it is not a mapping, it is a <class
'ansible.parsing.yaml.objects.AnsibleUnicode'>
[WARNING]: Skipping key (tags) in group (template) as it is not a mapping, it is a <class 'ansible.parsing.yaml.objects.AnsibleUnicode'>
[WARNING]: Skipping key (hostname) in group (template) as it is not a mapping, it is a <class 'ansible.parsing.yaml.objects.AnsibleUnicode'>
[WARNING]: Skipping key (ssh-keypath) in group (template) as it is not a mapping, it is a <class
'ansible.parsing.yaml.objects.AnsibleUnicode'>
[WARNING]: Skipping key (nodename) in group (template) as it is not a mapping, it is a <class 'ansible.parsing.yaml.objects.AnsibleUnicode'>
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
[WARNING]: Could not match supplied host pattern, ignoring: node001#domain.com
Conf. for resource models:
YAML:
Format: resourceyaml
File Path:/etc/ansible/hosts-rundeck-static.yml
Writeable: yes
Content of hosts-rundeck-static.yml:
---
template:
nodename: node001#domain.com
hostname: 1.2.3.4
username: admin#domain.com
ssh-keypath: keys/ssh_key/key1
description: this is a template node
tags: template
Ansible inventory:
ansible inventory File path:/etc/ansible/foreman.yml
Ansible config file path:/etc/ansible
Gather Facts: yes
Ignore Host Discovery Errors: yes
SSH Authentication: privateKey
SSH User:admin#domain.com
SSH Key File path:/rundeck/id_ecdsa
Privilege escalation method.: sudo
Ansible conf:
[defaults]
strategy_plugins = /opt/mitogen/ansible_mitogen/plugins/strategy
collections_paths = /etc/ansible/collections
inventory = /etc/ansible/foreman.yml
timeout = 30
[inventory]
enable_plugins = host_list, yaml, script, ini, foreman
[privilege_escalation]
[paramiko_connection]
[ssh_connection]
pipelining = True
[persistent_connection]
[accelerate]
[selinux]
[colors]
[diff]
Rundeck version: 3.3.6-20201111, with Ansible plugin version: 3.1.1
Can anyone help me with that? Thank you!

For the record answer: following this guide and defining correctly the ansible.cfg / inventory path on the Node Executor section (with filename at the end) solves this issue.

Related

How to pass multiple run time variables in ansible AWX?

My ansible playbook accepts two run-time variables
run_on_host
section
I want to pass multiple hosts to above variables. I can do this on jenkins pipeline by looping and feeding the data:
example:
hosts = [ "Server1", "Server2", "Server3" ] for(host in hosts) {
ansiblePlaybook inventory: '/etc/ansible/inventory_test', extras: "-e 'configFile=/nps/data/ansible/config_test.ini hosts=$host
section=$host' -playbook: '/nps/data/ansible/commonscripts/test.yml'
I want to do similar on AWX and I have tried passing variables in my job template as:
run_on_host:
- Server1
- Server2
section:
- Server1
- Server2
but the section variable is combined and passed into the playbook which fails.
Error:
An unhandled exception occurred while templating '{{ lookup('ini', 'TOMCATS section={{ section }} file={{ configFile }}').split(',') }}'. Error was a <class 'ansible.errors.AnsibleError'>, original message: An unhandled exception occurred while running the lookup plugin 'ini'. Error was a <class 'configparser.NoSectionError'>, original message: No section: \"['Server1', 'Server2 ']\""}
How can I achieve a loop-like logic similar to Jenkins for ansible AWX?
Thanks for the help.

Getting error while checking hosts IP via Ansible Server machine

I'm getting an error prompt while checking the node's IP in hosts/inventory from my server machines, all nodes are connected.
Error Prompt:
[WARNING]: Unable to parse /etc/ansible/hosts #poll_interval = 15 as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
[WARNING]: Could not match supplied host pattern, ignoring: demo
SSH connections are already established with my nodes and can access from the server machine as well
Also, in the hosts file inside the ansible server a group is created with the node's private IPs:
# Ex 1: Ungrouped hosts, specify before any group headers.
[demo]
172.31.31.15
172.31.31.128
Also, inside the ansible server config file:
inventory = /etc/ansible/hosts
sudo_user = root
Both these are uncommented as well. I'm learning ansible and new with this configuration tool.
Please help as I'm unable to fetch details of nodes with the above-said command not by group which I created as demo.

Ansible Collections: How to use Google Cloud Compute Engine inventory source

What are the correct commands for using the inventory file along with a playbook when using Ansible Collections google.cloud.gcp_compute. You can find an example of the inventory file very similar to what I'm using at the bottom of this article this article
I'm using this update.yml playbook:
- name: Update apt-get repo and cache
apt: update_cache=yes force_apt_get=yes cache_valid_time=3600
This is my inventory-gcp_compute.yml inventory file:
plugin: google.cloud.gcp_compute
zones: # populate inventory with instances in these regions
- us-central1-a
projects:
- vpn-server-sasp
auth_kind: serviceaccount
scopes:
- 'https://www.googleapis.com/auth/cloud-platform'
- 'https://www.googleapis.com/auth/compute.readonly'
keyed_groups:
# Create groups from GCE labels
- prefix: gcp
key: labels
hostnames:
# List host by name instead of the default public ip
- name
compose:
# Set an inventory parameter to use the Public IP address to connect to the host
# For Private ip use "networkInterfaces[0].networkIP"
ansible_host: networkInterfaces[0].accessConfigs[0].natIP
I've tried these commands:
ansible-playbook -i inventory-gcp_compute.yml update.yml
I got this error:
ansible-playbook 2.9.14
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/cheo/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.17 (default, Jul 20 2020, 15:37:01) [GCC 7.5.0]
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /home/cheo/sergio/ansible-gce/inventory-gcp_compute.yml as it did not pass its verify_file() method
virtualbox declined parsing /home/cheo/sergio/ansible-gce/inventory-gcp_compute.yml as it did not pass its verify_file() method
[WARNING]: * Failed to parse /home/cheo/sergio/ansible-gce/inventory-gcp_compute.yml with yaml plugin: Plugin configuration YAML file, not YAML inventory
File "/usr/lib/python2.7/dist-packages/ansible/inventory/manager.py", line 280, in parse_source
plugin.parse(self._inventory, self._loader, source, cache=cache)
File "/usr/lib/python2.7/dist-packages/ansible/plugins/inventory/yaml.py", line 112, in parse
raise AnsibleParserError('Plugin configuration YAML file, not YAML inventory')
[WARNING]: * Failed to parse /home/cheo/sergio/ansible-gce/inventory-gcp_compute.yml with constructed plugin: Incorrect plugin name in file: google.cloud.gcp_compute
File "/usr/lib/python2.7/dist-packages/ansible/inventory/manager.py", line 280, in parse_source
plugin.parse(self._inventory, self._loader, source, cache=cache)
File "/usr/lib/python2.7/dist-packages/ansible/plugins/inventory/constructed.py", line 109, in parse
self._read_config_data(path)
File "/usr/lib/python2.7/dist-packages/ansible/plugins/inventory/__init__.py", line 224, in _read_config_data
raise AnsibleParserError("Incorrect plugin name in file: %s" % config.get('plugin', 'none found'))
[WARNING]: Unable to parse /home/cheo/sergio/ansible-gce/inventory-gcp_compute.yml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
ERROR! 'apt' is not a valid attribute for a Play
The error appears to be in '/home/cheo/sergio/ansible-gce/update.yml': line 3, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Update apt-get repo and cache
^ here
Check the docs. It's looking for a file ending in .gcp_compute.yml or .gcp.yml, so while inventory.gcp_compute.yml would qualify, inventory-gcp_compute.yml does not. The errors you're getting says that that file isn't an inventory, but none of the plugin parsers claimed it.

Ansible playbook error while running on - hosts:

write a task in main.yml to stop and start service in service "ssh" using service module in ansible.
---
- hosts: localhost
become: true
become_method: sudo
tasks:
- name: stop service
service:
name: ssh
state: stopped
- name: start service
service:
name: ssh
state: started
when run it's giving below error
[WARNING]: Unable to parse /projects/challenge/localhost as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that
the implicit localhost does not match 'all'
ERROR! unexpected parameter type in action: <class 'ansible.parsing.yaml.objects.AnsibleSequence'>
The error appears to be in '/projects/challenge/fresco_module/tasks/main.yml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be
---
- hosts: localhost
^ here
Firstly, you should be able to do SSH to localhost.
You can try,
ssh user#localhost date
You can create a hosts file and name it hosts and add the following content to it.
[localhost]
localhost
[localhost:vars]
ansible_ssh_user=user
ansible_ssh_pass=pass
ansible_sudo_pass=sudopass
And run the playbook as
ansible-playbook -i hosts main.yml
Using command module was able to stop and start the service, using sudo service ssh stop and sudo service ssh start served my purpose.
was not able to do so with service module, still don't know about that
Resolved at my end by using complete path for .yml file
ansible-playbook -i /etc/ansible/hosts myfirstplaybook.yml

How to fix "Could not match supplied host pattern, ignoring: bigip" errors, works in Ansible, NOT Tower

I am running Ansible Tower v3.4.1 with Ansible v2.7.6 on an ubuntu 16.04 VM running on VirtualBox. I run a playbook that works when I run it from the command line using "ansible-playbook" but fails when I try to run it from Ansible Tower. I know I must have something misconfigured in ansible tower but I can't find it.
I get this warning no matter what changes I make to the inventory (hosts) file.
$ ansible-playbook 2.7.6
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/var/lib/awx/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.12 (default, Nov 12 2018, 14:36:49) [GCC 5.4.0 20160609]
Using /etc/ansible/ansible.cfg as config file
SSH password:
**/tmp/awx_74_z6yJB4/tmpVlXGCX did not meet host_list requirements**, check plugin documentation if this is unexpected
Parsed /tmp/awx_74_z6yJB4/tmpVlXGCX inventory source with script plugin
PLAYBOOK: addpool.yaml *********************************************************
1 plays in addpool.yaml
[WARNING]: **Could not match supplied host pattern, ignoring: bigip**
PLAY [Sample pool playbook] ****************************************************
17:05:43
skipping: no hosts matched
I have enabled inventory plugins for YAML, and made my hosts file into a hosts.yml file.
Here's my hosts file:
192.168.68.253
192.168.68.254
192.168.1.165
[centos]
dad2 ansible_ssh_host=192.168.1.165
[bigip]
bigip1 ansible_host=192.168.68.254
bigip2 ansible_host=192.168.68.253
Here's my playbook:
---
- name: Sample pool playbook
hosts: bigip
connection: local
tasks:
- name: create web servers pool
bigip_pool:
name: web-servers2
lb_method: ratio-member
password: admin
user: admin
server: '{{inventory_hostname}}'
validate_certs: no
I replaced hosts: bigip with hosts: all and specified the inventory in Tower as bigip which contains only the two hosts I want to change. This seems to provide the output I am looking for.
For the ansible-playbook command line, I added --limit bigip and this seems to provide the output I am looking for.
So things appear to be working, I just don't know whether this is best practice use.
If you get the error below while running a playbook with the command
ansible-playbook -i test-project/inventory.txt playbook.yml
{"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 172.31.24.10 port 22: Connection timed out", "unreachable": true}
The solution is to add, in the file ansible.cfg:
[defaults]
inventory=/etc/ansible/hosts
I think you need to remove the connection: local.
You have specified in hosts: bigip that you want these tasks to only run on hosts in the bigip group. You then specify connection: local which causes the task to run on the controller node (i.e. localhost), rather than the nodes in the bigip group. Localhost is not a member of the bigip group, and so none of the tasks in the play will trigger.
Check for special characters in absolute path of hosts file or playbook. Incase if you directly copied the path from putty, try copy and paste it from notepad or any editor
For me the issue was the format of the /etc/ansible/hosts file. You should use the :children suffix in order to use groups of groups like this:
[dev1]
dev_1 ansible_ssh_host=192.168.1.55 ansible_connection=ssh ansible_ssh_user={{username}} ansible_ssh_pass={{password}}
[dev2]
dev_2 ansible_ssh_host=192.168.1.68 ansible_connection=ssh ansible_ssh_user={{username}} ansible_ssh_pass={{password}}
[devs:children]
dev1
dev2
Reference: here

Resources