. ├── ansible │ ├── inventory.ini │ ├── roles │ │ └── common │ │ └── tasks │ │ └── main.yml │ └── site.yml └── buildspec.yml
version: 0.2
phases:
install:
commands:
# SSH接続時のホストキーチェックを無効にする
- sed -i 's/# StrictHostKeyChecking ask/StrictHostKeyChecking no/' /etc/ssh/ssh_config
# EC2の秘密鍵をAWS Secrets Managerから取得し、.sshディレクトリに保存
- aws secretsmanager get-secret-value --secret-id ec2-privatekey --query 'SecretBinary' --output text | base64 -d > ~/.ssh/id_rsa
# 秘密鍵のパーミッションを設定
- chmod 400 ~/.ssh/id_rsa
pre_build:
commands:
- cd ${CODEBUILD_SRC_DIR}/ansible
build:
commands:
# Ansibleプレイブックを実行
- ansible-playbook -i inventory.ini site.yml -u ec2-user -v
---
version: 0.2
phases:
pre_build:
commands:
- sudo apt-get update -y
- sudo apt-get install software-properties-common -y
- sudo apt-add-repository ppa:ansible/ansible -y
- sudo apt-get update -y
- sudo apt-get install ansible -y
- sudo apt-get install openssh-client -y
- cd ./playbook
- chmod 600 ./ssh-keys/sw-iwamoto.pem
- ansible -i hosts/inventory.yml -m ping all
build:
commands:
- ansible-playbook -i hosts/inventory.yml ./setup.yml
post_build:
commands:
- echo "Now Finished Privisioning by Ansible"
| プロジェクト名 | ansible-test1 |
| ソース | ソースプロバイダ:CodeCommit リポジトリ:ansible-test1 リファレンスタイプ:ブランチ ブランチ :main |
| 環境 | プロビジョニングモデル:オンデマンド 環境イメージ :マネージド型イメージ オペレーティングシステム :Amazon Linux 2 ランタイム :Standard イメージ :aws/codebuild/amazonlinux2-x86_64-standard:4.0 イメージのバージョン :最新のイメージ 環境タイプ :Linux サービスロール:既存のサービスロール (CodeCommitへの読み取りが可能なポリシーが必要) タイムアウト:30分 キュータイムアウト:1時間 特権付与:有効 証明書:証明書をインストールしない VPC: サブネット: セキュリティグループ: |