Memo/Packer

https://dexlab.net:443/pukiwiki/index.php?Memo/Packer
 

Packer

  • https://www.packer.io/
    • CHANGELOG.md
    • HashiCorp製ツール(Vagrant, packer, Serfの開発元)
    • 仮想マシンイメージ作成をスクリプト化できる
      • AMIs for EC2
      • VMDK/VMX files for VMware
      • OVF exports for VirtualBox
      • Docker

ansible 2.8以降だとGathering Factsから進まない

  • 一時的な対応: ansible <= 2.7.17だと動作する。
    sudo pip install ansible==2.7.17

aws_profileを指定する

  • access key, secret keyはawscliで管理して、それをpackerから指定したい。
  1. aws cliでprofileを作る
    aws configure --profile example
  2. packer.json
    {
      "variables": {
        "aws_profile": "{{env `AWS_PROFILE`}}",
        "aws_region": "ap-northeast-1"
      },
      "builders": [
        {
          "type": "amazon-ebs",
          "profile": "{{user `aws_profile`}}",
          "region": "{{user `aws_region`}}"
        }
      ]
    }
  3. 実行: AWS_PROFILEを環境変数として渡す場合
    AWS_PROFILE=example packer build packer.json

function "clean_ami_name" not defined

  • packer 1.5.6でのエラー
    function "clean_ami_name" not defined in:
  • 原因: v1.5.0から「clean_ami_name」が廃止され、「clean_resource_name」に変わった。
    -NG: {{isotime | clean_ami_name}}
    +OK: {{isotime | clean_resource_name}}

Could not find file for the medium

  • "HOME=/mnt/c/local/home/user01"とする
    Build 'virtualbox-iso' errored: Error attaching floppy: VBoxManage error: VBoxManage.exe: error: Could not find file for the medium 'C:\wsl\CentOS7C?\Users\USER01\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\tmp\virtualbox714031622\floppy.vfd' (VERR_PATH_NOT_FOUND)

Failed creating VirtualBox driver: exec: "VBoxManage": executable file not found in $PATH

  • Windows版Packerでは、環境変数に「VBOX_MSI_INSTALL_PATH="/mnt/c/Program Files/Oracle/VirtualBox"」があれば動くようだ。
  • WSL v1環境では、Linux版Packerを使うので、「VBoxManage.exe」の代わりに「VBoxManage」を探してしまい、動作しない。
    • 「alias VBoxManage="/mnt/c/Program Files/Oracle/VirtualBox/VBoxManage.exe"」ではエラーは変わらず

インストール

  • /usr/local/bin/ にインストールする場合
    PACKER_VER=1.5.4
    wget https://releases.hashicorp.com/packer/${PACKER_VER}/packer_${PACKER_VER}_linux_amd64.zip
    unzip packer_*linux_amd64.zip
    sudo mv packer /usr/local/bin/

