clearlinux / micro-config-drive

An alternative and small cloud-init implementation in C
Other
46 stars 17 forks source link

UCD executes runcmd entries in the wrong order #29

Open markdryan opened 6 years ago

markdryan commented 6 years ago

This can be seen with the tests/runcmd.yaml file which contains the following contents.

#cloud-config
runcmd:
  - [ ls, -l, / ]
  - [ sh, -xc, "echo $(date) ': hello world!'" ]
  - [ sh, -c, echo "=========hello world'=========" ]
  - ls -l /root
  - [ wget, "http://slashdot.org", -O, /tmp/index.html ]

Now look at the ouput of ucd. I also see this behaviour when ucd is running as part of the boot process.

Actually, it's not quite reverse order as it seems that the command not in flow form is executed first

./ucd -u examples/runcmd.yaml
[20051.434582] micro-config-drive version: 30
[20051.435051] userdata: Looking for shebang file /root/micro-config-drive/examples/runcmd.yaml
[20051.435147] userdata: Shebang found #cloud-config

[20051.435194] Parsing user data file /root/micro-config-drive/examples/runcmd.yaml
[20051.435623] Loaded handler for block "package_upgrade"
[20051.435666] Loaded handler for block "write_files"
[20051.435673] Loaded handler for block "packages"
[20051.435681] Loaded handler for block "groups"
[20051.435697] Loaded handler for block "users"
[20051.435708] Loaded handler for block "ssh_authorized_keys"
[20051.435715] Loaded handler for block "service"
[20051.435725] Loaded handler for block "hostname"
[20051.435750] Loaded handler for block "runcmd"
[20051.435768] Loaded handler for block "envar"
[20051.435792] Loaded handler for block "fbootcmd"
[20051.435820] Executing handler for block "runcmd"
[20051.435835] runcmd: runcmd handler running...
[20051.435855] lib: Executing: /bin/bash -c "ls -l /root "
[20051.439425] lib: STD output: total 4
drwxr-xr-x 11 root root 4096 Feb 28 17:26 micro-config-drive

[20051.439494] lib: Executing: /bin/bash -c "wget http://slashdot.org -O /tmp/index.html "
[20051.441239] lib: Command failed
[20051.441277] lib: STD Error: /bin/bash: wget: command not found

[20051.441288] lib: STD output: 
[20051.441299] runcmd: Execute command failed
[20051.441316] lib: Executing: /bin/bash -c "sh -c echo \"=========hello world'=========\" "
[20051.443245] lib: STD output: 

[20051.443287] lib: Executing: /bin/bash -c "sh -xc echo $(date) ': hello world!' "
[20051.446077] lib: STD output: 

[20051.446118] lib: Executing: /bin/bash -c "ls -l / "
[20051.448414] lib: STD output: total 64
drwxr-xr-x   1 root root 4096 Feb 26 13:34 bin
drwxr-xr-x   2 root root 4096 Apr 12  2016 boot
drwxr-xr-x   5 root root  360 Feb 28 14:48 dev
drwxr-xr-x   1 root root 4096 Feb 28 17:21 etc
drwxr-xr-x   2 root root 4096 Apr 12  2016 home
drwxr-xr-x   1 root root 4096 Feb 26 10:18 lib
drwxr-xr-x   2 root root 4096 Jan 23 22:49 lib64
drwxr-xr-x   2 root root 4096 Jan 23 22:49 media
drwxr-xr-x   2 root root 4096 Jan 23 22:49 mnt
drwxr-xr-x   2 root root 4096 Jan 23 22:49 opt
dr-xr-xr-x 180 root root    0 Feb 28 14:48 proc
drwx------   1 root root 4096 Feb 28 17:21 root
drwxr-xr-x   1 root root 4096 Feb 26 13:34 run
drwxr-xr-x   1 root root 4096 Feb 26 10:16 sbin
drwxr-xr-x   2 root root 4096 Jan 23 22:49 srv
dr-xr-xr-x  13 root root    0 Feb 28 17:16 sys
drwxrwxrwt   1 root root 4096 Feb 28 17:21 tmp
drwxr-xr-x   1 root root 4096 Jan 23 22:49 usr
drwxr-xr-x   1 root root 4096 Jan 23 22:49 var
electrocucaracha commented 5 years ago

I'm having the same issue, this is the output of my /var/lib/cloud/aws-user-data file:

#cloud-config
package_upgrade: false
packages:
  - wget
runcmd:
  - [ wget, "https://raw.githubusercontent.com/electrocucaracha/dlrs/master/postinstall.sh", -O, "/tmp/postinstall.sh" ]
  - [ sudo, chmod, "+x", "/tmp/postinstall.sh" ]
  - [ DLRS_TYPE=pytorch-oss, bash, "/tmp/postinstall.sh" ]

