株式会社ヴァンデミックシステム

Blog

<スポンサーリンク>

インストール

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

 

バージョン確認

ansible-playbook --version

 

Ansibleを流し込むマシンのauthorized_keysへ登録する

ssh-copy-id 128.22.133.120

 

公開鍵を指定する場合

  • なんかエラーになった
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
[servers]
128.22.133.120

 

接続確認

ansible 128.22.133.120 -m ping
128.22.133.120 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}

 

playbookを作成

- hosts: servers
  tasks:
    - name: install the latest version of wget
      yum:
        name: wget
        state: latest

 

実行

ansible-playbook wget.yaml
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

<スポンサーリンク>

コメントを残す

Allowed tags:  you may use these HTML tags and attributes: <a href="">, <strong>, <em>, <h1>, <h2>, <h3>
Please note:  all comments go through moderation.

*

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)