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