[EC2側]
まず、EC2を起動し、ターミナルからssh接続
$ ssh ec2-user@**** -i ~/.ssh/***.pem
$ cd /home/release
$ ls
LICENSE appspec.yml index.html scripts
[vagrant側]
.ssh/、inventory/hostsを作成済み
/hosts
[targets] **.***.**.**
今回デプロイするtest.htmlを作成する
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> ansible deploy test </body> </html>
$ ls
LICENSE appspec.yml index.html inventory playbook.yml scripts test.html
playbook.yml
- hosts: targets sudo: yes tasks: - name: put test.html copy: src=test.html dest=/home/release/ owner=root group=root mode=640
### デプロイ実行
$ ansible-playbook -i inventory/hosts –private-key=.ssh/***.pem playbook.yml -u ec2-user
PLAY [targets] *****************************************************************
TASK [Gathering Facts] *********************************************************
ok: [**.***.**.**]
TASK [put test.html] ***********************************************************
changed: [**.***.**.**]
PLAY RECAP *********************************************************************
**.***.**.** : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
### EC2側で確認
$ ls
LICENSE appspec.yml index.html scripts test.html
$ sudo cat test.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> ansible deploy test </body> </html>
playbook.ymlは、デプロイする場合は、copy: src=${source file} dest=${dest directory} owner=root group=root mode=640 でOK
test.htmlを修正して、再度ansible-playbookを叩いた場合でも、EC2側で反映されていることが確認できます。