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

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.

Related

Any ideas why I am getting "yum" is not a valid attribute for a play? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 days ago.
This post was edited and submitted for review 9 days ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I have the following and when I do a syntax check just on this part it is saying that "yum" is not a valid attribute for the play:
---
# tasks files for ansible-vsftpd
- name: Packages are installed
yum:
name: "{{ vsftpd_package }}"
state: present
if I run a syntax check just on this part or at the end of the rest of the code, it keeps coming back that "yum" is not a valid attribute for play and is flagging line 3 of the code.
Any ideas?
The syntax error message
"<moduleName>" is not a valid attribute for the play
is because of there seems to be something missing for a valid playbook. In example the keywords hosts and tasks are missing.
---
- hosts: localhost
tasks:
- name: Packages are installed
yum:
name: "{{ vsftpd_package }}"
state: present
Documentation
Playbook syntax

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.

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

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

Set environment in Ansible doesn't seem to work

The Consul lookup plugin has the following code. I would like to override by setting the environment variable for ANSIBLE_CONSUL_URL. I can't seem to get my task to use the environment variable. The task runs fine if I set the environment variable manually prior to running the task.
self.agent_url = 'http://localhost:8500'
if os.getenv('ANSIBLE_CONSUL_URL') is not None:
self.agent_url = os.environ['ANSIBLE_CONSUL_URL']
My task:
- name: Build list of modules and its associated tag
environment:
ANSIBLE_CONSUL_URL: "http://indeploy001.local.domain:8500"
set_fact: deploy_list="{{ item | replace("deploys/" + environment_id + "/",'') }}-{{ lookup('consul_kv','deploys/' + environment_id + '/' + item) }}"
with_items: "{{ modules }}"
register: deploy_list_result
Error
TASK: [Build list of modules and its associated tag] **************************
fatal: [127.0.0.1] => Failed to template deploy_list="{{ item | replace("deploys/" + environment_id + "/",'') }}-{{ lookup('consul_kv','deploys/' + environment_id + '/' + item) }}": Error locating 'deploys/sf/ariaserver' in kv store. Error was HTTPConnectionPool(host='localhost', port=8500): Max retries exceeded with url: /v1/kv/deploys/sf/ariaserver (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x1eac410>: Failed to establish a new connection: [Errno 111] Connection refused',))
FATAL: all hosts have already failed -- aborting
Lookups are a templating feature. The keys of a task are rendered to resolve any Jinja expressions before the task is executed. That means your lookup is executed before the task is executed. The environment key simply is a task property, which has an effect when the task is executed. But you're not getting that far.
Also, I'm not 100% sure what would happen with your environment in this special case used in a set_fact task. set_fact is an action plugin, running on the control machine. So do lookups. But the task itself is not delegated to localhost. So it's possible the env var would be set for the control machine or on the remote machine. My guess though is, it is not set at all, neither on localhost nor remotely. The reason for my guess is, many action plugins do later in the process call a module with the same name, which then is executed on the target host. The logical behavior, and what a user would expect, would be that the env var then is set on the remote host by the module. Just a guess and neglectable given the first paragraph.
Conclusion:
If a lookup plugin is depending on environment variables, you can not set them in the same task. They need to be set previously - what you already found working.

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