Created
August 8, 2022 05:06
-
-
Save aduzsardi/71fb28c903c0ec899850491b4b6ea8e6 to your computer and use it in GitHub Desktop.
Ansible filter plugin example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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