Cloud Assembly 템플릿 코드에 cloudConfig 섹션을 추가하여, 배포 시 실행되는 시스템 초기화 명령을 추가할 수 있습니다.

cloudConfig 명령 형식

  • Linux—초기화 명령은 개방형 cloud-init 표준을 따릅니다.
  • Windows—초기화 명령은 Cloudbase-init를 사용합니다.

Linux cloud-init 및 Windows Cloudbase-init는 동일한 구문을 공유하지 않습니다. 한 운영 체제의 cloudConfig 섹션이 다른 운영 체제의 시스템 이미지에서 작동하지 않습니다.

cloudConfig 명령으로 수행할 수 있는 작업

초기화 명령을 사용하여 인스턴스 생성 시 데이터 또는 설정 적용을 자동화하면 사용자, 권한, 설치 또는 기타 명령 기반 작업을 사용자 지정할 수 있습니다. 예는 다음과 같습니다.

  • 호스트 이름 설정
  • SSH 개인 키 생성 및 설정
  • 패키지 설치

cloudConfig 명령을 추가할 수 있는 위치

cloudConfig 섹션을 클라우드 템플릿 코드에 추가할 수 있지만 인프라를 구성할 때 시스템 이미지에 미리 추가할 수도 있습니다. 그러면 소스 이미지를 참조하는 모든 클라우드 템플릿이 동일한 초기화를 받습니다.

이미지 맵과 클라우드 템플릿 둘 다에 초기화 명령이 포함되어 있을 수 있습니다. 배포 시 명령이 병합되고, Cloud Assembly가 통합된 명령을 실행합니다.

동일한 명령이 두 곳 모두에 있고 매개 변수만 다른 경우에는 이미지 맵 명령만 실행됩니다.

자세한 내용은 vRealize Automation의 이미지 매핑에 대해 알아보기의 내용을 참조하십시오.

cloudConfig 명령 구문

잘못된 cloudConfig 명령으로 인해 리소스가 올바르게 구성되지 않았거나 예기치 않게 작동할 수 있습니다.

#cloud-config 문에 구문 오류가 있는 경우 배포를 취소하려면 다음 속성을 추가합니다.

      cloudConfigSettings:
        deploymentFailOnCloudConfigRuntimeError: true

다음 클라우드 템플릿에서 - mkdir 명령이 필요에 따라 runcmd: 아래 새 줄에 없으므로 디렉토리가 생성되지 않습니다. 오류로 인해 deploymentFailOnCloudConfigRuntimeError: true 속성이 배포에 실패합니다.

formatVersion: 1
inputs: {}
resources:
  Cloud_vSphere_Machine_1:
    type: Cloud.vSphere.Machine
    properties:
      image: img1
      cpuCount: 1
      totalMemoryMB: 1024
      cloudConfigSettings:
        deploymentFailOnCloudConfigRuntimeError: true
      cloudConfig: |
        #cloud-config
        runcmd:- mkdir -p /tmp/test-dir

속성을 생략하거나 false로 설정하면 cloudConfig 명령이 실패하더라도 배포가 계속됩니다.

또한 속성에는 #cloud-config 줄이 필요합니다. 이 줄을 생략하면 속성 설정에 관계없이 배포가 계속됩니다.

맞음:

      cloudConfigSettings:
        deploymentFailOnCloudConfigRuntimeError: true
      cloudConfig: |
        #cloud-config
        runcmd:- mkdir -p /tmp/test-dir

틀림:

      cloudConfigSettings:
        deploymentFailOnCloudConfigRuntimeError: true
      cloudConfig: |
        runcmd:- mkdir -p /tmp/test-dir

cloudConfig 명령 예

다음은 Linux 기반 MySQL 서버에 대한 WordPress 사용 사례 클라우드 템플릿 코드에서 가져온 cloudConfig 섹션 예시입니다.

참고:

명령이 제대로 해석되도록 하려면 아래와 같이 파이프 문자(cloudConfig: |)를 항상 포함해야 합니다.

      cloudConfig: |
        #cloud-config
        repo_update: true
        repo_upgrade: all
        packages:
         - apache2
         - php
         - php-mysql
         - libapache2-mod-php
         - php-mcrypt
         - mysql-client
        runcmd:
         - mkdir -p /var/www/html/mywordpresssite && cd /var/www/html && wget https://wordpress.org/latest.tar.gz && tar -xzf /var/www/html/latest.tar.gz -C /var/www/html/mywordpresssite --strip-components 1
         - i=0; while [ $i -le 5 ]; do mysql --connect-timeout=3 -h ${DBTier.networks[0].address} -u root -pmysqlpassword -e "SHOW STATUS;" && break || sleep 15; i=$((i+1)); done
         - mysql -u root -pmysqlpassword -h ${DBTier.networks[0].address} -e "create database wordpress_blog;"
         - mv /var/www/html/mywordpresssite/wp-config-sample.php /var/www/html/mywordpresssite/wp-config.php
         - sed -i -e s/"define( 'DB_NAME', 'database_name_here' );"/"define( 'DB_NAME', 'wordpress_blog' );"/ /var/www/html/mywordpresssite/wp-config.php && sed -i -e s/"define( 'DB_USER', 'username_here' );"/"define( 'DB_USER', 'root' );"/ /var/www/html/mywordpresssite/wp-config.php && sed -i -e s/"define( 'DB_PASSWORD', 'password_here' );"/"define( 'DB_PASSWORD', 'mysqlpassword' );"/ /var/www/html/mywordpresssite/wp-config.php && sed -i -e s/"define( 'DB_HOST', 'localhost' );"/"define( 'DB_HOST', '${DBTier.networks[0].address}' );"/ /var/www/html/mywordpresssite/wp-config.php
         - service apache2 reload

cloud-init 스크립트가 예기치 않게 작동하는 경우 문제를 해결할 때 /var/log/cloud-init-output.log에서 캡처된 콘솔 출력을 확인하십시오. cloud-init에 대한 자세한 내용은 cloud-init 설명서를 참조하십시오.

명령과 사용자 지정 규격이 혼합되지 않을 수 있음

vSphere에 배포하는 경우, 내장된 cloudConfig 명령과 사용자 지정 규격 초기화를 결합하려면 주의해서 진행해야 합니다. 공식적으로 호환되지 않으며 함께 사용하면 일관성이 없거나 원치 않는 결과가 발생할 수 있습니다.

명령과 사용자 지정 규격이 상호 작용하는 방식에 대한 예는 Cloud Assembly의 vSphere 고정 IP 주소에서 참조하십시오.