Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use environment variable for core | install item title #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jbillo
Copy link

@jbillo jbillo commented Jun 29, 2020

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants