Posted at

ansibleで遊んだplaybookメモ

More than 1 year has passed since last update.

用途としては違うだろうけど、複数のEC2でのファイル同期をS3を介してansibleでもできそうだなあ


playbook.yaml

- hosts: all

remote_user: ec2-user
gather_facts: no
tasks:
- name: yum install net tools
become: yes
become_user: root
yum: name="net-tools" state=present

- name: install pip
become: yes
become_user: root
shell: easy_install pip && easy_install --upgrade pip

- name: install boto3
become: yes
become_user: root
shell: pip install boto3
register: result

- name: config dir
become: yes
become_user: ec2-user
file:
path: ~/.aws
state: directory

- name: setup region for boto3
shell: echo "[default]" > ~/.aws/config
- name: setup region for boto3
shell: echo "region = ap-northeast-1" >> ~/.aws/config

- name: sync s3
shell: aws s3 sync s3://bucket ~/s3


ansible面白かった。

$ ansible-playbook playbook.yaml  --private-key ~/AWS/secret/private-aws.pem

PLAY [all] ******************************************************************************************

TASK [yum install net tools] ************************************************************************
ok: [54.250.161.68]

TASK [install pip] **********************************************************************************
changed: [54.250.161.68]

TASK [install boto3] ********************************************************************************
changed: [54.250.161.68]

TASK [config dir] ***********************************************************************************
ok: [54.250.161.68]

TASK [setup region for boto3] ***********************************************************************
changed: [54.250.161.68]

TASK [setup region for boto3] ***********************************************************************
changed: [54.250.161.68]

TASK [sync s3] **************************************************************************************
changed: [54.250.161.68]

PLAY RECAP ******************************************************************************************
54.250.161.68 : ok=7 changed=5 unreachable=0 failed=0