环境
系统:CentOS 6.8
Ansible安装
# yum install epel-release
# yum install ansible
Ansible配置
- 配置主文件
# vim /etc/ansible/ansible.cfg
inventory = /etc/ansible/inventory
roles_path = /data/ansible/roles
remote_user = root
- 创建文件夹
# mkdir -p /etc/ansible/inventory
# mkdir -p /data/ansible/playbooks
# mkdir -p /data/ansible/roles
# rm -rf /etc/ansible/host
# rm -rf /etc/ansible/roles
- 配置inventory
# vim /etc/ansible/inventory/lvs_list
[group]
host1
host2
- 设置密码登陆参数
# vim /etc/ansible/inventory/lvs_list
[group:vars]
ansible_ssh_user=
ansible_ssh_pass=
ansible_sudo_pass=
Ansible Ad-Hoc
- 对group组,使用shell模块,执行hostname命令
# ansible group -m shell -a 'hostname'
Ansible Playbook
- 配置Playbook
# vim /data/ansible/playbooks/centos-os-init.yml
---
- hosts: group
tasks:
- name: upgrade all packages
yum:
name: '*'
state: latest
- name: reboot
shell: init 6
- 执行Playbook
# ansible-playbook /data/ansible/playbooks/centos-os-init.yml
网友评论