インストール
1 2 3 4 |
sudo apt update -y sudo apt install -y software-properties-common sudo apt-add-repository --yes --update ppa:ansible/ansible sudo apt install -y ansible |
バージョン確認
1 |
ansible-playbook --version |
Ansibleを流し込むマシンのauthorized_keysへ登録する
1 |
ssh-copy-id 128.22.133.120 |
公開鍵を指定する場合
- なんかエラーになった
1 |
cat ~/.ssh/vamdemickey.pem | ssh ec2-user@18.179.207.62 -i ~/.ssh/vamdemickey.pem "cat >> ./.ssh/authorized_keys" |
ansible用のhostsに実行先のIPアドレスを書く
/etc/ansible/hosts
1 2 |
[servers] 128.22.133.120 |
接続確認
1 |
ansible 128.22.133.120 -m ping |
1 2 3 4 5 6 7 |
128.22.133.120 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong" } |
playbookを作成
1 2 3 4 5 6 |
- hosts: servers tasks: - name: install the latest version of wget yum: name: wget state: latest |
実行
1 |
ansible-playbook wget.yaml |
1 2 3 4 5 6 7 8 9 10 11 |
PLAY [servers] ************************************************************************************************ TASK [Gathering Facts] **************************************************************************************** ok: [128.22.133.120] TASK [install the latest version of wget] ********************************************************************* ok: [128.22.133.120] PLAY RECAP **************************************************************************************************** 128.22.133.120 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignore d=0 |
参考
https://qiita.com/s-nishimaki/items/bd396b5ceaa9370d79c7