forked from roots/trellis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add reverse_www filter to fix www_redirect
- Loading branch information
Showing
5 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.vault_pass | ||
.vagrant | ||
vendor/roles | ||
*.py[co] |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Make coding more python3-ish | ||
from __future__ import (absolute_import, division, print_function) | ||
__metaclass__ = type | ||
|
||
import types | ||
|
||
from ansible import errors | ||
from ansible.compat.six import string_types | ||
|
||
def reverse_www(value): | ||
''' Add or remove www subdomain ''' | ||
|
||
# Check if value is a list and parse each item | ||
if isinstance(value, (list, tuple, types.GeneratorType)): | ||
values = [] | ||
for item in value: | ||
values.append(reverse_www(item)) | ||
return values | ||
|
||
# Add or remove www | ||
elif isinstance(value, string_types): | ||
if value.startswith('www.'): | ||
return value[4:] | ||
else: | ||
return 'www.{0}'.format(value) | ||
|
||
# Handle invalid input type | ||
else: | ||
raise errors.AnsibleFilterError('The reverse_www filter expects a string or list of strings, got ' + repr(value)) | ||
|
||
|
||
class FilterModule(object): | ||
''' Trellis jinja2 filters ''' | ||
|
||
def filters(self): | ||
return { | ||
'reverse_www': reverse_www, | ||
} |
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