Skip to content

Commit

Permalink
Merge tag '1.0.0-rc.2' into primoz
Browse files Browse the repository at this point in the history
* tag '1.0.0-rc.2':
  1.0.0-rc.2
  Update to WP-CLI 1.4.1.
  Disallow duplicate site keys within a host's wordpress_sites (roots#910)
  Replace bare Dataloader() with pre-loaded play._loader (roots#917)
  Remove outdated to_unicode import from plugin utils (roots#916)
  Fix raw_vars functionality for Ansible 2.4.1 (roots#915)
  Enable ioapic
  Update vagrant_box_version to current release
  • Loading branch information
primozcigler committed Nov 19, 2017
2 parents 814ff06 + f759a11 commit 5f57462
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 15 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
@@ -1,4 +1,8 @@
### HEAD
### 1.0.0-rc.2: November 13th, 2017
* Update wp-cli to 1.4.1 ([#918](https://github.com/roots/trellis/pull/918))
* Disallow duplicate site keys within a host's `wordpress_sites` ([#910](https://github.com/roots/trellis/pull/910))
* Fix `raw_vars` functionality for Ansible 2.4.1 ([#915](https://github.com/roots/trellis/pull/915))
* Enable Virtualbox ioapic option ([#913](https://github.com/roots/trellis/pull/913))
* Dynamically increase `ansible_group_priority` for selected env ([#909](https://github.com/roots/trellis/pull/909))
* Bump Ansible `version_tested_max` to 2.4.1.0 ([#911](https://github.com/roots/trellis/pull/911))
* Update wp-cli to 1.4.0 ([#906](https://github.com/roots/trellis/pull/906))
Expand Down
5 changes: 3 additions & 2 deletions Vagrantfile
Expand Up @@ -140,10 +140,11 @@ Vagrant.configure('2') do |config|
vb.name = config.vm.hostname
vb.customize ['modifyvm', :id, '--cpus', vconfig.fetch('vagrant_cpus')]
vb.customize ['modifyvm', :id, '--memory', vconfig.fetch('vagrant_memory')]
vb.customize ['modifyvm', :id, '--ioapic', vconfig.fetch('vagrant_ioapic', 'on')]

# Fix for slow external network connections
vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'on']
vb.customize ['modifyvm', :id, '--natdnsproxy1', 'on']
vb.customize ['modifyvm', :id, '--natdnshostresolver1', vconfig.fetch('vagrant_natdnshostresolver', 'on')]
vb.customize ['modifyvm', :id, '--natdnsproxy1', vconfig.fetch('vagrant_natdnsproxy', 'on')]
end

# VMware Workstation/Fusion settings
Expand Down
8 changes: 4 additions & 4 deletions lib/trellis/plugins/callback/vars.py
Expand Up @@ -7,9 +7,9 @@
from __main__ import cli
from ansible.module_utils.six import iteritems
from ansible.errors import AnsibleError
from ansible.parsing.dataloader import DataLoader
from ansible.parsing.yaml.objects import AnsibleMapping, AnsibleSequence, AnsibleUnicode
from ansible.playbook.play_context import PlayContext
from ansible.playbook.task import Task
from ansible.plugins.callback import CallbackBase
from ansible.template import Templar

Expand All @@ -21,7 +21,6 @@ class CallbackModule(CallbackBase):
CALLBACK_NAME = 'vars'

def __init__(self):
self.loader = DataLoader()
self._options = cli.options if cli else None

def raw_triage(self, key_string, item, patterns):
Expand All @@ -42,7 +41,7 @@ def raw_vars(self, play, host, hostvars):
if 'raw_vars' not in hostvars:
return

raw_vars = Templar(variables=hostvars, loader=self.loader).template(hostvars['raw_vars'])
raw_vars = Templar(variables=hostvars, loader=play._loader).template(hostvars['raw_vars'])
if not isinstance(raw_vars, list):
raise AnsibleError('The `raw_vars` variable must be defined as a list.')

Expand Down Expand Up @@ -95,7 +94,8 @@ 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]):
hostvars = play.get_variable_manager().get_vars(play=play, host=host)
# 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())
self.raw_vars(play, host, hostvars)
host.vars['ssh_args_default'] = PlayContext(play=play, options=self._options)._ssh_args.default
host.vars['cli_options'] = self.cli_options()
Expand Down
7 changes: 1 addition & 6 deletions lib/trellis/utils/output.py
Expand Up @@ -8,12 +8,7 @@
import textwrap

from ansible import __version__

# to_unicode will no longer be needed once Trellis requires Ansible >= 2.2
try:
from ansible.module_utils._text import to_text
except ImportError:
from ansible.utils.unicode import to_unicode as to_text
from ansible.module_utils._text import to_text

def system(vagrant_version=None):
# Get most recent Trellis CHANGELOG entry
Expand Down
20 changes: 20 additions & 0 deletions roles/common/defaults/main.yml
@@ -1,5 +1,25 @@
ntp_timezone: Etc/UTC

env_groups: "{{ ['development', 'staging', 'production'] | intersect(group_names) }}"

envs_with_wp_sites: "{{
lookup('filetree', playbook_dir + '/group_vars') |
selectattr('path', 'match', '(' + env_groups | join('|') + ')/wordpress_sites\\.yml$') |
map(attribute='path') | map('regex_replace', '([^/]*)/.*', '\\1') | list
}}"

site_keys_by_env_pair: "[
{% for env_pair in envs_with_wp_sites | combinations(2) | list %}
{
'env_pair': {{ env_pair }},
'site_keys': {{
(vars[env_pair[0] + '_sites'].wordpress_sites | default({})).keys() | intersect(
(vars[env_pair[1] + '_sites'].wordpress_sites | default({})).keys())
}}
},
{% endfor %}
]"

apt_packages_default:
python-software-properties: "{{ apt_package_state }}"
python-pycurl: "{{ apt_package_state }}"
Expand Down
22 changes: 22 additions & 0 deletions roles/common/tasks/main.yml
@@ -1,4 +1,26 @@
---
- block:
- name: Load wordpress_sites.yml vars into <env>_sites vars
include_vars:
file: group_vars/{{ item }}/wordpress_sites.yml
name: "{{ item }}_sites"
with_items: "{{ envs_with_wp_sites }}"
when: envs_with_wp_sites | count > 1

- name: Fail if there are duplicate site keys within host's wordpress_sites
fail:
msg: >
If you put multiple environments on `{{ inventory_hostname }}`, `wordpress_sites`
must use different site keys per environment. Adjust the following site keys that
are duplicated between the `{{ item.env_pair | join('` and `') }}` groups:
{{ item.site_keys | to_nice_yaml | indent(2) }}
when: item.site_keys | count
with_items: "{{ site_keys_by_env_pair }}"

when:
- env_groups | count > 1
- validate_site_keys | default(true) | bool

- name: Validate wordpress_sites
fail:
msg: "{{ lookup('template', 'wordpress_sites.j2') }}"
Expand Down
2 changes: 1 addition & 1 deletion roles/wp-cli/defaults/main.yml
@@ -1,4 +1,4 @@
wp_cli_version: 1.4.0
wp_cli_version: 1.4.1
wp_cli_bin_path: /usr/bin/wp
wp_cli_phar_url: "https://github.com/wp-cli/wp-cli/releases/download/v{{ wp_cli_version }}/wp-cli-{{ wp_cli_version }}.phar"
wp_cli_completion_url: "https://raw.githubusercontent.com/wp-cli/wp-cli/v{{ wp_cli_version }}/utils/wp-completion.bash"
Expand Down
2 changes: 1 addition & 1 deletion vagrant.default.yml
Expand Up @@ -3,7 +3,7 @@ vagrant_ip: '192.168.31.41'
vagrant_cpus: 1
vagrant_memory: 1024 # in MB
vagrant_box: 'bento/ubuntu-16.04'
vagrant_box_version: '<= 2.3.8'
vagrant_box_version: '<= 201710.25.0'
vagrant_ansible_version: '2.4.1.0'
vagrant_skip_galaxy: false

Expand Down

0 comments on commit 5f57462

Please sign in to comment.