Created
March 4, 2015 18:27
-
-
Save caljess599/074af0c879ad61050e65 to your computer and use it in GitHub Desktop.
Hash filter for ansible 1.8.x
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
# Hash filter for ansible 1.8.x | |
# Note: Ansible 1.9 includes this filter, but since there is no rpm | |
# for 1.9, this saves the trouble of upgrading by hand. | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
from ansible import errors | |
try: | |
import hashlib as hl | |
except ImportError: | |
hl = None | |
def get_hash(data, hashtype='sha1'): | |
if not hl: | |
raise errors.AnsibleError( | |
"hashlib must be installed to use the hash filer") | |
try: # see if hash is supported | |
h = hl.new(hashtype) | |
except: | |
return None | |
h.update(data) | |
return h.hexdigest() | |
class FilterModule (object): | |
def filters(self): | |
return {"hash": get_hash} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment