Ansible is not picking up installed hvac module after installing on mac OS - ansible

My ansible play uses hashivault_read. I installed this module on my mac. When I try to execute the playbook, this task errors out saying No module named hvac. When I see pip list I can find this module on my mac.
Did anyone face this issue before on mac? If someone has a resolution to this please comment.
Ansible Properties
ansible-playbook 2.8.0
config file = /Users/mdhoke/ansible.cfg
configured module search path = [u'/Users/mdhoke/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /Library/Python/2.7/site-packages/ansible
executable location = /usr/local/bin/ansible-playbook
python version = 2.7.10 (default, Feb 22 2019, 21:55:15) [GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)]
I assume ansible is trying to find hvac module under /Library/Python/2.7/site-packages/ansible which is not present but hashivault_read is present.
hvac module is present under /Library/Python/2.7/site-packages.
Error I am getting:
fatal: [vault]: FAILED! => {"changed": false, "module_stderr": "Shared connection to vault closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n File \"/home/mdhoke/.ansible/tmp/ansible-tmp-1567120470.9-210430890667193/AnsiballZ_hashivault_read.py\", line 114, in <module>\r\n _ansiballz_main()\r\n File \"/home/mdhoke/.ansible/tmp/ansible-tmp-1567120470.9-210430890667193/AnsiballZ_hashivault_read.py\", line 106, in _ansiballz_main\r\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n File \"/home/mdhoke/.ansible/tmp/ansible-tmp-1567120470.9-210430890667193/AnsiballZ_hashivault_read.py\", line 49, in invoke_module\r\n imp.load_module('__main__', mod, module, MOD_DESC)\r\n File \"/tmp/ansible_hashivault_read_payload_kE0iQk/__main__.py\", line 3, in <module>\r\n File \"/tmp/ansible_hashivault_read_payload_kE0iQk/ansible_hashivault_read_payload.zip/ansible/module_utils/hashivault.py\", line 4, in <module>\r\n
ImportError: No module named hvac\r\n",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

I managed to solve this issue for myself yesterday. I assume you are running ansible locally from your mac and connecting to the remote server (vault). If so, you will need to install hvac on the vault server too.
the following code snippet will suffice
- name: install hvac pip package
become: yes
become_method: sudo
pip:
name: hvac
state: present
obviously for the above play to work, you will need python-pip installed on the vault server too and in order to install that, you will need to enable epel-release. The below coe will take care of those dependencies.
- name: enable epel-relase and install pip
become: yes
become_method: sudo
yum:
name: "{{ item }}"
state: present
with_items:
- epel-release
- python-pip

Actually hashivault_read module is expected to be executed on a local machine. So delegating it to local machine solved my issue.

Related

Cythonized package cannot be installed due to incompatible platform

I have built a cythonized package on Ubuntu 20.04.
The Python version I used to build is 3.7.1, and cython is of version 0.29.30.
The generated package is with name bbbox-2.0.6-cp37-cp37m-manylinux_2_31_x86_64.whl. I manage to install this package on other servers with Ubuntu 20.04 installed.
However when I tried installing the same package on Debian GNU/Linux 9 (stretch), I got the following error
using pip 22.2 from /venvs/dztradeio_pre/lib/python3.7/site-packages/pip (python 3.7)
Non-user install because user site-packages disabled
Created temporary directory: /tmp/pip-ephem-wheel-cache-tu_4hz24
Created temporary directory: /tmp/pip-build-tracker-q85jg79w
Initialized build tracking at /tmp/pip-build-tracker-q85jg79w
Created build tracker: /tmp/pip-build-tracker-q85jg79w
Entered build tracker: /tmp/pip-build-tracker-q85jg79w
Created temporary directory: /tmp/pip-install-7_4efkhe
ERROR:bbbox-2.0.6-cp37-cp37m-manylinux_2_31_x86_64.whl is not a supported wheel on this platform.
Exception information:
Traceback (most recent call last):
File "/venvs/dztradeio_pre/lib/python3.7/site-packages/pip/_internal/cli/base_command.py", line 167, in exc_logging_wrapper
status = run_func(*args)
File "/venvs/dztradeio_pre/lib/python3.7/site-packages/pip/_internal/cli/req_command.py", line 247, in wrapper
return func(self, options, args)
File "/venvs/dztradeio_pre/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 370, in run
reqs, check_supported_wheels=not options.target_dir
File "/venvs/dztradeio_pre/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 73, in resolve
collected = self.factory.collect_root_requirements(root_reqs)
File "/venvs/dztradeio_pre/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 493, in collect_root_requirements
requested_extras=(),
File "/venvs/dztradeio_pre/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 452, in _make_requirement_from_install_req
self._fail_if_link_is_unsupported_wheel(ireq.link)
File "/venvs/dztradeio_pre/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 138, in _fail_if_link_is_unsupported_wheel
raise UnsupportedWheel(msg)
pip._internal.exceptions.UnsupportedWheel:bbbox-2.0.6-cp37-cp37m-manylinux_2_31_x86_64.whl is not a supported wheel on this platform.
Remote version of pip: 22.2
Local version of pip: 22.2
Was pip installed by pip? True
Removed build tracker: '/tmp/pip-build-tracker-q85jg79w'
How can this be resolved?

Ansible script - error with pexpect module

I am writing ansible script to install universal forwarder but stuck using pexpect module.
Error I am getting:
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named 'pexpect'
fatal: [Server-a]: FAILED! => {"changed": false, "msg": "Failed to import the required Python library (pexpect) on **** Python /usr/bin/python3. Please read the module documentation and install it in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter"}
I tried many workarounds like passing python interpreter in the command line while running ansible script.
Tried with both python versions 2.7 and 3.
I also see that pexpect is installed: pexpect-2.3-py2.7.egg-info
Since the pexpect Python module is needed on the nodes in a version greater or equal to 3.3 and that there is a pip module to install python dependancies, what you could do is to write the pip task needed to upgrade your nodes dependancies to the right version on pexpect.
Something like:
- pip:
name: pexpect>=3.3
- name: This is just an expect demo
expect:
command: read -p 'What is the answer to life, the universe and everything?'
responses:
(?i)answer: 42
Those two would then yield:
TASK [pip] *******************************************************************
changed: [localhost]
TASK [This is just an expect demo] *******************************************
changed: [localhost]

Fast idempotent Ansible apt deb url

It looks like like command apt install https://github.com/jgraph/drawio-desktop/releases/download/v12.9.3/draw.io-amd64-12.9.3.deb could take long time each time when is invoked even if the package is installed already. It is literally downloads the package each time.
And yes, with ansible is idempotent, with status changed: no.
- name: Install a drawio-desktop .deb package
apt:
deb: https://github.com/jgraph/drawio-desktop/releases/download/v12.9.3/draw.io-amd64-12.9.3.deb
when: ansible_facts['lsb']['id'] == "Ubuntu"
tags:
- debug
- not-macos
Is there any short way to skip download if package installed ?
Ideally will be to say in name that I want to install draw.io if not installed from deb: url else consider things installed.
- name: Install a drawio-desktop .deb package
apt:
name: draw.io
deb: https://github.com/jgraph/drawio-desktop/releases/download/v12.9.3/draw.io-amd64-12.9.3.deb
but is not working like that
TASK [desktop : Install a drawio-desktop .deb package] *********
fatal: [tuxedo]: FAILED! => {"changed": false, "msg": "parameters are mutually exclusive: deb|package|upgrade"}
Any suggestion on a lighter solution to speed up the task?
The behavior seems to be intended according the parameter deb
Ansible will attempt to download deb before installing.
and the current source of apt.py.
So you may have a look into the module package_facts
- name: Gather Package Facts
package_facts:
manager: apt # default ["auto"]
as well a Conditional Example of
when: "ansible_facts['lsb']['id'] == 'Ubuntu' and 'draw.io' not in ansible_facts.packages"
Credits to
How to get the installed apt packages with Ansible?
Further Q&A
Ansible: Do task if apt package is missing
An other approach might be to have the latest package always internally (cached) available and provide a .list file for the native package manager, pointing to the internal repository URL (file share).
By doing this, you could then just use
- name: Install a drawio-desktop .deb package
apt:
name: draw.io
state: latest
without further checks. This will address required updates too.

Can't run Ansible Playbook on M1 Mac

When I run ansible-playbook command I get the following error:
ERROR! unexpected parameter type in action: <class 'bool'>
The error appears to be in '/Users/mycomputer/.ansible/roles/wtanaka.jq/tasks/compat_sudo.yml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
---
- name: install python-apt on ansible < 1.6.0 and ubuntu et al
^ here
I took a look at that playbook, and I'm not seeing anything that sticks out at me:
---
- name: install python-apt on ansible < 1.6.0 and ubuntu et al
sudo: yes
Ansible Version:
ansible 2.10.7
config file = /Users/mycomputer/Tools/xeno-ansible/ansible.cfg
configured module search path = ['/Users/mycomputer/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /opt/homebrew/Cellar/ansible/3.1.0/libexec/lib/python3.9/site-packages/ansible
executable location = /opt/homebrew/bin/ansible
python version = 3.9.2 (default, Mar 26 2021, 15:28:17) [Clang 12.0.0 (clang-1200.0.32.29)]
Would this be an issue with Ansible and my M1 Mac or is there something in the playbook that is wrong?
In my case, the issue was that I was using an old playbook that isn't compatible with Ansible 2.9+. I had to install ansible using Rosetta2, similar to this.

error creating a new ec2 volume with ansible

I am using ansible 2.1.0. When I try to use ec2_vol to create a new volume, the error I get is 'Volume' object has not attribute 'encrypted'. The trace is:
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_QgknUu/ansible_module_ec2_vol.py", line 593, in <module>
main()
File "/tmp/ansible_QgknUu/ansible_module_ec2_vol.py", line 583, in main
volume_info = get_volume_info(volume, state)
File "/tmp/ansible_QgknUu/ansible_module_ec2_vol.py", line 454, in get_volume_info
'encrypted': volume.encrypted,
AttributeError: 'Volume' object has no attribute 'encrypted'
Has anyone else seen this?
My issue was related to the fact that my version of python boto was not compatible with the ansible version I was using. Using apt-get in Ubuntu install version 2.20, and I think I need at least 2.30. So I used pip to install boto
pip install boto
An everything is fine now.

Resources