您好,登錄后才能下訂單哦!
注意三臺都需要聯網
我的是80.100、80.101、80.102
我是在80.100上操作的其他兩臺只要開著就行了不需要操作
yum install -y epel-release //安裝epel源
yum install ansible -y
ansible --version //查看ansible版本
yum install tree -y
cd /etc/ansible
vi hosts //配置主機清單
最后一行添加
[web]
192.168.80.10[1:2]
ansible all --list-hosts 顯示所有已定義的主機
ssh-keygen -t rsa
ssh-copy-id root@192.168.80.101
ssh-copy-id root@192.168.80.102
ansible all -a 'systemctl stop firewalld'
ansible all -a 'setenforce 0'
mkdir -p /opt/roles/nginx/{tasks,templates}
cd /opt/roles/nginx/tasks/
vi epel.yml
- name: copy epel
copy: src=/etc/yum.repos.d/ dest=/etc/yum.repos.d/
vi user.yml
- name: create user
user: name=nginx group=nginx system=yes shell=/sbin/nologin
vi group.yml
- name: create group
group: name=nginx system=yes
vi yum.yml
- name: install package
yum: name=nginx
vi start.yml
- name: start service
service: name=nginx state=restarted enabled=true
vi restart.yml
- name: restart service
service: name=nginx state=restarted
cd ../templates/
yum install -y nginx
cp /etc/nginx/nginx.conf nginx.conf.j2
vi nginx.conf.j2
worker_processes {{ ansible_processor_vcpus }};
cd ../tasks/
vi temp.yml
- name: copy conf file
template: src=nginx.conf.j2 dest=/etc/nginx/nginx.conf
vi main.yml
- include: epel.yml
- include: group.yml
- include: user.yml
- include: yum.yml
- include: temp.yml
- include: start.yml
cd /etc/ansible/
vi nginx_role.yml
- hosts: web
remote_user: root
roles:
- role: nginx
tree roles/
mkdir -p /etc/ansible/group_vars/
touch /etc/ansible/group_vars/all
mkdir -p /etc/ansible/roles/common
mkdir -p /etc/ansible/roles/httpd/{files,templates,tasks,handlers,vars,defaults,meta}
mkdir -p /etc/ansible/roles/mysql/{files,templates,tasks,handlers,vars,defaults,meta}
mkdir -p /etc/ansible/roles/php/{files,templates,tasks,handlers,vars,defaults,meta}
touch /etc/ansible/roles/httpd/{defaults,vars,tasks,meta,handlers}/main.yml
touch /etc/ansible/roles/mysql/{defaults,vars,tasks,meta,handlers}/main.yml
touch /etc/ansible/roles/php/{defaults,vars,tasks,meta,handlers}/main.yml
vi /etc/ansible/site.yml
- hosts: web
remote_user: root
roles:
- httpd
- mysql
cd /opt/
vi nginx.yml
- hosts: web
remote_user: root
roles:
- role: nginx
ansible web -a "rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm"
ansible-playbook nginx.yml
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。