LoginSignup
14
14

More than 5 years have passed since last update.

ansible導入してみた

Last updated at Posted at 2013-10-14

macの場合

sudo easy_install ansibleで失敗する場合は以下でeasy_installのバージョンを更新するとよい。

curl http://python-distribute.org/distribute_setup.py | sudo python
ansible実行
% ansible all -m ping
127.0.0.1 | success >> {
    "changed": false, 
    "ping": "pong"
}
ホストの追加
% ssh-copy-id 192.168.11.4
% echo 192.168.11.4 >> ~/ansible_hosts
% ansible all -m ping
192.168.11.4 | success >> {
    "changed": false, 
    "ping": "pong"
}

127.0.0.1 | success >> {
    "changed": false, 
    "ping": "pong"
}

playbookを作る

hosts
[srv]
192.168.11.4
localhost.yml
- hosts: srv
  user: root
  become: yes

  tasks:
    - apt: pkg=mysql-server state=present
    - apt: pkg=mysql-client state=present
    - apt: pkg=python-pip state=present
    - apt: pkg=python-dev state=present
    - apt: pkg=python-mysqldb state=present
    - copy: src="etc/mysql/my.cnf" dest="/etc/mysql/my.cnf" owner=root group=root mode=0644
    - service: name=mysql state=restarted
run.sh
if [ ! -e /usr/sbin/ansible-playbook ];then
    sudo apt install -y ansible
fi
ansible-playbook -i hosts main.yml  -v
適用
sh run.sh
14
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
14