How to perform bitwise operation inside ansible playbook

Hi,

I am looking to perform “bitwise OR” operation like below inside the Ansible playbook.

0x102030 or 0x908060

I understood from the internet that there is no direct way to do this. So, as sugegsted in this post (How to perform bitwise operations in Ansible?), I have created the .py file for “bitwise or” and placed under specific paths under filter dir.

1)The ansible “.cfg” file is edited to specify the filter plugin path.

filter_plugins = /usr/share/ansible/plugins/filter:~/.ansible/plugins/filter

2)Also I tried setting env variable “ANSIBLE_FILTER_PLUGINS” with the dir path of filter plugin.

3)Ansible version on controller node is: 3.6.10

But unfortunately I dont see the playbook is able to find the new defined filter. I am not sure if I am missing anything. Is there anything else i need to be done?

Is there a way i can do bitwise operation using simple way.

Any help with this is appreciate.

Thanks,

Reshma

have you tried using python bitwise operators (they should work in any
Jinja2 template)?

<<, >>, &, |, ~, and ^

Hi Brian,

I tried using ’ | ’ operator inside the jinja template , but it was not considered as "btwise or " operator, instead it is considered as pipe for filter operation that follows it.

The filter_plugin I tried is working now, there was a small coding issue inside the filetr.py file , which was reported by playbook run logs on the console, which i missed to look.

After carefully looking into the logs, i could fix the coding issue and after that filter operation was found from the filter_plugin path that was specified in the ansible.cfg file.

filter_plugins = /usr/share/ansible/plugins/filter

There was no more setting needed apart from specifying the filter path in ansible.cfg

Thanks,
Reshma