安裝
rpm -Uvh https://mirrors.zju.edu.cn/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum install -y ansible
配置hosts
vi /etc/ansible/hosts
aly ansible_ssh_port=10011 ansible_ssh_host=127.0.0.1
kaiping ansible_ssh_port=10013 ansible_ssh_host=127.0.0.1
hosts一些參數
ansible_ssh_host
#用于指定被管理的主機的真實IP
ansible_ssh_port
#用于指定連接配接到被管理主機的ssh端口号,預設是22
ansible_ssh_user
#ssh連接配接時預設使用的使用者名
ansible_ssh_pass
#ssh連接配接時的密碼
ansible_python_interpreter
#用來指定python解釋器的路徑,預設為/usr/bin/python 同樣可以指定ruby 、perl 的路徑
執行指令,說明:all 是是以都執行,可以改成組名
ansible all -m command -a 'mkdir -p /usr/local/nba'
執行複制
ansible all -m copy -a "src=/usr/local/1.txt dest=/usr/"
驗證
ansible all -a "ls /usr/"
定義cron任務
ansible all -m cron -a'name="custom job" minute=*/3 hour=* day=* month=* weekday=* job="/usr/sbin/ntpdate
ansible all -a "crontab -l"
yum安裝
ansible all -m yum -a "state=present name=nload"
ansible all -a "rpm -qa nload"
啟動服務
ansible all -m service -a "state=started name=httpd enabled=yes"
ansible all -m command -a 'rpm -Uvh https://mirrors.zju.edu.cn/epel/6/x86_64/epel-release-6-8.noarch.rpm'