Can anyone see what I am doing wrong in the ansible playbook? - ansible

Got the following odd error with ansible lint and I can't for the life of me figure out what we did wrong, it's probably something incredibly stupid but there you go.
ansible-lint -p disable-beats.yml
Couldn't parse task at disable-beats.yml:5 (conflicting action statements: systemd, __line__
The error appears to be in '<unicode string>': line 5, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
(could not open file to display line))
{ 'name': 'disable auditbeats',
'skipped_rules': [],
'systemd': { '__file__': 'disable-beats.yml',
'__line__': 7,
'enabled': False,
'name': 'auditbeat'}}
the following is the contents of the file checked with linter:
---
- hosts: linuxservers
tasks:
- name: disable auditbeats
systemd:
name: auditbeat
enabled: no

That's a known issue with ansible-lint; upgrading to a more recent version such as 5.0.12 will make that go away. If it doesn't for your case, you can either comment on that issue or open a regression at which time you should provide the versions you are using

Related

Ansible AWX returns error: template error while templating string: unable to locate collection community.general

I am working on a project using ansible AWX. In this project I have a check to see if all my microk8s pods are in the state running. Before I installed AWX I was testing all my plays on my linux vm. The following play worked fine on my linux vm but does not seem to work in ansible awx.
- name: Wait for pods to become running
hosts: host_company_01
tasks:
- name: wait for pod status
shell: kubectl get pods -o json
register: kubectl_get_pods
until: kubectl_get_pods.stdout|from_json|json_query('items[*].status.phase')|unique == ["Running"]
timeout: 600
AWX gives me the following respons
[WARNING]: an unexpected error occurred during Jinja2 environment setup: unable
to locate collection community.general
fatal: [host_company_01]: FAILED! => {"msg": "The conditional check 'kubectl_get_pods.stdout|from_json|json_query('items[*].status.phase')|unique == [\"Running\"]' failed. The error was: template error while templating string: unable to locate collection community.general. String: {% if kubectl_get_pods.stdout|from_json|json_query('items[*].status.phase')|unique == [\"Running\"] %} True {% else %} False {% endif %}"}
I have looked at the error message and tried different possible solutions but without any effect.
First thing I tried was looking for the community.general collections in the ansible galaxy collection list. After I saw that it was found I tried downloading it once again, but this time with sudo. The collection was installed. After running my workflow template, the error message popped up again.
Second thing was trying to use different Execution environments, I thought that this was not going to make any difference but tried it anyways since someone online fixed a similar issue by changed EE.
Last thing I tried was trying to find a way around this play by building a new play with different commands. Sadly I was not able to build an other play that did what the original one did.
Since I can not build a play that fits my needs I came back at the error message to try and fix it.

Ansible on SLES: zypper plugin not able to install PostgreSQL 14

I am trying my hand on Ansible after having a very nice training in it. Currently, my task is to create a playbook that sets up a PostgreSQL cluster (with Patroni and etcd).
However, while installing PostgreSQL should be a pretty easy task, doing it using the zypper plugin throws an error. First, the part of the playbook that should install PostgreSQL:
- name: Installation PostgreSQL 14 Latest ohne Recommendations
become: true
zypper:
disable_recommends: true
name:
postgresql14-server
postgresql14-contrib
postgresql14-devel
update_cache: true
when: ansible_host in pgservers
The error message given is this:
fatal: [goeccdb22l]: FAILED! => {"changed": false, "cmd": ["/usr/bin/zypper", "--quiet", "--non-interactive", "--xmlout", "install", "--type", "package", "--auto-agree-with-licenses", "--no-recommends", "--", "+postgresql14-server postgresql14-contrib postgresql14-devel"], "msg": "No provider of '+postgresql14-server postgresql14-contrib postgresql14-devel' found.", "rc": 104, "stderr": "", "stderr_lines": [], "stdout": "<?xml version='1.0'?>\n<stream>\n<message type=\"error\">No provider of &apos;+postgresql14-server postgresql14-contrib postgresql14-devel&apos; found.</message>\n</stream>\n", "stdout_lines": ["<?xml version='1.0'?>", "<stream>", "<message type=\"error\">No provider of &apos;+postgresql14-server postgresql14-contrib postgresql14-devel&apos; found.</message>", "</stream>"]}
Let's extract the error message:
"msg": "No provider of '+postgresql14-server postgresql14-contrib postgresql14-devel' found."
I tried to replicate the problem using the shell on the target server. However, running the command seems to be able to install the packages:
ansible#goeccdb22l:~> sudo /usr/bin/zypper install --type package --auto-agree-with-licenses --no-recommends -- +postgresql14-server postgresql14-contrib postgresql14-devel
Loading repository data...
Reading installed packages...
Resolving package dependencies...
The following 12 NEW packages are going to be installed:
libecpg6 libopenssl-1_1-devel libpq5 postgresql postgresql14 postgresql14-contrib postgresql14-devel postgresql14-server postgresql-contrib postgresql-devel postgresql-server zlib-devel
The following package needs additional customer contract to get support:
postgresql14
12 new packages to install.
Overall download size: 8.0 MiB. Already cached: 0 B. After the operation, additional 35.4 MiB will be used.
Continue? [y/n/v/...? shows all options] (y):
I've removed only the --quiet and --non-interactive options from the command, but kept all other given options.
The best idea I have is that the user/privilege escalation workings could be different from me logging in as the Ansible user to the target and just using sudo before the command.
Edit 1: I have developed an idea what the problem could be. As I mentioned above, when I tested the command, I removed two options: --quiet and --non-interactive. Testing the command with those two options gives the message:
The flag --quiet is not known.
However, using man zypper, I can clearly see that --quiet is a documented option:
-q, --quiet
Suppress normal output. Brief (esp. result notification) messages and error messages will still be printed, though. If used together with conflicting --verbose option, the --verbose option takes preference.
Now, my idea is that Ansible calls the command it documents in the return XML, but that because somehow --quiet is not understood it interprets that as nothing providing the requested package list. So that would leave two questions:
Why is --quiet not understood, yet documented? Is that a problem of SLES vs. OpenSuse?
How to work around that?
As the Ansible zypper module has no option to suppress the --quiet option I don't see any chance of working around it with parameters. The last option would be to split the zypper task into smaller shell tasks which I would like to avoid if possible.
So, with the help of a knowledgeable sysadmin I was able to diagnose the problem.
The list of packages documented above was not in fact a list. As I missed the dashes in front of the packages, Ansible accepted the packages with the newlines and everything as one package name and tried to install it.
The solution is to change the packages into a list of packages by prefixing them with dashes/minus signs.
The problem with --quiet was that it is a positional argument, and I used the wrong position when testing it.

