Page MenuHomePhabricator

Role with quote in description causes bash syntax error
Closed, ResolvedPublic

Description

I was confused after sshing in to clouddb1021 that it said clouddb was still insetup, although a puppet patch was merged to give it a role: https://gerrit.wikimedia.org/r/c/operations/puppet/+/668494

$ ssh clouddb1021.e
Linux clouddb1021 4.19.0-14-amd64 #1 SMP Debian 4.19.171-2 (2021-01-30) x86_64
Debian GNU/Linux 10 (buster)
clouddb1021 is a Host being setup for later application of a role (insetup)
...

The issue is a syntax error in the message of the day script which prints the host's role:

razzi@clouddb1021:~$ /etc/update-motd.d/05-role-wmcs--db--wikireplicas--dedicated--analytics-multiinstance
/etc/update-motd.d/05-role-wmcs--db--wikireplicas--dedicated--analytics-multiinstance: 2: /etc/update-motd.d/05-role-wmcs--db--wikireplicas--dedicated--analytics-multiinstance: Syntax error: ")" unexpected

which is caused by a quote in the description:

class role::wmcs::db::wikireplicas::dedicated::analytics_multiinstance {
    system::role { $name:
        description => 'wikireplica database - analytics, multi-instance (Analytics team\'s special db host)',
    }

interpolated into a single-quoted bash script.

motd::script { "role-${role_title}":
    ensure   => $ensure,
    priority => 5,
    content  => "#!/bin/sh\necho '${message}'\n",
}

Event Timeline

Change 670013 had a related patch set uploaded (by Razzi; owner: Razzi):
[operations/puppet@production] motd: Use heredoc to allow expanding description with apostrophe

https://gerrit.wikimedia.org/r/670013

Change 670013 merged by Razzi:

[operations/puppet@production] motd: Use heredoc to allow expanding description with apostrophe

https://gerrit.wikimedia.org/r/670013

razzi claimed this task.

This has been fixed!