Score:1

How can I run complex piped commands in Autoinstall / Cloud-Init?

cn flag

In either cloud-init user-data runcmd, or in autoinstall late-commands, I need to essentially run this command as part of a Clevis + Tang initialization for a LUKS encrypted volume:

echo '<secret>' | clevis luks bind -d /dev/sda2 tang '{"url": "http://<ip-tangserver>" , "adv": "/tmp/adv.jws" }'

The problem is, I'm having a hard time determining if this is actually possible using either runcmd or late-commands, and if so, how I can do this in a YAML-compliant way, eg:

runcmd:
  - echo 'some-luks-temp-passwd' | clevis luks bind -d /dev/vda3 tang '{"url": "http://192.168.122.150" , "adv": "/tmp/adv.jws" }'

Enclosing the entire string above doesn't seem to work either, yamllint still shows a syntax error:

runcmd:
  - "echo 'some-luks-temp-passwd' | clevis luks bind -d /dev/vda3 tang '{"url": "http://192.168.122.150" , "adv": "/tmp/adv.jws" }'"

Thanks!

lnee avatar
td flag
try this `bash -c 'echo '\''<secret>'\'' | clevis luks bind -d /dev/sda2 tang '\''{"url": "http://<ip-tangserver>" , "adv": "/tmp/adv.jws" }'\'''`
lnee avatar
td flag
What I did is put the thing I want to run in a file and do `i=$(cat tmp)` next run this `set | grep "^i="` remove the "i=" part, and you're good
cn flag
Thanks @lnee, but it looks like the escaping above still results in yamllint failures. `syntax error: expected <block end>, but found ','` I'm going to keep on digging but thank you for the option to try!
lnee avatar
td flag
`bash -c "$(xxd -r -p <<<"hexblob)" ` replace "hexblob" with the output of this `hexdump -v -e '/1 "%02X "' "REPLACEWITHFILETHAT HAS YOUR CODE" |sed -e 's/ //g'" ` (note code was taken from https://github.com/lnee94/resh/blob/main/l/bintools)
Score:1
jp flag

You might be able to use YAML multiline syntax. I'm not sure what is failing with your current syntax, but here is an autoinstall snippet that uses json, piping, output redirection, and Heredoc in multiline syntax.

#cloud-config
runcmd:
  - |
    echo '{"foo":"FOO" , "bar" : "BAR"}' > /run/cmd.log
    cat <<EOF | xxd >> /run/cmd.log
    {
      "foo": "FOO",
      "bar": "BAR"
    }
    EOF

FWIW, this is the resulting /run/cmd.log file

root@ubuntu-server:/# cat /run/cmd.log
{"foo":"FOO" , "bar" : "BAR"}
00000000: 7b0a 2020 2266 6f6f 223a 2022 464f 4f22  {.  "foo": "FOO"
00000010: 2c0a 2020 2262 6172 223a 2022 4241 5222  ,.  "bar": "BAR"
00000020: 0a7d 0a                                  .}.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.