I got this two errors while vagrant up on islandora-playbook repository, do you have any idea about the problem?

fatal: [default]: FAILED! => {"msg": "The conditional check 'motomo_sql_dump_create | changed' failed. The error was: No filter named 'changed' found.\n\nThe error appears to be in '/home/oem/islandora-playbook/roles/external/Islandora-Devops.matomo/tasks/console_install.yml': line 12, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name:\n ^ here\n"}
fatal: [default]: FAILED! => {"ansible_facts": {}, "ansible_included_var_files": [], "changed": false, "message": "Could not find or access 'Ubuntu-20.yml'\nSearched in:\n\t/home/oem/islandora-playbook/roles/external/geerlingguy.java/vars/Ubuntu-20.yml\n\t/home/oem/islandora-playbook/roles/external/geerlingguy.java/Ubuntu-20.yml\n\t/home/oem/islandora-playbook/roles/external/geerlingguy.java/tasks/vars/Ubuntu-20.yml\n\t/home/oem/islandora-playbook/roles/external/geerlingguy.java/tasks/Ubuntu-20.yml\n\t/home/oem/islandora-playbook/vars/Ubuntu-20.yml\n\t/home/oem/islandora-playbook/Ubuntu-20.yml on the Ansible Controller.\nIf you are using a module and expect the file to exist on the remote, see the remote_src option"}
Probably the wrong place to ask an Islandora question. The Slack channel is the fastest. Ideally I'd suggest to switch to the ISLE (dockerized) version instead of the Ansible version. I know that's not always possible, so this looks like a previously common issue to run into. If I remember correctly it's a Ansible Version issue. The Ansible deployment of Islandora was locked into a very specific version due in part to a lack of interest in that type of build process.
The 1st error relates to changes in Ansible. In your Ansible playbook (...console_install.yml) change motomo_sql_dump_create | changed to motomo_sql_dump_create is changed. I don't know about the 2nd error

vmware_guest_snapshot: ERROR! no action detected in task [duplicate]

This question already has answers here:
Why does Ansible show "ERROR! no action detected in task" error?
(6 answers)
Closed 5 years ago.
I've an issue with a really basic module which doesn't seem do work like it is supposed to work, I guess?
I actually copied the part out of the documentation.
My playbook looks like this:
---
- hosts: all
tasks:
- name: Create Snapshot
vmware_guest_snapshot:
hostname: vSphereIP
username: vSphereUsername
password: vSpherePassword
name: vmname
state: present
snapshot_name: aSnapshotName
description: aSnapshotDescription
I run this playbook from ansible tower and it throws "ERROR! no action detected in task". It seems like a syntax error for me but I literaly copied it over from the documentation and other modules are working with the same syntax.
So does anyone knows what I'm doing wrong?
The vmware_guest_snapshot module is available since version 2.3 of Ansible (which is not yet released).
If you are running any older version, the module name will not be recognised and Ansible will report the error no action detected in task.
Currently you need to be running Ansible from source (the devel branch) to run the vmware_guest_snapshot module.

Ansible copy fails

I was trying to copy a test file from a Linux control server to a Windows 7 client. my playbook is
- name: Test Copy from Linux to Windows
hosts: Windows
gather_facts: false
tasks:
- name: Copy
copy: src=/tmp/tmp.txt dest=C:\Ansible
And getting this error
failed: [10.8.0.4] => {"failed": true, "md5sum": "c9566265d534d0e3c666ea52daf96cc8", "parsed": false}
invalid output was: The argument 'C:\Users\me.HOMEPC\AppData\Local\Temp\ansible-tmp-1422383762.86-109261083693479\\copy.ps1' to the -File parameter does not exist. Provide the path to an existing '.ps1' file as an argument to the -File parameter.
FATAL: all hosts have already failed -- aborting
Any thoughts? How I can make this work?
There's a small bug in that fork version. Use https://gist.github.com/dmitrydigi/dc4843fca7e69bcca147 with the fix. If you use the mentioned version, then template will always report changed=true.
Looks like the copy module doesn't support for file copy function in Windows and atm, a win_copy module is in the dev phase.
However I have found this VERY useful module which is copy.ps1
https://gist.github.com/tkinz27/fd92ba9af0e0309614ee
And then things got working :-)
Important: You gotta upgrade your Windows (7) Powershell to Version 4.0

Resources