複数バージョンを管理したい場合

  • CentOS6.x 64bitの場合。alternativesで複数バージョンを切り替えられるようにする。
    sudo mkdir -p /opt/packer.0.8.6
    sudo wget -O /opt/packer.0.8.6/packer_0.6.9_linux_amd64.zip https://releases.hashicorp.com/packer/0.8.6/packer_0.8.6_linux_amd64.zip
    sudo unzip -d /opt/packer.0.8.6/ /opt/packer.0.8.6/packer_0.6.9_linux_amd64.zip
    
    sudo alternatives --install /usr/local/bin/packer packer /opt/packer.0.8.6/packer 86 \
     --slave /usr/local/bin/packer-builder-amazon-chroot packer-builder-amazon-chroot /opt/packer.0.8.6/packer-builder-amazon-chroot \
     --slave /usr/local/bin/packer-builder-amazon-ebs packer-builder-amazon-ebs /opt/packer.0.8.6/packer-builder-amazon-ebs \
     --slave /usr/local/bin/packer-builder-amazon-instance packer-builder-amazon-instance /opt/packer.0.8.6/packer-builder-amazon-instance \
     --slave /usr/local/bin/packer-builder-digitalocean packer-builder-digitalocean /opt/packer.0.8.6/packer-builder-digitalocean \
     --slave /usr/local/bin/packer-builder-docker packer-builder-docker /opt/packer.0.8.6/packer-builder-docker \
     --slave /usr/local/bin/packer-builder-file packer-builder-file /opt/packer.0.8.6/packer-builder-file \
     --slave /usr/local/bin/packer-builder-googlecompute packer-builder-googlecompute /opt/packer.0.8.6/packer-builder-googlecompute \
     --slave /usr/local/bin/packer-builder-null packer-builder-null /opt/packer.0.8.6/packer-builder-null \
     --slave /usr/local/bin/packer-builder-openstack packer-builder-openstack /opt/packer.0.8.6/packer-builder-openstack \
     --slave /usr/local/bin/packer-builder-parallels-iso packer-builder-parallels-iso /opt/packer.0.8.6/packer-builder-parallels-iso \
     --slave /usr/local/bin/packer-builder-parallels-pvm packer-builder-parallels-pvm /opt/packer.0.8.6/packer-builder-parallels-pvm \
     --slave /usr/local/bin/packer-builder-qemu packer-builder-qemu /opt/packer.0.8.6/packer-builder-qemu \
     --slave /usr/local/bin/packer-builder-virtualbox-iso packer-builder-virtualbox-iso /opt/packer.0.8.6/packer-builder-virtualbox-iso \
     --slave /usr/local/bin/packer-builder-virtualbox-ovf packer-builder-virtualbox-ovf /opt/packer.0.8.6/packer-builder-virtualbox-ovf \
     --slave /usr/local/bin/packer-builder-vmware-iso packer-builder-vmware-iso /opt/packer.0.8.6/packer-builder-vmware-iso \
     --slave /usr/local/bin/packer-builder-vmware-vmx packer-builder-vmware-vmx /opt/packer.0.8.6/packer-builder-vmware-vmx \
     --slave /usr/local/bin/packer-post-processor-artifice packer-post-processor-artifice /opt/packer.0.8.6/packer-post-processor-artifice \
     --slave /usr/local/bin/packer-post-processor-atlas packer-post-processor-atlas /opt/packer.0.8.6/packer-post-processor-atlas \
     --slave /usr/local/bin/packer-post-processor-compress packer-post-processor-compress /opt/packer.0.8.6/packer-post-processor-compress \
     --slave /usr/local/bin/packer-post-processor-docker-import packer-post-processor-docker-import /opt/packer.0.8.6/packer-post-processor-docker-import \
     --slave /usr/local/bin/packer-post-processor-docker-push packer-post-processor-docker-push /opt/packer.0.8.6/packer-post-processor-docker-push \
     --slave /usr/local/bin/packer-post-processor-docker-save packer-post-processor-docker-save /opt/packer.0.8.6/packer-post-processor-docker-save \
     --slave /usr/local/bin/packer-post-processor-docker-tag packer-post-processor-docker-tag /opt/packer.0.8.6/packer-post-processor-docker-tag \
     --slave /usr/local/bin/packer-post-processor-vagrant packer-post-processor-vagrant /opt/packer.0.8.6/packer-post-processor-vagrant \
     --slave /usr/local/bin/packer-post-processor-vagrant-cloud packer-post-processor-vagrant-cloud /opt/packer.0.8.6/packer-post-processor-vagrant-cloud \
     --slave /usr/local/bin/packer-post-processor-vsphere packer-post-processor-vsphere /opt/packer.0.8.6/packer-post-processor-vsphere \
     --slave /usr/local/bin/packer-provisioner-ansible-local packer-provisioner-ansible-local /opt/packer.0.8.6/packer-provisioner-ansible-local \
     --slave /usr/local/bin/packer-provisioner-chef-client packer-provisioner-chef-client /opt/packer.0.8.6/packer-provisioner-chef-client \
     --slave /usr/local/bin/packer-provisioner-chef-solo packer-provisioner-chef-solo /opt/packer.0.8.6/packer-provisioner-chef-solo \
     --slave /usr/local/bin/packer-provisioner-file packer-provisioner-file /opt/packer.0.8.6/packer-provisioner-file \
     --slave /usr/local/bin/packer-provisioner-powershell packer-provisioner-powershell /opt/packer.0.8.6/packer-provisioner-powershell \
     --slave /usr/local/bin/packer-provisioner-puppet-masterless packer-provisioner-puppet-masterless /opt/packer.0.8.6/packer-provisioner-puppet-masterless \
     --slave /usr/local/bin/packer-provisioner-puppet-server packer-provisioner-puppet-server /opt/packer.0.8.6/packer-provisioner-puppet-server \
     --slave /usr/local/bin/packer-provisioner-salt-masterless packer-provisioner-salt-masterless /opt/packer.0.8.6/packer-provisioner-salt-masterless \
     --slave /usr/local/bin/packer-provisioner-shell packer-provisioner-shell /opt/packer.0.8.6/packer-provisioner-shell \
     --slave /usr/local/bin/packer-provisioner-shell-local packer-provisioner-shell-local /opt/packer.0.8.6/packer-provisioner-shell-local \
     --slave /usr/local/bin/packer-provisioner-windows-restart packer-provisioner-windows-restart /opt/packer.0.8.6/packer-provisioner-windows-restart \
     --slave /usr/local/bin/packer-provisioner-windows-shell packer-provisioner-windows-shell /opt/packer.0.8.6/packer-provisioner-windows-shell \
  • バージョンの切り替え
    sudo alternatives --display packer
    sudo alternatives --set packer /opt/packer.0.8.6/packer

macOSX

brew install packer

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2020-05-08 (金) 12:53:51 (139d)