0

i want to execute this cloud-init file and terraform file:

Cloud-init:

#cloud-config
runcmd:
  - mkdir react
  - cd react
  - type -p curl >/dev/null || sudo apt install curl -y
    curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
    && sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
    && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
    && sudo apt update \
    && sudo apt install gh -y
  - curl -o actions-runner-linux-x64-2.301.1.tar.gz -L https://github.com/actions/runner/releases/download/v2.301.1/actions-runner-linux-x64-2.301.1.tar.gz
  - tar xzf ./actions-runner-linux-x64-2.301.1.tar.gz
  - yes "" | ./config.sh --url https://github.com/yuuval/react-deploy --token AVYXWHXNRBPIDXJDPUDK6QTD2LIPE
  - sudo ./svc.sh install
  - sudo ./svc.sh start
  - yes "" | sudo apt install nginx
  - gh auth login --hostname github.com --with-token <<< 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 --git-protocol https
  - gh repo clone yuuval/react-deploy
  - cd react-deploy
  - gh workflow run node.js.yml
  - sleep 70
  - cd /etc/nginx/sites-available
  - sudo rm default
  - echo     "server {
      listen 80 default_server;
      server_name _;
      # react app & front-end files
      location / {
       root /home/ubuntu/react/_work/react-deploy/react-deploy/build;
       try_files \$uri /index.html;
      }
    }" | sudo tee /etc/nginx/sites-available/default
  - sudo service nginx restart
  - sudo chmod +x /home
  - sudo chmod +x /home/ubuntu
  - sudo chmod +x /home/ubuntu/react
  - sudo chmod +x /home/ubuntu/react/_work
  - sudo chmod +x /home/ubuntu/react/_work/react-deploy
  - sudo chmod +x /home/ubuntu/react/_work/react-deploy/react-deploy
  - sudo chmod +x /home/ubuntu/react/_work/react-deploy/react-deploy/build

The terraform file isn't relevant i think. So when i run this whole thing with terraform init and terraform apply, its going threw but nothing is hapenning. In the /var/log in the file cloud-init-output file i found this error:

dd: unrecognized operand ‘ ’
Try 'dd --help' for more information.
E: Command line option 'S' [from -fsSL] is not understood in combination with the other options.

I guess its from this command, which should install gh cli (found here: https://github.com/cli/cli/blob/trunk/docs/install_linux.md):

type -p curl >/dev/null || sudo apt install curl -y
    curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
    && sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
    && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
    && sudo apt update \
    && sudo apt install gh -y

If i do this whole cloud-init file manually it works. So i don't know what to do else.

crvxッ
  • 60
  • 7

1 Answers1

0

You seem to be missing \ and && after install curl -y, since I just tried on two WSL machines (that's all I have with me right now) and it was just fine there.
So my suspicion is that your curl command got dazed inside, since you're not exactly running that smaller command and bigger one separately, but they should be rather sundered, so maybe give it a shot? On this weird page (came up by exact search) https://ouyen.github.io/github/ I found no install curl -y but the next one, which clearly indicated it being ran separately, so I think your issue is just there.

Randych
  • 56
  • 5