I have 2 playbooks that need to be run one ofter the other.
the first one preapare env (bring other playbook to localhost for example) and the second
use the preperation files and roles.
---
- name: PREP
import_playbook: prep.yml
- name: after
import_playbook: after.yml
I get a compilation error:
RROR! the role 'from_prep_role' was not found in ....
The error appears to be in '/root/dev/ansible-roles/after.yml': line 13, column 9, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- { role: from_prep_role}
^ here
How can I solve it?
the first playbook is bringing all the roles that the second use.
thanks
It seems that the "roles" path(s) configuration is missing, at least the path to "from_prep_role" role.
Check your applied "ansible.cfg" file for "roles_path" property, should be something like :
roles_path = ~/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/another/path/to/your/roles:/another/second/path/to/your/other/roles
Please note that having many Ansible config. files might lead to unwanted behaviour (Asnible chooses the 1st found and ignore the rest), for details see https://docs.ansible.com/ansible/latest/reference_appendices/config.html#the-configuration-file.
Related
I try to do a simple apt update on a remote system. My playbook looks like this
---
- hosts: all
become: true
tasks:
- name: update
ansible.builtin.apt:
update_cache: yes
When I run it I get the error
ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.
The error appears to have been in '/opt/LabOS/ansible/test_pb.yml': line 6, column 5, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
tasks:
- name: update
^ here
However if I remove the module path (ansible.builtin.) it runs just fine. According to the documentation both notations should work. What am I missing here?
My ansible-playbook version is 2.7.7
The (optional) full name of the module like ansible.builtin.apt is only available starting from ansible version 2.10.
Since, you are on an older version, it gives an error and you can use only the short name of the module, for example: apt
I am using below playbook to update specific element value in xml file and its throwing error. I have installed python-lxml module as well as ansible version 2.7.8
---
- name: Set element
xml:
path: /home/emsuser/appD_agent_master/machineagent/machine_agent/conf/controller-info.xml
xpath: /controller-info/application-name
value: "Vicom Enterprise blackout Manager"
...
responce:
ERROR! 'xml' is not a valid attribute for a Play
The error appears to have been in '/home/emsuser/playbooks/editMechineAgentConf.yml': line 2, column 4, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
---
- name: Set element
^ here
I am not sure where I am doing mistake. Please help me out . I am new to ansible.
Your code is not a playbook, it's a task file.
In a playbook, you have a tasks: section listing your tasks.
Take a look at the Playbooks intro documentation.
I want to use the archive module of ansible but it is unfortunately not working. I have the following version installed: ansible 2.3.0 (devel 2131eaba0c)
my playbook looks like this:
- archive: path="{{path_dir}}" dest="{{dest_dir}}/foo.zip" format=zip
The output looks like this:
"failed": true, "reason": "no action detected in task. This often indicates a misspelled module name, or incorrect module path.
The error appears to have been in '/prj/sndbox1/app/jenkins/jobs/release/workspace/tasks/build_rpclient.yml': line 125, column 3, but may be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- archive: path="{{path_dir}}" dest="{{dest_dir}}/foo.zip" format=zip
^ here
We could be wrong, but this one looks like it might be an issue with missing quotes. Always quote template expression brackets when they start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"
As far as I understood the doc, the extra modules are shipped within ansible, so I assume I don't need to separately install this module.
However, what am I doing wrong? Is there any configuration I need to change in order to tell ansible where to look for the extra modules?
Thanks in advance!
Edit: Included the the full log message
Edit 2:
I tried to put the archive.py directly into my working directory --> [library]/archive.py
Now I get the following error:
"failed": true, "msg": "Could not find imported module support code for archive. Looked for either get_exception or pycompat24"
I have the same use case here, I'm using Ansible version 2.2.0.0. Installed via brew on MacOS sierra.
I've managed to solve the issue by adding the following into my local ansible.cfg file.
On defautls section, you must change the library entry:
[defaults]
library = /usr/local/Cellar/ansible/2.2.0.0_2/libexec/lib/python2.7:library
If you have a different setup, check:
pip show ansible
/usr/share/ansible if you are on Linux machine.
So one thing we've encountered in our project is that we do not want to store our large files in our git repo for our ansible roles because it slows down cloning (and git limits files to 100 mb anyways).
What we've done is store our files in a separate internal location, where our files can sit statically and have no size restrictions. Our roles are written so that they first pull these static files to their local files folder and then continue like normal.
i.e.
roles/foo/tasks/main.yml
- name: Create role's files directory
file:
path: "{{roles_files_directory}}"
state: directory
- name: Copy static foo to local
get_url:
url: "{{foo_static_gz}}"
dest: "{{roles_files_directory}}/{{foo_gz}}"
#....Do rest of the tasks...
roles/foo/vars/main.yml
roles_files_directory: "/some/path/roles/foo/files"
foo_static_gz: "https://internal.foo.tar.gz"
foo_gz: "foo.tar.gz"
The main thing I don't find really sound is the hard coded path to the role's files directory. I preferably would like to dynamically look up the path when running ansible, but I haven't been able to find documentation on that. The issue can arise because different users may check roles to a different root paths. Does anyone know how to dynamically know the role path, or have some other pattern that solves the overall problem?
Edit:
I discovered there's actually a {{playbook_dir}} variable that would return "/some/path", which might be dynamic enough in this case. Still isn't safe against the situation where the role name might change, but that's a way rarer occurrence and can be handled through version control.
What about passing values from the command line?
---
- hosts: '{{ hosts }}'
remote_user: '{{ user }}'
tasks:
- ...
ansible-playbook release.yml --extra-vars "hosts=vipers user=starbuck"
http://docs.ansible.com/playbooks_variables.html#passing-variables-on-the-command-line
I just want to add another possible solution: you can try to add custom "facter".
Here is a link to official documentation: http://docs.ansible.com/setup_module.html
And I found this article that might be useful: http://serverascode.com/2015/01/27/ansible-custom-facts.html
I am using the zzet.rbenv role on my playbook. It has a files/default-gems file that it copies to the provisioned system.
I need my playbook to check for a myplaybook/files/default-gems and use it if it exists, using the zzet.rbenv/files/default-gems if otherwise.
How can I do that?
After some research and trial/error. I found out that Ansible is not capable of checking if files exist between roles. This is due to the way role dependencies (which roles themselves) will get expanded into the one requiring it, making it part of the playbook. There are no tasks that will let you differentiate my_role/files/my_file.txt from required_role/files/my_file.txt.
One approach to the problem (the one I found the easiest and cleanest) was to:
Add a variable to the my_role with the path to the file I want to use (overriding the default one)
Add a task (identical to the one that uses the default file) that checks if the above variable is defined and run the task using it
Example
required_role
# Existing task
- name: some task
copy: src=roles_file.txt dest=some/directory/file.txt
when: my_file_path is not defined
# My custom task
- name: my custom task (an alteration of the above task)
copy: src={{ my_file_path }} dest=/some/directory/file.txt
when: my_file_path is defined
my_role
#... existing code
my_file_path: "path/to/my/file"
As mentioned by Ramon de la Fuente: this solution was accepted into the zzet.rbenv repo :)