Oefenweb / ansible-wordpress

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

Use environment variable for core | install item title #58

Open jbillo opened 4 years ago

jbillo commented 4 years ago

I have a WordPress installation in my list of wordpress_installs that has a single-quote character ' in the title. An example would be something like:

      - name: example.com
        path: "/var/www/example.com"
        url: "http://example.com"
        title: "Example User's Weblog"

Currently this fails as the wp-cli core install command is invoked with the Ansible {{ item.item.title }} variable in single quotes, making the shell command unbalanced (https://github.com/Oefenweb/ansible-wordpress/blob/master/tasks/core.yml#L53).

Rather than using regex_replace or replace on the string, as a workaround, set the ITEM_TITLE environment variable, then use it in a double-quoted string. This should preserve behaviour of single quotes, apostrophes, and $ characters.

Tested with the following config:

      - name: example.com
        path: "/var/www/example.com"
        url: "http://example.com"
        title: "Title with Single Quote ' Double Quote \" Dollar Sign $"
        dbname: example_wp
        dbuser: example_wp
        dbpass: NotARealDBPassword
        admin_email: example@example.com
        admin_password: NotARealWPPassword
        themes: []
        plugins: []
        options: []

Resulting in the following database value:

# mysql example_wp -e "select option_value from wp_options where option_name='blogname'"
+------------------------------------------------------------------+
| option_value                                                     |
+------------------------------------------------------------------+
| Title with Single Quote ' Double Quote " Dollar Sign $ |
+------------------------------------------------------------------+

I would be amenable to changing the environment variable name if there is a preference, but it should also only persist for this particular task in core as per the Ansible documentation (https://docs.ansible.com/ansible/latest/user_guide/playbooks_environment.html).