And the output in the journalctl is:

Jul 17 18:50:56 clr-ec28044a3ae4cbd130a11a5fdd66cb3c ucd-aws[477]: Successfully installed 1 bundle
Jul 17 18:50:56 clr-ec28044a3ae4cbd130a11a5fdd66cb3c ucd-aws[477]: [12.205854] Executing handler for block "runcmd"
Jul 17 18:50:56 clr-ec28044a3ae4cbd130a11a5fdd66cb3c ucd-aws[477]: [12.205859] runcmd: runcmd handler running...
Jul 17 18:50:56 clr-ec28044a3ae4cbd130a11a5fdd66cb3c ucd-aws[477]: [12.205869] lib: Executing: /bin/sh -c "DLRS_TYPE=pytorch-oss bash /tmp/postinstall.sh "
Jul 17 18:50:56 clr-ec28044a3ae4cbd130a11a5fdd66cb3c ucd-aws[477]: [12.208210] lib: Command failed
Jul 17 18:50:56 clr-ec28044a3ae4cbd130a11a5fdd66cb3c ucd-aws[477]: [12.208222] lib: STD Error: bash: /tmp/postinstall.sh: No such file or directory
Jul 17 18:50:56 clr-ec28044a3ae4cbd130a11a5fdd66cb3c ucd-aws[477]: [12.208225] lib: STD output:
Jul 17 18:50:56 clr-ec28044a3ae4cbd130a11a5fdd66cb3c ucd-aws[477]: [12.208228] runcmd: Execute command failed
Jul 17 18:50:56 clr-ec28044a3ae4cbd130a11a5fdd66cb3c ucd-aws[477]: [12.208238] lib: Executing: /bin/sh -c "sudo chmod +x /tmp/postinstall.sh "
Jul 17 18:50:56 clr-ec28044a3ae4cbd130a11a5fdd66cb3c sudo[806]: pam_unix(sudo:account): expired password for user root (root enforced)
Jul 17 18:50:56 clr-ec28044a3ae4cbd130a11a5fdd66cb3c sudo[806]:     root : Account or password is expired, reset your password and try again ; TTY=unknown ; PWD=/ ; USER=root ; COMMAND=
/usr/bin/chmod +x /tmp/postinstall.sh
Jul 17 18:50:56 clr-ec28044a3ae4cbd130a11a5fdd66cb3c sudo[806]: pam_warn(sudo:chauthtok): function=[pam_sm_chauthtok] flags=0x4020 service=[sudo] terminal=[] user=[root] ruser=[root] rh
ost=[<unknown>]
Jul 17 18:50:56 clr-ec28044a3ae4cbd130a11a5fdd66cb3c sudo[806]:     root : unable to change expired password: Authentication token manipulation error ; TTY=unknown ; PWD=/ ; USER=root ;
 COMMAND=/usr/bin/chmod +x /tmp/postinstall.sh
Jul 17 18:50:56 clr-ec28044a3ae4cbd130a11a5fdd66cb3c ucd-aws[477]: [12.290418] lib: Command failed
Jul 17 18:50:56 clr-ec28044a3ae4cbd130a11a5fdd66cb3c ucd-aws[477]: [12.290432] lib: STD Error: sudo: Account or password is expired, reset your password and try again
Jul 17 18:50:56 clr-ec28044a3ae4cbd130a11a5fdd66cb3c ucd-aws[477]: sudo: unable to change expired password: Authentication token manipulation error
Jul 17 18:50:56 clr-ec28044a3ae4cbd130a11a5fdd66cb3c ucd-aws[477]: [12.290436] lib: STD output:
Jul 17 18:50:56 clr-ec28044a3ae4cbd130a11a5fdd66cb3c ucd-aws[477]: [12.290439] runcmd: Execute command failed
Jul 17 18:50:56 clr-ec28044a3ae4cbd130a11a5fdd66cb3c ucd-aws[477]: [12.290451] lib: Executing: /bin/sh -c "wget https://raw.githubusercontent.com/electrocucaracha/dlrs/master/postinstall.sh -O /tmp/postinstall
.sh "
Jul 17 18:50:57 clr-ec28044a3ae4cbd130a11a5fdd66cb3c ucd-aws[477]: [12.366846] lib: STD output:
Jul 17 18:50:57 clr-ec28044a3ae4cbd130a11a5fdd66cb3c systemd[1]: Started micro-config-drive job for AWS.

Maybe the runcmd_item function is inverting the order.

ahkok commented 4 years ago

The issue is due to the cloud_config_simplify function we run on the gnode tree after it is complete.