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

Fixed quotes to represent intent of examples #43268

Open
wants to merge 1 commit into
base: devel
from

Conversation

Projects
None yet
4 participants
@xdfil

xdfil commented Jul 25, 2018

I think the changes I made are the true intent of the author

+label: docsite_pr

SUMMARY
ISSUE TYPE
  • Docs Pull Request
COMPONENT NAME
ANSIBLE VERSION

ADDITIONAL INFORMATION

Fixed quotes to represent intent of examples
I think the changes I made are the true intent of the author

+label: docsite_pr
@ansibot

This comment has been minimized.

Contributor

ansibot commented Jul 25, 2018

@samdoran

This comment has been minimized.

Member

samdoran commented Jul 25, 2018

Thank you for your contribution. Unfortunately, the changes made would not work in the second example.

Double quotes and single qutoes in YAML have different escaping requirements that behave similar to other languages. From the YAML spec on double-quoted style:

This is the only style capable of expressing arbitrary strings, by using “\” escape sequences. This comes at the cost of having to escape the “\” and “"” characters.

So any backrefs would have to escape the backslah, e.g., \\1Xms

The single-quoted style interprets pretty much everything as a literal, with only single quotes having to be escpaed. From the YAML spec on single-quoted style:

The single-quoted style is specified by surrounding “'” indicators. Therefore, within a single-quoted scalar, such characters need to be repeated. This is the only form of escaping performed in single-quoted scalars. In particular, the “\” and “"” characters may be freely used.

That's why it's generally easier to use single quotes for regular expressions in YAML.

@ansibot ansibot removed the needs_triage label Jul 25, 2018

# Yaml requires escaping backslashes in double quotes but not in single quotes
- lineinfile:
path: /opt/jboss-as/bin/standalone.conf
regexp: '^(.*)Xms(\\d+)m(.*)$'
line: '\1Xms${xms}m\3'
line: "\1Xms${xms}m\3"

This comment has been minimized.

@samdoran

samdoran Jul 25, 2018

Member

This example is supposed to show the difference in single vs double quoting requirements in YAML, but it's incorrect. This like should be singel quoted but the regexp should be double quoted.

- lineinfile:
path: /etc/sudoers
state: present
regexp: '^%wheel\s'
line: '%wheel ALL=(ALL) NOPASSWD: ALL'
line: "%wheel ALL=(ALL) NOPASSWD: ALL"
# Yaml requires escaping backslashes in double quotes but not in single quotes

This comment has been minimized.

@samdoran

samdoran Jul 25, 2018

Member

Capitalize YAML

@@ -158,26 +158,26 @@
line: '192.168.1.99 foo.lab.net foo'
create: yes
# Fully quoted because of the ': ' on the line. See the Gotchas in the YAML docs.
# Double quoted because of the ': ' on the line. See the Gotchas in the YAML docs.

This comment has been minimized.

@samdoran

samdoran Jul 25, 2018

Member

Fully quoted is accurate. This line can be double of single quoted.

@ansibot

This comment has been minimized.

Contributor

ansibot commented Jul 26, 2018

The test ansible-test sanity --test yamllint [explain] failed with 1 error:

lib/ansible/modules/files/lineinfile.py:172:13: error EXAMPLES: syntax error: found unknown escape character '1'

The test ansible-test sanity --test validate-modules [explain] failed with 1 error:

lib/ansible/modules/files/lineinfile.py:172:13: E311 EXAMPLES is not valid YAML

click here for bot help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment