Oefenweb / ansible-wordpress

Ansible role to set up (multiple) wordpress installations in Debian-like systems (using wp-cli)
MIT License
78 stars 35 forks source link

How to set table_prefix? #42

Closed betrcode closed 8 years ago

betrcode commented 8 years ago

In wp-config.php there is a table_prefix setting:

$table_prefix = 'wp_';

How can it be set using this role? Thanks!

tersmitten commented 8 years ago

It can't be set (for now). Does wp-cli support it?

betrcode commented 8 years ago

@tersmitten Yep, there is a "dbprefix" option to the wp-cli command. I hacked around it for now. Like this:

    - name: Remove Wordpress config so we can recreate it
      file: path="{{ www_root }}wp-config.php" state=absent
      sudo: yes

    - name: Overwrite Wordpress config
      command: "wp-cli --allow-root --no-color --path='{{ item.path }}' core config --dbprefix='{{ wordpress_db_prefix }}' --dbname='{{ item.dbname }}' --dbuser='{{ item.dbuser }}' --dbpass='{{ item.dbpass }}' --dbhost='{{ item.dbhost | default('localhost') }}'"
      with_items: wordpress_installs
      sudo: yes
      notify: restart apache

Should be straightforward to add the option to this role so my ugly workaround wouldn't be needed. Wanna do it yourself or do you want a PR? :-)

tersmitten commented 8 years ago

Can you make a pull request?

Add the dbprefix to wordpress_installs.{n}. And add some logic like this (look for skip_update).

betrcode commented 8 years ago

Yep, my motivation is to get rid of my ugly hack. :-) Will make a PR but it may have to wait until tomorrow. Thanks for the quick response and being helpful!

tersmitten commented 8 years ago

I'll wait for the PR, thanks in advance.

betrcode commented 8 years ago

There is no --skip-update option for wp-cli core config. See:

http://wp-cli.org/commands/core/config/

Will try without it.

tersmitten commented 8 years ago

That was just to illustrate the inline if

betrcode commented 8 years ago

Oh, I see! It seems cleaner and easier to go with a default. PR is incoming.

tersmitten commented 8 years ago

Fixed in #44