Skip to content

Commit

Permalink
Merge pull request #1103 from roots/ansible-2.8
Browse files Browse the repository at this point in the history
Ansible 2.8 support
  • Loading branch information
swalkinshaw committed Sep 13, 2019
2 parents 967658c + d4922a3 commit e4e70d5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,4 +1,5 @@
### HEAD
* Ansible 2.8.x support ([#1103](https://github.com/roots/trellis/pull/1103))
* Bump galaxy dependency versions ([#1105](https://github.com/roots/trellis/pull/1105))
* Fix issues with Vagrant ansible_local provisioner ([#1104](https://github.com/roots/trellis/pull/1104))
* Bump ansible requirement to 2.7.12([#1102](https://github.com/roots/trellis/pull/1102))
Expand Down
26 changes: 16 additions & 10 deletions lib/trellis/plugins/callback/vars.py
Expand Up @@ -22,7 +22,14 @@ class CallbackModule(CallbackBase):
CALLBACK_NAME = 'vars'

def __init__(self):
self._options = cli.options if cli else None
super(CallbackModule, self).__init__()

# handle Ansible 2.7 and 2.8 cases by normalizing each into a dict
try:
from ansible import context
self._options = context.CLIARGS
except ImportError:
self._options = vars(cli.options) if cli else {}

def raw_triage(self, key_string, item, patterns):
# process dict values
Expand Down Expand Up @@ -70,13 +77,13 @@ def cli_options(self):
}

for option,value in iteritems(strings):
if getattr(self._options, value, False):
options.append("{0}='{1}'".format(option, str(getattr(self._options, value))))
if self._options.get(value, False):
options.append("{0}='{1}'".format(option, str(self._options.get(value))))

for inventory in getattr(self._options, 'inventory'):
for inventory in self._options.get('inventory'):
options.append("--inventory='{}'".format(str(inventory)))

if getattr(self._options, 'ask_vault_pass', False):
if self._options.get('ask_vault_pass', False):
options.append('--ask-vault-pass')

return ' '.join(options)
Expand All @@ -98,11 +105,10 @@ def v2_playbook_on_play_start(self, play):
env_group.set_priority(20)

for host in play.get_variable_manager()._inventory.list_hosts(play.hosts[0]):
# it should be ok to remove dummy Task() once minimum required Ansible >= 2.4.2
hostvars = play.get_variable_manager().get_vars(play=play, host=host, task=Task())
hostvars = play.get_variable_manager().get_vars(play=play, host=host)
self.raw_vars(play, host, hostvars)
host.vars['ssh_args_default'] = PlayContext(play=play, options=self._options)._ssh_args.default
host.vars['ssh_args_default'] = PlayContext(play=play)._ssh_args.default
host.vars['cli_options'] = self.cli_options()
host.vars['cli_ask_pass'] = getattr(self._options, 'ask_pass', False)
host.vars['cli_ask_become_pass'] = getattr(self._options, 'become_ask_pass', False)
host.vars['cli_ask_pass'] = self._options.get('ask_pass', False)
host.vars['cli_ask_become_pass'] = self._options.get('become_ask_pass', False)
host.vars['darwin_without_passlib'] = self.darwin_without_passlib()
2 changes: 1 addition & 1 deletion lib/trellis/plugins/vars/version.py
Expand Up @@ -15,7 +15,7 @@
display = Display()

version_requirement = '2.7.12'
version_tested_max = '2.7.13'
version_tested_max = '2.8.4'
python3_required_version = '2.5.3'

if version_info[0] == 3 and not ge(LooseVersion(__version__), LooseVersion(python3_required_version)):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
@@ -1,2 +1,2 @@
ansible>=2.7.12,<2.8
ansible>=2.7.12,<2.9
passlib

0 comments on commit e4e70d5

Please sign in to comment.