Error running playbook with encrypted group_vars - ansible

I am trying to run a playbook with a file that has been encrypted using ansible-vault. However, I get the following error:
ERROR! Syntax Error while loading YAML.
could not find expected ':'
The error appears to have been in 'inventories/group_vars/main_server': line 41, column 1, but may
be elsewhere in the file depending on the exact syntax problem.
Content of vault file:
me#server:ansible$ cat inventories/group_vars/main_server
$ANSIBLE_VAULT;1.1;AES256
...
Command I'm running:
ansible-playbook -i inventories/group_vars/main_server --extra-vars "target=my_target" playbook.yml --ask-become-pass --ask-pass --vault-password-file vault_pwd.txt
vault_pwd.txt is populated with the required password. I have been encrypting/decrypting as I develop my playbook. For instance, the shell script with the encrypting command:
ansible-vault encrypt inventories/group_vars/main_server --vault-password-file vault_pwd.txt
Edit #1
Version of Ansible:
me#server:ansible$ ansible --version
ansible 2.7.5
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/me/.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
python version = 2.7.12 (default, Nov 12 2018, 14:36:49) [GCC 5.4.0 20160609]

The error you're seeing...
ERROR! Syntax Error while loading YAML.
could not find expected ':'
The error appears to have been in 'inventories/group_vars/main_server': line 41, column 1, but may
be elsewhere in the file depending on the exact syntax problem.
...is a YAML syntax error. Ansible is probably complaining about an actual syntax error in the unencrypted content (and if you're lucky, the line referenced in the error message is in fact the one with the error).

Related

How run the Volttron playbook install-platform.yml with Ansible

First I install the Volttron recipes via
ansible-galaxy install git+https://github.com/volttron/volttron-ansible.git
Then Verify the install
ansible-galaxy list
# /Users/username/.ansible/roles
- volttron-ansible, (unknown version)
Then I setup the host and try to run the playbook
ansible-playbook -K \
-i $TEST_HOST \
playbooks/install-platform.yml
# TEST_HOST is the path the to host file
And I get the error:
ERROR! the role 'volttron.deployment.set_defaults' was not found in /Users/username/Development/iot/experiment-volttron/playbooks/roles:/Users/username/.ansible/roles/volttron-ansible:/Users/username/Development/iot/experiment-volttron/playbooks
The error appears to be in '/Users/username/Development/iot/experiment-volttron/playbooks/install-platform.yml': line 6, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
roles:
- volttron.deployment.set_defaults
^ here
The Host connects correctly - and the roles seemed to be installed at /Users/username/.ansible/roles/volttron-ansible correctly.
Any suggestions?

Ansible AWX on K3s - Galaxy install problem "Failed to download collection tar from 'server0': <urlopen error [Errno -2] Name or service not known"

I have a problem with the Ansible AWX instance on K3s.
Used guide: https://computingforgeeks.com/how-to-install-ansible-awx-on-ubuntu-linux/
I want to use the Ansible collections install option when syncing my project to git but that doesn't work.
I am using collections/requirements.yml file which during execution expects on a random collection (I want to install 7 collections from)
My collections:
community.general
community.mysql
community.docker
ansible.posix
community.vmware
community.zabbix
awx.awx
Error with job details (Standard Error):
ERROR! Failed to download collection tar from 'server0': <urlopen error [Errno -2] Name or service not known>
Error with manual installation in a container with -vvv and -c flags
bash-4.4$ ansible-galaxy collection install -r requirements.yml --collections-path /var/lib/awx/projects/.__awx_cache/_15__gitlab_ansible_awx_devops/stage/requirements_collections -vvv -c
ansible-galaxy [core 2.12.5.post0]
config file = None
configured module search path = ['/home/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.8/site-packages/ansible
ansible collection location = /home/runner/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible-galaxy
python version = 3.8.12 (default, Sep 21 2021, 00:10:52) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]
jinja version = 2.10.3
libyaml = True
No config file found; using defaults
Reading requirement file at '/var/lib/awx/projects/_15__gitlab_ansible_awx_devops/collections/requirements.yml'
Starting galaxy collection install process
Process install dependency map
Opened /home/runner/.ansible/galaxy_token
[WARNING]: Skipping Galaxy server https://galaxy.ansible.com/api/. Got an unexpected error when getting available versions of collection community.general: Unknown
error when attempting to call Galaxy at 'https://galaxy.ansible.com/api/v2/collections/community/general/': <urlopen error [Errno 101] Network is unreachable>
ERROR! Unknown error when attempting to call Galaxy at 'https://galaxy.ansible.com/api/v2/collections/community/general/': <urlopen error [Errno 101] Network is unreachable>
It alternates between getting the error with "Network is unreachable" and "Name or service not known". Local installation goes without any problem.
Thanks for any help
Info:
Ubuntu 20.04
ansible [core 2.12.5.post0]
AWX 21.1.0
k3s version v1.23.6+k3s1 (418c3fa8)

Ansible cannot pickle 'module' object

Running the playbook with
$ ansible-playbook test-playbook.yml
Getting error response
ERROR! Unexpected Exception, this is probably a bug: cannot pickle 'module' object
Also have tried shell: "echo text", same error.
Ansible version 2.9, Python 3.8, running on Macos.
test-playbook.yml:
---
- name: run on localhost
hosts: localhost
gather_facts: false
connection: local
tasks:
- name: some name
debug:
msg: "some text"
...
Full output:
$ ansible-playbook test-playbook.yml
[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'
PLAY [run on localhost] *************************************************************************************
TASK [some name] ********************************************************************************************
ERROR! Unexpected Exception, this is probably a bug: cannot pickle 'module' object
to see the full traceback, use -vvv
Verbose output is not helpful:
$ ansible-playbook test-playbook.yml -vvv
ansible-playbook 2.9.0
config file = None
configured module search path = ['/Users/jprusakova/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/ansible
executable location = /Library/Frameworks/Python.framework/Versions/3.8/bin/ansible-playbook
python version = 3.8.0 (v3.8.0:fa919fdf25, Oct 14 2019, 10:23:27) [Clang 6.0 (clang-600.0.57)]
No config file found; using defaults
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
yaml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
ini declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
toml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
[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'
PLAYBOOK: test-playbook.yml *********************************************************************************
1 plays in test-playbook.yml
PLAY [run on localhost] *************************************************************************************
META: ran handlers
TASK [some name] ********************************************************************************************
task path: /Users/jprusakova/ViaControl/temp-ansible/test-playbook.yml:9
ERROR! Unexpected Exception, this is probably a bug: cannot pickle 'module' object
the full traceback was:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/bin/ansible-playbook", line 123, in <module>
exit_code = cli.run()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/ansible/cli/playbook.py", line 127, in run
results = pbex.run()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/ansible/executor/playbook_executor.py", line 169, in run
result = self._tqm.run(play=play)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/ansible/executor/task_queue_manager.py", line 240, in run
play_return = strategy.run(iterator, play_context)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/ansible/plugins/strategy/linear.py", line 310, in run
self._queue_task(host, task, task_vars, play_context)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/ansible/plugins/strategy/__init__.py", line 343, in _queue_task
worker_prc.start()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/ansible/executor/process/worker.py", line 96, in start
return super(WorkerProcess, self).start()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/process.py", line 121, in start
self._popen = self._Popen(self)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/context.py", line 224, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/context.py", line 283, in _Popen
return Popen(process_obj)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/popen_spawn_posix.py", line 32, in __init__
super().__init__(process_obj)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/popen_fork.py", line 19, in __init__
self._launch(process_obj)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/popen_spawn_posix.py", line 47, in _launch
reduction.dump(process_obj, fp)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/reduction.py", line 60, in dump
ForkingPickler(file, protocol).dump(obj)
TypeError: cannot pickle 'module' object
Ansible version
$ ansible --version
ansible 2.9.0
config file = None
configured module search path = [...]
ansible python module location = /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/ansible
executable location = /Library/Frameworks/Python.framework/Versions/3.8/bin/ansible
python version = 3.8.0 (v3.8.0:fa919fdf25, Oct 14 2019, 10:23:27) [Clang 6.0 (clang-600.0.57)]
I had the same issue today, my install details:
$ ansible --version
ansible 2.9.0
config file = None
configured module search path = ['/Users/mark/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /Users/mark/.pyvenv/ansible/lib/python3.9/site-packages/ansible
executable location = /Users/mark/.pyvenv/ansible/bin/ansible
python version = 3.9.6 (default, Jun 29 2021, 05:25:02) [Clang 12.0.5 (clang-1205.0.22.9)]
$ ansible app -m ping
ERROR! Unexpected Exception, this is probably a bug: cannot pickle 'module' object
to see the full traceback, use -vvv
I was unable to resolve with Python3, but using a virtual environment for Python2 it did work:
$ ansible --version
/Users/mark/.pyenv/py2ansible/lib/python2.7/site-packages/ansible/parsing/vault/__init__.py:41: CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in the next release.
from cryptography.exceptions import InvalidSignature
ansible 2.9.0
config file = None
configured module search path = [u'/Users/mark/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /Users/mark/.pyenv/py2ansible/lib/python2.7/site-packages/ansible
executable location = /Users/mark/.pyenv/py2ansible/bin/ansible
python version = 2.7.16 (default, May 8 2021, 11:48:02) [GCC Apple LLVM 12.0.5 (clang-1205.0.19.59.6) [+internal-os, ptrauth-isa=deploy
$ ansible app -m ping
/Users/mark/.pyenv/py2ansible/lib/python2.7/site-packages/ansible/parsing/vault/__init__.py:41: CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in the next release.
from cryptography.exceptions import InvalidSignature
m1-base | SUCCESS => {
"changed": false,
"ping": "pong"
}
Maybe not ideal, but at least I can carry on. If you did manage to solve, please post your solution
To create the virtual env on MacBookPro:
pip install virtualenv
python -m virtualenv ~/.pyenv/py2ansible
source ~/.pyenv/py2ansible/bin/activate
I had the same issue on Mac (Python 3.10.4)
I was able to resolve it by installing ansible v 2.9.8
ansible 2.9.8
config file = None
configured module search path = ['/Users/smanciot/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/ansible
executable location = /Library/Frameworks/Python.framework/Versions/3.10/bin/ansible
python version = 3.10.4 (v3.10.4:9d38120e33, Mar 23 2022, 17:29:05) [Clang 13.0.0 (clang-1300.0.29.30)]
UPDATE: Using the latest version of Ansible in my venv fixed the problem (replacing ansible==2.9 with ansible in requirements.txt)
$ ansible all -vvv -a 'uptime' -i hosts.yaml
ansible [core 2.12.1]
config file = None
configured module search path = ['/Users/jsherman/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /Users/jsherman/Desktop/Code/ansible-plays/ansible-env/lib/python3.9/site-packages/ansible
ansible collection location = /Users/jsherman/.ansible/collections:/usr/share/ansible/collections
executable location = /Users/jsherman/Desktop/Code/ansible-plays/ansible-env/bin/ansible
python version = 3.9.9 (main, Nov 21 2021, 03:22:47) [Clang 12.0.0 (clang-1200.0.32.29)]
jinja version = 3.0.3
libyaml = True
I'm seeing the same issue, also on macOS. I was able to reproduce the issue using python 3.9.9 and 3.10.1 (both from Homebrew), and the OS-installed python3 binary (3.8.2)
Using python2 on macOS fixes it for me, as does using python3 on Ubuntu instead.
I'm wondering if there's something wrong with python3 on macOS specifically that's causing this

What does this "ansible -m ping all" mean?

ansible -m ping all
Why am I getting the same warnings and Errors when I tried running my Playbook? (starfish.yml)
So, that means: My Playbook is Right? But something important is Not. What is that?
Please Help...Thank You.
With Hope,
Prabhakaran
The following are the Warnings and Errors:
/usr/lib/python2.7/site-packages/ansible/parsing/vault/__init_.py:44: CyptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in a future release.
from cryptography.exceptions import InvalidSignature
[WARNING]: * Failed to parse /etc/ansible/hosts with yaml plugin: We were unable to read either as JSON nor YAML, these are the errors we got from each: JSON: No JSON object could be decoded Syntax Error while loading YAML. expected '<document start>', but found '[' The error appears to be in '/etc/ansible/hosts': line 4, column 1, but may be elsewhere in the file depending on the exact syntax problem. The offending line appears to be: ] [starfish] ^ here
[WARNING]: * Failed to parse /etc/ansible/hosts with ini plugin: need more than 2 values to upack
[WARNING]: Unable to parse /etc/ansible/hosts 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'
I think you need to follow this doc https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html to build your ansible inventory.

Ansible: error when deploying playbooks in parallel

i am setting up a kubernetes cluster with ansible.
This is running fine.
Now i usually have 2 or 3 clusters i can test different things with.
Often it happens at some point in time that the cluster/server gots broken. If that happens, i usually recreate the servers and start the playbook again. because this takes some time, i want to be able to run 2 or more playbooks in parallel.
But every time i do this, i get the following error:
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: FileNotFoundError: [Errno 2] No such file or directory
I run my playbook like this:
"$ansible_playbook"
-i "${ANSIBLE_HOSTS}"
"${ANSIBLE_YML}"
--flush-cache
--user root
--become
--become-user root
--ask-sudo-pass
What could be the reason for the error?
I can imagine, that ansible creates some files in the background, used by the different playbooks. But which files could that be?
thx in advance!
Update more detailed error log (-vvv)
ansible-playbook 2.7.8
config file = /home/mod/cod/wo/thingylabs/kubernetes-provisioning/playbooks/test1/ansible.cfg
configured module search path = ['/home/mod/cod/wo/thingylabs/kubernetes-provisioning/vendors/kubespray/library']
ansible python module location = /usr/lib/python3.7/site-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 3.7.2 (default, Jan 10 2019, 23:51:51) [GCC 8.2.1 20181127]
Using /home/mod/cod/wo/thingylabs/kubernetes-provisioning/playbooks/test1/ansible.cfg as config file
SUDO password:
ERROR! Unexpected Exception, this is probably a bug: [Errno 2] No such file or directory
the full traceback was:
Traceback (most recent call last):
File "/usr/bin/ansible-playbook",
exit_code = cli.run()
File "/usr/lib/python3.7/site-packages/ansible/cli/playbook.py", line 104, in run
loader, inventory, variable_manager = self._play_prereqs(self.options)
File "/usr/lib/python3.7/site-packages/ansible/cli/__init__.py", line 786, in _play_prereqs
inventory = InventoryManager(loader=loader, sources=options.inventory)
File "/usr/lib/python3.7/site-packages/ansible/inventory/manager.py", line 148, in __init__
self.parse_sources(cache=True)
File "/usr/lib/python3.7/site-packages/ansible/inventory/manager.py", line 207, in parse_sources
source = unfrackpath(source, follow=False)
File "/usr/lib/python3.7/site-packages/ansible/utils/path.py", line 47, in unfrackpath
basedir = op.getcwd()
FileNotFoundError: [Errno 2] No such file or directory

Resources