AAP
WokrFlow
作成
実行
ワークフローの承認
ジョブにて確認
承認しない場合
ワークフロー取り消しの場合
ワークフロー内にワークフローを定義した場合
- 以下を作成
- 赤い線は異常時にのみ実行されるように指定したため
- 子のworkflowでも承認待ちになることを確認
サブネットはプライベートを指定
高度な詳細の最下部にあるユーザデータオプションにSSM-Agentのインストール処理を追記
ユーザデータに以下を記載
#!/bin/bash cd /tmp sudo dnf install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm sudo systemctl enable amazon-ssm-agent sudo systemctl start amazon-ssm-agent
対象のインスタンスが表示されること
インスタンスidを押下
. └── playbook ├── roles │ └── httpd │ ├── tasks │ │ └── main.yml. # Playbookの大元から呼ばれるRoleのPlaybook │ └── vars │ └── main.yml └── site.yml # Playbookの大元
find ./ -type f -name "*yml" | xargs -I{} -t cat -n {} cat -n .//playbook/site.yml 1 --- 2 - name: Install httpd 3 hosts: all 4 gather_facts: true 5 become: true 6 7 tasks: 8 # - name: Show facts 9 # ansible.builtin.debug: 10 # var: ansible_facts 11 12 - name: include role 13 ansible.builtin.include_role: 14 name: httpd cat -n .//playbook/roles/httpd/vars/main.yml 1 --- 2 package: 3 - name: httpd 4 version: 2.4.53 cat -n .//playbook/roles/httpd/tasks/main.yml 1 --- 2 - name: install httpd package 3 ansible.builtin.yum: 4 name: "{{ item.name }}-{{ item.version }}" 5 state: present 6 with_items: "{{ package }}"
zip -r playbook.zip playbook adding: playbook/ (stored 0%) adding: playbook/site.yml (deflated 43%) adding: playbook/roles/ (stored 0%) adding: playbook/roles/httpd/ (stored 0%) adding: playbook/roles/httpd/vars/ (stored 0%) adding: playbook/roles/httpd/vars/main.yml (stored 0%) adding: playbook/roles/httpd/tasks/ (stored 0%) adding: playbook/roles/httpd/tasks/main.yml (deflated 28%)
S3にplaybookを置き、RunCommandでダウンロードするためS3のアクセス権を付与
pathに
アクセス先(オブジェクトURL)を取得
で取得したパスを設定
Playbook Fileに作成したPlaybookを指定
Failedが0であることを確認
[root@ip-10-1-1-124 ssm]# dnf history httpd Updating Subscription Management repositories. Unable to read consumer identity This system is not registered with an entitlement server. You can use subscription-manager to register. ID | Command line | Date and time | Action(s) | Altered -------------------------------------------------------------------------------------------------------- 5 | | 2024-03-03 10:41 | Install | 12 [root@ip-10-1-1-124 ssm]# [root@ip-10-1-1-124 ssm]# dnf info httpd Updating Subscription Management repositories. Unable to read consumer identity This system is not registered with an entitlement server. You can use subscription-manager to register. Last metadata expiration check: 0:04:24 ago on Sun 03 Mar 2024 10:40:24 AM UTC. Installed Packages Name : httpd Version : 2.4.53 Release : 11.el9_2.5 Architecture : x86_64 Size : 59 k Source : httpd-2.4.53-11.el9_2.5.src.rpm Repository : @System From repo : rhel-9-appstream-rhui-rpms Summary : Apache HTTP Server URL : https://httpd.apache.org/ License : ASL 2.0 Description : The Apache HTTP Server is a powerful, efficient, and extensible : web server. Available Packages Name : httpd Version : 2.4.57 Release : 5.el9 Architecture : x86_64 Size : 52 k Source : httpd-2.4.57-5.el9.src.rpm Repository : rhel-9-appstream-rhui-rpms Summary : Apache HTTP Server URL : https://httpd.apache.org/ License : ASL 2.0 Description : The Apache HTTP Server is a powerful, efficient, and extensible : web server. [root@ip-10-1-1-124 ssm]#
SSMログ確認
sudo grep -rn ansible /var/log/amazon/ssm/amazon-ssm-agent.log
SSM-Agentはアウトバンド通信にてVPC中からSystems Managerに連携しにいく
リアルタイムでログを出力したいならCloudWatch Logのみが対応している
対象インスタンスのインバウンドルールには何も設定されていないため、何も許可されていない
ログ出力設定をする
ログ
ロググループ
**ログはEC2から最終的にCloudWatchLogsに送るが、現在のEC2のIAMロールでは権限がない
cloudwatchlogsfull
🐱🐱🐱🐱🐱
バージョンが上がったことを確認
取得されていることを確認
収集されたことを確認
versionは3系のため、4で検索するとデータ無しと表示される
ドキュメント名 | 意味 |
---|---|
AWS-EnableExplorer | 複数の Explorer と AWS アカウント の情報を表示 |
AWS-UpdateSSMAgent | SSM-Agentのアップデート |
AWS-GatherSoftwareInventory | インベントリ収集 |
VPCCidr: VPC設定
PublicSubnetCidr: パブリックサブネット設定
PrivateSubnetCidr: プライベートサブネット設定
PublicSubnet: パブリックサブネットを作成し、サブネットはパブリックサブネット設定を参照、アベイラビリティーは関数によって取得する
PrivateSubnet: プライベートサブネットを作成し、サブネットはプライベートサブネット設定を参照、アベイラビリティーは関数によって取得する
EIP: ElasticIPを作成
InternetGateway: インターネットゲートウェイを作成する
AttachGateway: 作成したInternetGatewayをVPCにアタッチする
NATGateway: EIPの割り当てIDを取得しパブリック接続として設定しサブネットはPublicSubnetを参照する
RouteTableforPublic: VPCを参照しパブリック用のルートテーブルを作成する
RouteTableforPrivate: VPCを参照しプライベート用のルートテーブルを作成する
RouteForPublic: AttachGatewayの作成後に作成したRouteTableforPublicを参照しDestinationCidrBlockで全トラフィックをインターネットゲートウェイに向けるためにInternetGatewayを参照する
RouteForPrivate: NATGatewayの作成後に作成したRouteTableforPrivateを参照しDestinationCidrBlockで全トラフィックをNatゲートウェイに向けるためにNATGatewayを参照する
SubnetRouteTableAssociation1: サブネットとしてPublicSubnet、ルートテーブルとしてRouteTableforPublicを指定しサブネットをルートテーブルに関連付ける
SubnetRouteTableAssociation2: サブネットとしてPrivateSubnet、ルートテーブルとしてRouteTableforPrivateを指定しサブネットをルートテーブルに関連付ける
EC2SecurityGroup: VPC、を指定しセキュリティグループを作成
パラメータ | 意味 | 記載例 | 記載例説明 |
---|---|---|---|
EnableDnsSupport | VPC が Amazon 提供の DNS サーバーを介した DNS 解決策をサポートするかどうかを決定 | true | サポートする |
EnableDnsHostnames | VPC がパブリック IP アドレスを持つインスタンスへのパブリック DNS ホスト名の割り当てをサポートするかどうかを決定 | true | サポートをする |
AvailabilityZone | アベイラビリティーゾーンを指定 | { "Fn::Select" : [ "0", { "Fn::GetAZs" : { "Ref" : "AWS::Region" }}]} | CloudFormationを設定するRegionを取得しGetAZs 関数でAZをアルファベット順にリストした配列を返し、select 関数でリストの0番目(最初)の要素を返す |
MapPublicIpOnLaunch | インスタンスがパブリック IPv4 アドレスを受け取るかどうかを | true | パブリックIPv4アドレスを割り当てる |
AllocationId | 割り当てIDを指定 | { "Fn::GetAtt" : [ "EIP" , "AllocationId"] } | EIPの割り当てIDを取得しGetAtt 関数で属性の値を取得し設定する |
ConnectivityType | Natゲートウェイがパブリック接続かプライベート接続のどちらをサポートするかを設定 | publlic | パブリック接続のサポートをする |
{ "AWSTemplateFormatVersion" : "2010-09-09", "Description" : "This template is for 'AWS Hands-on for Beginners Systems Manager Hands-on'.", "Parameters" : { "VPCCidr" : { "Type" : "String", "Default" : "10.0.0.0/16", "Description" : "VPCCidr" }, "PublicSubnetCidr" : { "Type" : "String", "Default" : "10.0.0.0/24", "Description" : "PublicSubnetCidr" }, "PrivateSubnetCidr" : { "Type" : "String", "Default" : "10.0.1.0/24", "Description" : "PrivateSubnetCidr" } }, "Resources" : { "VPC" : { "Type" : "AWS::EC2::VPC", "Properties" : { "CidrBlock" : { "Ref" : "VPCCidr"}, "EnableDnsSupport" : true, "EnableDnsHostnames" : true, "Tags" : [ {"Key" : "Name", "Value" : "h4b-vpc" } ] } }, "PublicSubnet" : { "Type" : "AWS::EC2::Subnet", "Properties" : { "VpcId" : { "Ref" : "VPC" }, "CidrBlock" : { "Ref" : "PublicSubnetCidr"}, "AvailabilityZone" : { "Fn::Select" : [ "0", { "Fn::GetAZs" : { "Ref" : "AWS::Region" }}]}, "MapPublicIpOnLaunch" : true, "Tags" : [ {"Key" : "Name", "Value" : "h4b-public-subnet" } ] } }, "PrivateSubnet" : { "Type" : "AWS::EC2::Subnet", "Properties" : { "VpcId" : { "Ref" : "VPC" }, "CidrBlock" : { "Ref" : "PrivateSubnetCidr"}, "AvailabilityZone" : { "Fn::Select" : [ "1", { "Fn::GetAZs" : { "Ref" : "AWS::Region" }}]}, "Tags" : [ {"Key" : "Name", "Value" : "h4b-private-subnet" } ] } }, "EIP" : { "Type" : "AWS::EC2::EIP", "Properties" : { "Tags" : [ {"Key" : "Name", "Value" : "h4b-eip" } ] } }, "InternetGateway" : { "Type" : "AWS::EC2::InternetGateway", "Properties" : { "Tags" : [ {"Key" : "Name", "Value" : "h4b-igw" } ] } }, "AttachGateway" : { "Type" : "AWS::EC2::VPCGatewayAttachment", "Properties" : { "VpcId" : { "Ref" : "VPC" }, "InternetGatewayId" : { "Ref" : "InternetGateway" } } }, "NATGateway" : { "Type" : "AWS::EC2::NatGateway", "Properties" : { "AllocationId" : { "Fn::GetAtt" : [ "EIP" , "AllocationId"] }, "ConnectivityType" : "public", "SubnetId" : { "Ref" : "PublicSubnet" } } }, "RouteTableforPublic" : { "Type" : "AWS::EC2::RouteTable", "Properties" : { "VpcId" : {"Ref" : "VPC"}, "Tags" : [ {"Key" : "Name", "Value" : "h4b-public-route-table" } ] } }, "RouteTableforPrivate" : { "Type" : "AWS::EC2::RouteTable", "Properties" : { "VpcId" : {"Ref" : "VPC"}, "Tags" : [ {"Key" : "Name", "Value" : "h4b-private-route-table" } ] } }, "RouteForPublic" : { "Type" : "AWS::EC2::Route", "DependsOn" : "AttachGateway", "Properties" : { "RouteTableId" : { "Ref" : "RouteTableforPublic" }, "DestinationCidrBlock" : "0.0.0.0/0", "GatewayId" : { "Ref" : "InternetGateway" } } }, "RouteForPrivate" : { "Type" : "AWS::EC2::Route", "DependsOn" : "NATGateway", "Properties" : { "RouteTableId" : { "Ref" : "RouteTableforPrivate" }, "DestinationCidrBlock" : "0.0.0.0/0", "NatGatewayId" : { "Ref" : "NATGateway" } } }, "SubnetRouteTableAssociation1" : { "Type" : "AWS::EC2::SubnetRouteTableAssociation", "Properties" : { "SubnetId" : { "Ref" : "PublicSubnet" }, "RouteTableId" : { "Ref" : "RouteTableforPublic" } } }, "SubnetRouteTableAssociation2" : { "Type" : "AWS::EC2::SubnetRouteTableAssociation", "Properties" : { "SubnetId" : { "Ref" : "PrivateSubnet" }, "RouteTableId" : { "Ref" : "RouteTableforPrivate" } } }, "EC2SecurityGroup" : { "Type" : "AWS::EC2::SecurityGroup", "Properties" : { "VpcId" : { "Ref" : "VPC" }, "GroupDescription" : "No Inbound Rule Security Group", "GroupName" : "h4b-ec2-sg", "Tags" : [ {"Key" : "Name", "Value" : "h4b-ec2-sg" } ] } } } }