The "synchronize" module does not work in Ansible - ansible

Worked on another machine with Ansible 2.9.27. It is installed on a new machine ansible [core 2.12.2].I assume that the problem is the difference in versions.
[root#localhost ansible]# ansible-playbook test.yml
ERROR! couldn't resolve module/action 'synchronize'. This often indicates a misspelling, missing collection, or incorrect module path.
The error appears to be in '/root/ansible/test.yml': line 4, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
tasks:
- name: Start copy scripts
^ here
Playbook contents.
---
- hosts: gate_test
tasks:
- name: Start copy scripts
synchronize:
src: ~/ansible/build/base_ca
dest: ~/
mode: push
The task of the playbook, transferring a directory with contents from a local machine to a virtual one

Related

Ansible collection not detected when running playbook on AWX

I use modules from the collection netapp.ontap in my ansible playbook which works perfectly fine when run using ansible-playbook command.
However, when run from AWX, it fails to detect the collection and immediately throws an errors that it cannot detect the ansible module/collection.
I even tried to re-install the collection from the playbook itself but with no luck.
The ansible collection is confirmed to be installed as it already works fine when run outside AWX.
The host is running ansible 2.10.4.
Here is my playbook:
---
- hosts: all
gather_facts: yes
collections:
- netapp.ontap
tasks:
- name: Install Netapp Collection from Ansible Galaxy
shell: ansible-galaxy collection install netapp.ontap
- name: Run Task
import_tasks: tasks/hil.yml
Task:
- name: 'Gather SVMs'
netapp.ontap.na_ontap_info:
state: info
hostname: "{{ netapp_hostname }}"
username: "{{ netapp_username }}"
password: "{{ netapp_hv_password }}"
gather_subset:
- vserver_info
Error from AWX:
SSH password:
Vault password:
ERROR! couldn't resolve module/action 'netapp.ontap.na_ontap_info'. This often indicates a misspelling, missing collection, or incorrect module path.
The error appears to be in '/tmp/awx_421_gey54bdw/project/tasks/hil.yml': line 6, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: 'Gather SVMs'
^ here
This one looks easy to fix. It seems that there is a value started
with a quote, and the YAML parser is expecting to see the line ended
with the same kind of quote. For instance:
when: "ok" in result.stdout
Could be written as:
when: '"ok" in result.stdout'
Or equivalently:
when: "'ok' in result.stdout"
Update:
I created a collections/requirements.yml file, with the below details but now AWX fails the task itself.
collections/requirements.yml
collections:
name: https://github.com/ansible-collections/netapp.git
type: git
Error:
"/var/lib/awx/venv/awx/lib/python3.6/site-packages/awx/main/tasks.py",
line 1279, in run self.pre_run_hook(self.instance, private_data_dir) File
"/var/lib/awx/venv/awx/lib/python3.6/site-packages/awx/main/tasks.py",
line 1862, in pre_run_hook sync_task.run(local_project_sync.id) File
"/var/lib/awx/venv/awx/lib/python3.6/site-packages/awx/main/tasks.py",
line 698, in _wrapped return f(self, *args, **kwargs) File
"/var/lib/awx/venv/awx/lib/python3.6/site-packages/awx/main/tasks.py",
line 1444, in run raise AwxTaskError.TaskError(self.instance, rc)
Exception: project_update 435 (failed) encountered an error (rc=2), please
see task stdout for details.

Issue getting running config back up from Nexus switch in Ansible

I am trying to take running config back up from two nexus switches, what am I missing from below
configuration?
- name: copy nexus switch running configurations
hosts: nxos-devices
gather_facts: no
ignore_errors: yes
tasks:
- name: timestamp
local_action: command date +%Y%m%d
register: timestamp
- name: get running configuration from nexus switch
nxos_config: running_config
register: running_config
- copy:
content: "{{ running_config.stdout[0] }}"
dest: ".config/{{ item.hostname }}_{{ timestamp.stdout }}.txt"
with_items:
- { hostname: bur1-mrt1 }
- { hostname: bur1-mrt2 }
Getting below error
[root#ansible-net-001 bkrishna]# ansible-playbook -i hosts running-config.yml
[DEPRECATION WARNING]: The TRANSFORM_INVALID_GROUP_CHARS settings is set to allow bad characters in group names by default, this will change, but
still be user configurable on deprecation. This feature will be removed in version 2.10. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
ERROR! this task 'nxos_config' has extra params, which is only allowed in the following modules: shell, win_shell, include_vars, add_host, raw, include_role, meta, set_fact, include, import_tasks, script, import_role, include_tasks, group_by, command, win_command
The error appears to be in '/root/ansible/bkrishna/running-config.yml': line 12, column 7, but may be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: get running configuration from nexus switch
^ here

Running an ansible playbook on localhost but referring to inventory's group_var

I am trying to run a playbook locally but I want all the vars in the role's task/main.yml file to refer to a group_var in a specific inventory file.
Unfortunately the playbook is unable to access to the group_vars directory as if fail to recognize the vars specified in the role.
The command ran is the following:
/usr/local/bin/ansible-playbook --connection=local /opt/ansible/playbooks/create.yml -i ./inventory-file
but fails to find the group_vars in the /group_vars directory at the same directory level of the inventory file
fatal: [127.0.0.1]: FAILED! => {
"msg": "The task includes an option with an undefined variable. The error was: 'admin_user_name' is undefined\n\nThe error appears to have been in '/opt/roles/create/tasks/main.yml': line 2, 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: create org\n ^ here\n"
}
This is my configuration:
ansible-playbook 2.7.5
config file = /etc/ansible/ansible.cfg
configured module search path = ['/opt/ansible-modules']
ansible python module location = /usr/local/lib/python3.6/dist-packages/ansible
executable location = /usr/local/bin/ansible-playbook
python version = 3.6.3 (default, Oct 3 2017, 21:45:48) [GCC 7.2.0]
Any help is appreciated.
Thanks,
dom
So, theoretically adding localhost in the inventory would have been a good solution, but in my specific case (and in general for large deployments) was not an option.
I also added --extra-vars "myvar.json" but did not work either.
Turns out (evil detail...) that the right way to add a var file via command line is: --extra-vars "#myvar.json"
Posting it here in hope nobody else struggle days to find this solution.
Cheers,
dom
As per the error, your ansible is not able to read the group_vars, Can you please make sure that your group_vars have the same folder called localhost.
Example Playbook
host is localhost
- hosts: localhost
become: true
roles:
- { role: common, tags: [ 'common' ] }
- { role: docker, tags: [ 'docker' ] }
So in group_vars, it should be localhost and in that folder file in main.yml
Or
You can create a folder called all in group_vars and create a file called all.yml
This should solve the issue

Unable to run get_url module with ansible playbook

I have started to learn Ansible watching online vids . But got stuck at the first step when creating and running a simple playbook.
When I run below playbook as below ->
$ ansible-playbook download.yml
Then output displayed is ->
ERROR! Syntax Error while loading YAML.
mapping values are not allowed in this context
The error appears to have been in '/etc/ansible/download.yml': line 3, column 11, but may
be elsewhere in the file depending on the exact syntax problem. The offending line appears to be:
-name: Test
get_url:
^ here
Below are the contents of my playbook download.yml ->
tasks:
-name: Test
get_url:
url: https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/ec2.ini
dest: /home/sunny/ec2.ini
mode: 700
What am I doing wrong here ?
Space behind the dash in name is missing. Instead of
-name: Test
the correct syntax is
- name: Test

Host not found error while executing copy module

Ansible version :1.9.4, 1.9.3, 1.9.1,
Using ec2, so specifying pem key in ansible.cfg
I have used Ansible for while, but this error is strange.
Copy module works fine when executing in ad-hoc like the snippet below. The below line is just an example.
Ansible instance123 -m copy - a "src= dest= mode ="
But gives "host not found" while executing the same module in playbook.
The playbook:
---
- hosts: all
sudo: yes
tasks:
- name: copy
copy: src=./ansible.cfg dest=/home/ubuntu/ mode=0644
I checked command module both in playbooks and trying it in ad-hoc also. That works fine. I found that version 1.8.2 had this error, and I tried all state versions of 1.9.
The culprit was a var named inventory_hostname. So this was the var that was conflicting.

Resources