Skip to content

Instantly share code, notes, and snippets.

@aduzsardi
Created August 8, 2022 05:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aduzsardi/71fb28c903c0ec899850491b4b6ea8e6 to your computer and use it in GitHub Desktop.
Save aduzsardi/71fb28c903c0ec899850491b4b6ea8e6 to your computer and use it in GitHub Desktop.
Ansible filter plugin example
#!/usr/bin/env python3
from passlib.totp import TOTP
from ansible.module_utils._text import to_text
class FilterModule(object):
def filters(self):
return {
'totpcode': self.totpcode
}
def totpcode(self, var):
totp = TOTP(key=var)
code = totp.generate().token
return to_text(code)
# tasks:
# - debug:
# msg: "{{ 'BASE32_KEY_HERE' | totpcode }}"
#
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment