å ¨å½1å人ã®ãµã¼ãã¼ã¯ã¼ã¯ã¹ãã¡ã³ã®çãã¾ãåãã¾ãã¦ã2015å¹´10æã«å ¥ç¤¾ãã¾ããæ³äººå¶æ¥èª²ã½ãªã¥ã¼ã·ã§ã³ã¢ã¼ããã¯ã(試ç¨æéä¸)ã®æµ¦åº(@urasoko)ã¨ç³ãã¾ãã試ç¨æéä¸ã®ããã«ããã°ãæ¸ããã¨ä¸æ¸ããå¯ããã¦ãããã人äºã«ã課é·ã«ãå ã«åºããã¦ãã¾ãã¾ãããããããã§ããããããã©ãããææããã«ãããããé¡ããããã¾ãã
Chefã£ã¦
ãã¦ãåçªã§ããã¿ãªãããChefã£ã¦ãåç¥ã§ããããããã§ããã®Chefã§ãã説æã¯ããã§ã¯çãã¾ãã
ãµã¼ãã¼ã¯ã¼ã¯ã¹ãSlackãå°å ¥ãã¦ããã®ã¯çãã¾ãåç¥ãã¨æãã¾ããããã« #chef_study ã£ã¦ãã£ã³ãã«ããã£ãããã§ããããããããªãã¨ã¡ã³ãã¼ãã¼ãã ã£ãããã§ãããã¼ãã
ããããããPreviewãã¦ã¿ãã¨2014å¹´9æã§æ´æ°ãæ¢ã¾ã£ã¦ãã¨ãããªãã¨ã
Chefã¯ãããªã¯ã³ã³ãªã®ã
ããããã°ãã12æã§ããã12æã¨ããã°Advent Calendarã§ããã試ãã«Chefã§Advent Calendaræ¤ç´¢ããã2014å¹´ã®ããããã«åºã¦ããããã§ããããã
Chefã¯ãã¯ããªã¯ã³ã³ãªã®ã
é話ä¼é¡(æ¸ãããã£ãã ã)
ãã¦ããããªãæä¸ã§ãããæ¬æ¥ã¯chef-provisioning-awsããç´¹ä»ãããã¾ãã
Chef Provisioningã£ã¦
ã¾ããChefã¨ããã°åç¬ã®Node(EC2ã§ããã°ã¤ã³ã¹ã¿ã³ã¹)ã«å¯¾ããchef-clientåããããªã«èªååãã¦ãããã¨ãããç解ãçãã¾ãæã¡ã¨æãã¾ãããã以ä¸ã®èª¬æã¯ããã§ã¯çãã¾ããããµã«ãªãåãä»ãã¾ããã
ããã«ãä»åã®chef-provosioning-awsã®åã«chef-provisioningã説æããªãã¨ãããªãã®ã§ããããã¡ãã¯ä¸è¨ã®åç¬Nodeã«å¯¾ããèªååã®ä¸æ®µä¸å±¤ã§åä½ãããã¬ã¼ã ã¯ã¼ã¯ã§ããããªãã¡è¤æ°Nodeã®ã¯ã©ã¹ã¿ãªã³ã°ã®èªååãå®ç¾ãã¾ãããã以ä¸ã®èª¬æã¯ããã§ã¯çãã¾ã(以ä¸åæ
ã§ããã以ä¸ã«chef-provisioningã®è¯ãã¨ããã2ç¹ããã¾ããã¾ãã¯Nodeã®ä¸å±¤ã§å®ç¾ãããè¦æ±ãå®è£ ã§ããã¨ããã¨ãããä¾ãã°ãNodeéã®ç¸äºé¢é£ããé¢é£ã¥ããããã®æ¦å¿µã®äºåå®ç¾©ãé¢é£ãç´ä»ããããã®å½¹å²ã®äºå¾å¦çãªã©ãªã©ã
ããä¸ã¤ã¯ãã®å¦çè¦æ±ãChefã®ãã¬ã¼ã ã¯ã¼ã¯å ã¨ãããããRubyã§å®è£ å¯è½ãªã¨ããã§ããã¤ã¾ãAWSã§ããã°aws-sdk-rubyãèªå¨ã«æ´»ç¨å¯è½ã¨ããã¨ããã§ããä¸ã¤ç®ã®å©ç¹ã«éããã¨VPCä½ã£ã¦Subnetå®ç¾©ãã¦ããMulti Availability Zoneã«ã¤ã³ã¹ã¿ã³ã¹èµ·åãã¦ãæå¾ã«ELBã«ã¶ãä¸ããã¿ãããªã
Chef Provisioning AWSã£ã¦
ç¾ã«chef-provisioning-awsã«æ¨æºã§ç¨æããã¦ããAWS Driver Resourceã«ã¯ä»¥ä¸ã®ãããªãã®ãããã¾ãã
- aws_auto_scaling_group
- aws_cache_cluster
- aws_cache_replication_group
- aws_cache_subnet_group
- aws_cloudsearch_domain
- aws_dhcp_options
- aws_ebs_volume
- aws_eip_address
- aws_image
- aws_instance
- aws_internet_gateway
- aws_key_pair
- aws_launch_configuration
- aws_load_balancer
- aws_network_acl
- aws_network_interface
- aws_rds_instance
- aws_rds_subnet_group
- aws_route_table
- aws_s3_bucket
- aws_security_group
- aws_server_certificate
- aws_sns_topic
- aws_sqs_queue
- aws_subnet
- aws_vpc
Resourceåããåããã¨ãããComputing以å¤ã®AWSãªã½ã¼ã¹ãæ±ãããã¨ããåãããã¨æãã¾ããã¾ããchef-provisioningã®æ¨æºResourceã®ãã¡ãload_balancerã¯ELBãAWS Driverã«ã¦å®è£ ãã¦ãã¾ãã
ä½è«ã§ãããä¸è¨ã®ã¨ããæ¨ä»ã®ãã¬ã¼ã ã¯ã¼ã¯ã«å¤ããå®è£ ãPlugin/Driverã«å§ãããã¨ã§æ½è±¡åã¨èªç±åº¦ãé«ãããã¬ã¼ã ã¯ã¼ã¯ã§ããAWS Driver Resourceã®ç¨®é¡ãè±å¯ãªã®ããã®æ©æµã«ä¾ãã¨ãããããã¨æãã¾ãã
試ãã¦ã¿ã
ã¨ããããæã£åãæ©ã試ãã¦ã¿ãã¨ããã¾ã§ã
chef-provisioningã¯chef-clientã®local modeã§åä½ãã¾ãã®ã§ãå®è¡ããã«ã¯chef-clientãå¿ è¦ã§ããä»ã¯ChefDKããã±ã¼ã¸ã«chef-provisioningãchef-provisioning-awsã(ãã®ä»è«¸ã ããâ¦ä»¥ä¸ç¥)å ¥ã£ã¦ã¾ãã®ã§è¯ããã°ã©ããã
ä»åã¯âã®ãããªã³ã¼ãã試ãã¦ã¿ã¾ãã
ä¸ãããVPCæã£ã¦ãSubnetåãã¦ãRDSã¤ã³ã¹ã¿ã³ã¹ä¸ãã¦ãEC2ã¤ã³ã¹ã¿ã³ã¹2åããã¦ãELBããã¦ã¤ã³ã¹ã¿ã³ã¹2åã¶ãä¸ããæãã§ããæ¬æ¥ãªãNACLãSecurity Groupã®è¨å®ãªã©ãªã©ç´°ãããããã¨ãããªãã®ã§ãããä»åã¯åãããããã®ããã«çãã¦ã¾ã(ãã¡ããè¨å®ã¯å¯è½ã§ã)ã
å®è¡ãã¦ã¿ãã¨âãªæãã«æµãã¾ãã
mbp:chef-provisioning-aws ura$ chef-client -z chef-prov-test.rb [2015-12-28T09:59:27+09:00] WARN: No config file found or specified on command line, using command line options. Starting Chef Client, version 12.5.1 resolving cookbooks for run list: [] Synchronizing Cookbooks: Compiling Cookbooks... Converging 7 resources Recipe: @recipe_files::/Users/ura/swx/chef-provisioning-aws/chef-prov-test.rb * aws_vpc[test-vpc] (vpc-9ed44efb) action create - waited 0/300s for #state state to change to [:available]... - create VPC test-vpc in ap-northeast-1 - update data bag item test-vpc at chefzero://localhost:8889 - update reference.id from "vpc-9ed44efb" to "vpc-20d54f45" - attach vpc vpc-20d54f45 to igw-3d248558 - create internet gateway igw-managed-by-vpc-20d54f45 in region ap-northeast-1 - create data bag item igw-managed-by-vpc-20d54f45 at chefzero://localhost:8889 - add reference = {"id"=>"igw-3d248558"} - add driver_url = "aws::ap-northeast-1" - creating tags {"OwnedByVPC"=>"vpc-20d54f45"} - route 0.0.0.0/0 to internet_gateway (igw-3d248558) * aws_subnet[test-subnet-a] (subnet-f7641c80) action create - create subnet test-subnet-a with CIDR 10.0.0.0/26 in VPC test-vpc (vpc-20d54f45) in ap-northeast-1 - update data bag item test-subnet-a at chefzero://localhost:8889 - update reference.id from "subnet-f7641c80" to "subnet-a5641cd2" - turn on automatic public IPs for subnet subnet-a5641cd2 * aws_subnet[test-subnet-c] (subnet-1167f748) action create - create subnet test-subnet-c with CIDR 10.0.0.64/26 in VPC test-vpc (vpc-20d54f45) in ap-northeast-1 - update data bag item test-subnet-c at chefzero://localhost:8889 - update reference.id from "subnet-1167f748" to "subnet-c267f79b" - turn on automatic public IPs for subnet subnet-c267f79b * aws_rds_subnet_group[test-db-subnet] action create - create RDS subnet group test-db-subnet in ap-northeast-1 * aws_rds_instance[test-rds] action create - create RDS instance test-rds in ap-northeast-1 * machine_batch[default] action allocate - create chef_default on aws::ap-northeast-1 from local key at - creating machine machine2 on aws::ap-northeast-1 - max_count: 1 - min_count: 1 - instance_type: "t2.micro" - image_id: "ami-d3a194bd" - key_name: "chef_default" - subnet_id: "subnet-c267f79b" - creating machine machine1 on aws::ap-northeast-1 - max_count: 1 - min_count: 1 - instance_type: "t2.micro" - image_id: "ami-d3a194bd" - key_name: "chef_default" - subnet_id: "subnet-a5641cd2" - machine machine1 created as i-7f4503da on aws::ap-northeast-1 - [machine1] update node machine1 at chefzero://localhost:8889 - [machine1] update normal.chef_provisioning.reference.allocated_at from "2015-12-25 12:35:25 UTC" to "2015-12-28 00:59:52 UTC" - [machine1] update normal.chef_provisioning.reference.instance_id from "i-5a6025ff" to "i-7f4503da" - machine machine2 created as i-a276d12d on aws::ap-northeast-1 - [machine2] update node machine2 at chefzero://localhost:8889 - [machine2] update normal.chef_provisioning.reference.allocated_at from "2015-12-25 12:35:24 UTC" to "2015-12-28 00:59:52 UTC" - [machine2] update normal.chef_provisioning.reference.instance_id from "i-2ae94ca5" to "i-a276d12d" * load_balancer[test-elb] action create - create load balancer test-elb in ap-northeast-1 - attach subnets #, # - with listeners [{:port=>80, :protocol=>:http, :instance_port=>80, :instance_protocol=>:http}] - add machines machine1, machine2 - update data bag item test-elb at chefzero://localhost:8889 - update reference.allocated_at from "2015-12-25 12:49:43 UTC" to "2015-12-28 00:59:53 UTC" Running handlers: Running handlers complete ...(ç¥)... Chef Client finished, 7/7 resources updated in 26 seconds
ããã«ä»åã¯ãmachine_batch Resourceã®é¨åã§ã¤ã³ã¹ã¿ã³ã¹ã®èµ·åã®ã¿(action :allocate)ãæå®ãã¾ããããããã§Chefã®Recipeãå®è¡ãããã¨ãå¯è½ã§ããããã§AWSã®å種ãµã¼ãã¹ã¨EC2ã¤ã³ã¹ã¿ã³ã¹ã¸ã®ããã«ã¦ã§ã¢ãããã¸ã§ãã³ã°ãé£æºããããã¨ãå¯è½ã§ãã
ã¨ããã®ä»ã«ãããããæ¸ããããã¨ã¯ããã®ã§ãããç¶ãã¯å¹´æãã«ã§ãã
ããã§ã¯çãããè¯ããå¹´ãã