๋ฌธ์ ์ ํ :
Bug Report
Ansible ๋ฒ์ :
ansible 2.0.0 (devel 2963bba901) last updated 2015/10/14 15:07:35 (GMT +300)
lib/ansible/modules/core: (devel 95b10c9fdd) last updated 2015/10/14 10:52:54 (GMT +300)
lib/ansible/modules/extras: (devel 15480e3d04) last updated 2015/10/14 10:52:56 (GMT +300)
config file = /etc/ansible/ansible.cfg
configured module search path = None
Ansible ๊ตฌ์ฑ :
ansible.cfg์ github ๋ฒ์ ์๋ ๋ฌธ์ ๊ฐ ์์ต๋๋ค.
ํ๊ฒฝ:
MacOSX ์์ธ๋ฏธํฐ 10.10.5
์์ฝ:
์ต๊ทผ ๊ฐ๋ฐ์์ ec2 ๋ชจ๋์ ์ฌ์ฉ์ด ์ค๋จ๋์์ต๋๋ค. ec2_module -page์ ๊ธฐ๋ณธ ์์ ๋ ์ฌ์ฉํ๋ ค๊ณ ํ๋ฉด ๋ค์ ๋ฉ์์ง๊ฐ ์์ฑ๋ฉ๋๋ค.
fatal: [localhost]: FAILED! => {"failed": true, "msg": "ERROR! module is missing interpreter line"}
๋ชจ๋ ์ต์ ์ด ๊ตฌ๋ฌธ ๋ถ์๋๊ธฐ ์ ์๋ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
์ปค๋ฐ 18e2ee16ef0895831ead312550eb5de44c99524c ์ดํ ๊ธฐ๋ฅ์ด ์์๋์์ต๋๋ค. ๊ทธ ์ปค๋ฐ์ด ec2 ๋ชจ๋์ ๋ง๊ฐ ๋จ๋ฆฐ ์ด์ ๋ฅผ ํด๋ ํ ์ ์์์ต๋๋ค.
์ฌํ ๋จ๊ณ :
- hosts: localhost
tasks:
- ec2:
key_name: mykey
instance_type: t2.micro
image: ami-123456
wait: yes
group: webserver
count: 3
vpc_subnet_id: subnet-29e63245
assign_public_ip: yes
์์ ๊ฒฐ๊ณผ :
ec2 ๋ชจ๋์ ์ด์ ์ฒ๋ผ ์๋ํด์ผํ๋ฉฐ ์ธ์คํด์ค ์์ฑ์ ํ์ฉํด์ผํฉ๋๋ค.
์ค์ ๊ฒฐ๊ณผ:
๋ค์ ์ค๋ฅ๊ฐ ์ธ์๋๊ณ ํ๋ ์ด ๋ถ ์คํ์ด ์ข ๋ฃ๋ฉ๋๋ค.
fatal: [localhost -> localhost]: FAILED! => {"failed": true, "msg": "ERROR! module is missing interpreter line"}
๋ณต์ ํ ์ ์์ต๋๋ค. ์ด ์ค๋ฅ๋ ๋ชจ๋์ ํ์ํ ๊ฒฝ๋ก๊ฐ ์์์ ๋ํ๋ด์ง ๋ง ์ค์ ๋ก๋ ์์ต๋๋ค. https://github.com/ansible/ansible-modules-core/blob/devel/cloud/amazon/ec2.py#L1
๊ฒฝ๋ก ๋ฌธ์ ๋ฐ / ๋๋ ์ค์ ๋ฌธ์ ๋๋ฌธ์ผ ์ ์์ต๋๋ค. ๋ค๋ฅธ ๋ชจ๋์์๋ ์ด๋ฐ ์ผ์ด ๋ฐ์ํฉ๋๊น?
OSX : 10.10.2
ํ ์คํธ ๋ HEAD :
PLAY ***************************************************************************
TASK [setup] *******************************************************************
ok: [localhost]
TASK [ec2 aws_secret_key=***** count=1 aws_access_key=****** group=All key_name=***** region=us-west-1 vpc_subnet_id=subnet-64e9d522 instance_type=t2.micro assign_public_ip=True image=ami-df6a8b9b wait=True] ***
changed: [localhost] => {"changed": true, "instance_ids": ["i-249c1196"], "instances": [{"ami_launch_index": "0", "architecture": "x86_64", "block_device_mapping": {"/dev/sda1": {"delete_on_termination": true, "status": "attached", "volume_id": "vol-c611fe3e"}}, "dns_name": "ec2-54-193-42-241.us-west-1.compute.amazonaws.com", "ebs_optimized": false, "groups": {"sg-f2953597": "All"}, "hypervisor": "xen", "id": "i-249c1196", "image_id": "ami-df6a8b9b", "instance_type": "t2.micro", "kernel": null, "key_name": "*****", "launch_time": "2015-10-20T05:02:16.000Z", "placement": "us-west-1a", "private_dns_name": "ip-172-31-10-161.us-west-1.compute.internal", "private_ip": "172.31.10.161", "public_dns_name": "ec2-54-193-42-241.us-west-1.compute.amazonaws.com", "public_ip": "54.193.42.241", "ramdisk": null, "region": "us-west-1", "root_device_name": "/dev/sda1", "root_device_type": "ebs", "state": "running", "state_code": 16, "tags": {}, "tenancy": "default", "virtualization_type": "hvm"}], "tagged_instances": []}
PLAY RECAP *********************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0
ํ ์คํธ ๋ ์ปค๋ฐ : 18e2ee16ef0895831ead312550eb5de44c99524c
PLAY ***************************************************************************
TASK [setup] *******************************************************************
ok: [localhost]
TASK [ec2 aws_secret_key=***** count=1 aws_access_key=*****group=All key_name=***** region=us-west-1 vpc_subnet_id=subnet-64e9d522 instance_type=t2.micro assign_public_ip=True image=ami-df6a8b9b wait=True] ***
changed: [localhost] => {"changed": true, "instance_ids": ["i-9d911c2f"], "instances": [{"ami_launch_index": "0", "architecture": "x86_64", "block_device_mapping": {"/dev/sda1": {"delete_on_termination": true, "status": "attached", "volume_id": "vol-7468878c"}}, "dns_name": "ec2-54-193-61-87.us-west-1.compute.amazonaws.com", "ebs_optimized": false, "groups": {"sg-f2953597": "All"}, "hypervisor": "xen", "id": "i-9d911c2f", "image_id": "ami-df6a8b9b", "instance_type": "t2.micro", "kernel": null, "key_name": "*****", "launch_time": "2015-10-20T05:21:45.000Z", "placement": "us-west-1a", "private_dns_name": "ip-172-31-5-245.us-west-1.compute.internal", "private_ip": "172.31.5.245", "public_dns_name": "ec2-54-193-61-87.us-west-1.compute.amazonaws.com", "public_ip": "54.193.61.87", "ramdisk": null, "region": "us-west-1", "root_device_name": "/dev/sda1", "root_device_type": "ebs", "state": "running", "state_code": 16, "tags": {}, "tenancy": "default", "virtualization_type": "hvm"}], "tagged_instances": []}
PLAY RECAP *********************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0
ํ๋ ์ด ๋ถ :
- hosts: localhost
connection: local
tasks:
- ec2:
aws_access_key: '*****'
aws_secret_key: '*****'
region: us-west-1
key_name: *****
instance_type: t2.micro
image: ami-df6a8b9b
wait: yes
group: All
count: 1
vpc_subnet_id: subnet-64e9d522
assign_public_ip: yes
๋ง์นจ๋ด ๋ฒ๊ทธ๋ฅผ ํด๊ฒฐํ์ต๋๋ค. ๋๋ '๋ผ์ด๋ธ๋ฌ๋ฆฌ'-๋๋ ํ ๋ฆฌ์ ec2.ini๋ฅผ ๊ฐ์ง๊ณ ์์๊ณ ์ด๋ค ์ด์ ๋ก ec2 ๋ชจ๋์ ์ฐพ์ ๋ ansible์ด ๊ทธ๊ฒ์ ์ ํํ์ต๋๋ค. ec2.ini์ ์ด๋ฆ์ ec2_dynamic_inventory.ini๋ก ๋ฐ๊พธ๊ณ 'export EC2_INI_PATH = library / ec2_dynamic_inventory.ini'๋ฅผ ์คํํ๋ฉด ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋์์ต๋๋ค.
์ฐธ๊ณ ๋ก ๋ค์์ด ๋๋ฝ ๋ ๊ฒฝ์ฐ์ด ์ค๋ฅ๊ฐ ๋ฐ์ํ ์ ์์ต๋๋ค.
#!/usr/bin/python
๋ชจ๋ ํ์ผ ์๋จ์ hashbang. ์๋ง๋ ์์ ์ ๋ชจ๋์ ๊ฐ๋ฐํ๋ ์ฌ๋๋ค์๊ฒ๋ง ๊ด๋ จ์ด์์ ๊ฒ์ ๋๋ค. ๊ทธ๋ฌ๋ ๊ทธ๊ฒ์ ๋๋ฅผ ๋์ด ๋จ๋ ธ๋ค!
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ฐธ๊ณ ๋ก ๋ค์์ด ๋๋ฝ ๋ ๊ฒฝ์ฐ์ด ์ค๋ฅ๊ฐ ๋ฐ์ํ ์ ์์ต๋๋ค.
๋ชจ๋ ํ์ผ ์๋จ์ hashbang. ์๋ง๋ ์์ ์ ๋ชจ๋์ ๊ฐ๋ฐํ๋ ์ฌ๋๋ค์๊ฒ๋ง ๊ด๋ จ์ด์์ ๊ฒ์ ๋๋ค. ๊ทธ๋ฌ๋ ๊ทธ๊ฒ์ ๋๋ฅผ ๋์ด ๋จ๋ ธ๋ค!