码迷,mamicode.com
首页 > 其他好文 > 详细

ansible一键部署NFS挂载

时间:2017-09-11 18:24:28      阅读:272      评论:0      收藏:0      [点我收藏+]

标签:ansible-nfs

 第1章 创建配置文件

1.1 编写创建密钥对和分发脚本

[root@m01 scripts]# cat /server/scripts/fenfa.sh

#!/bin/bash

## create key pair ##创建密钥对

ssh-keygen -t dsa -f /root/.ssh/id_dsa -P""

##fenfa ##非交互式分发到每台主机

for ip in 17 18 141

do

 echo"========fenfa key to host 172.16.1.$ip========="

sshpass -p123456 ssh-copy-id -i/root/.ssh/id_dsa.pub "-o StrictHostKeyChecking=no root@172.16.1.$ip"

echo "======================= end===================="

echo " "

echo " "

done

[root@m01 scripts]#

1.2 配置/etc/ansible/hosts文件

[root@m01 scripts]# tail -13 /etc/ansible/hosts

 [web]

172.16.1.17

172.16.1.18

[root@m01 scripts]#

1.3 编写配置脚本文件

[root@m01 ansible-playbook]# cat /server/scripts/nfspeizhi.sh

#!/bin/bash

cat  >>/etc/exports<< EOF

/data 172.16.1.0/24(rw,sync)

EOF

 

1.4 编写剧本

[root@m01 ansible-playbook]# cat /server/scripts/nfspeizhi.sh

#!/bin/bash

cat  >> /etc/exports<<EOF

/data 172.16.1.0/24(rw,sync)

EOF

[root@m01 ansible-playbook]# cat/etc/ansible/ansible-playbook/nfspeizhi.yml

- hosts: 172.16.1.141

  tasks:

  - name: yun

    shell: yum install -ynfs-utils rpcbind

  - name: chuangjianmulu

    shell: mkdir -p/server/tools/

  - name: peizhi

    copy:src=/server/scripts/nfspeizhi.sh dest=/server/tools/nfspeizhi.sh

  - name: yunxingjiaoben

    script:/server/scripts/nfspeizhi.sh

  - name: guanlimulu

    shell: mkdir -p /data&& chown -R nfsnobody.nfsnobody /data

  - name: qidong

    shell: /etc/init.d/rpcbindstart

  - name:

    shell: /etc/init.d/nfsstart

  - name: kaijiqidong

    shell: chkconfig rpcbindon  && chkconfig nfs on

- hosts: web

  tasks:

  - name: yumn

    shell: yum install -ynfs-utils rpcbind

  - name: guazai

    mount: name=/mntsrc=172.16.1.141:/data fstype=nfs state=mounted

[root@m01 ansible-playbook]#


ansible一键部署NFS挂载

标签:ansible-nfs

原文地址:http://2416402119.blog.51cto.com/13112195/1964267

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!