Cloud-config

From Federal Burro of Information
Revision as of 22:22, 1 December 2020 by David (talk | contribs)
Jump to navigationJump to search

sample file:

source: https://docs.microsoft.com/en-us/azure/virtual-machines/linux/tutorial-automate-vm-deployment

#cloud-config
package_update: true
package_upgrade: true
packages:
  - nginx
  - nodejs
  - npm
  - vim
  - ping
  - lsof
  - telnet
  - iptraf-ng
  - apt-utils


write_files:
  - owner: www-data:www-data
    path: /etc/nginx/sites-available/default
    content: |
      server {
        listen 80;
        location / {
          proxy_pass http://localhost:3000;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection keep-alive;
          proxy_set_header Host $host;
          proxy_cache_bypass $http_upgrade;
        }
      }
  - owner: azureuser:azureuser
    path: /home/azureuser/myapp/index.js
    content: |
      var express = require('express')
      var app = express()
      var os = require('os');
      app.get('/', function (req, res) {
        res.send('Hello World from host ' + os.hostname() + '!')
      })
      app.listen(3000, function () {
        console.log('Hello world app listening on port 3000!')
      })
runcmd:
  - curl -sSO https://dl.google.com/cloudagents/add-monitoring-agent-repo.sh
  - bash add-monitoring-agent-repo.sh
  - apt-get update
  - apt-get install -y 'stackdriver-agent'
  - service stackdriver-agent start
  - service nginx restart
  - cd "/home/azureuser/myapp"
  - npm init
  - npm install express -y
  - nodejs index.js