当前位置: 首页> 教育> 就业 > ansible2

ansible2

时间:2025/7/11 1:10:14来源:https://blog.csdn.net/weixin_69088860/article/details/141333280 浏览次数:0次

自动化运维工具ansible

  1. yum环境与相关安装包的安装

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo

yum clean all

yum makecache

yum -y install epel-release

yum -y install ansible

ansible --version

  1. 编写主机清单文件、配置免密登录、测试连通性

vim /etc/ansible/hosts

[a01]

192.168.110.21

[b02]

192.168.110.21

192.168.110.20

#免密

ssh-keygen

ssh-copy-id -i 192.168.110.21

ssh-copy-id -i 192.168.110.20

ansible-doc -l | wc -l    //产看ansible可用模块数量

3387

  1. file模块

可以创建目录、文件

常用参数:path:路径、owner:属主、group:属组、mode:权限、state:执行的动作 absent:删除、direvtory:目录

  1. 安装vsftpd

Vim vs.yml

---

-       hosts:          s

        remote_user:    root

        tasks:

        -       name:   卸载vsftp

                yum:    name=vsftpd     state=absent

        -       name:   安装vsftpd

                yum:    name=vsftpd     state=latest

        -       name:   启动服务

                service:        name=vsftpd     state=started   enabled=yes

        -       name:   修改配置文件

                command:        sed -i '/^anonymous_enable=YES/s/YES/NO/g' /etc/vsftpd/vsftpd.conf

                notify:

                -       abcdefg

        handlers:

                -       name:   abcdefg

                        service:        name=vsftpd     state=restarted

5、安装nfs-utils、rpcbind、

---

-       hosts:          s1

        remote_user:    root        

        tasks:

        -       name:   安装nfs-utils

                yum:    name=nfs-utils  state=present

        -       name:   安装rpcbind

                yum:    name=rpcbind    state=present

        -       name:   创建共享目录

                file:   path=/static   state=directory

        -       name:   配置文件

                shell:  echo '/static    *(ro,sync)' > /etc/exports

                notify:

                -       rstss

        -       name:           启动服务nfs

                service:        name=nfs        state=started enabled=yes

        -       name:           启动服务rpcbind

                service:        name=rpcbind    state=started enabled=yes

        handlers:

                -       name:   rstss

                        service:        name=nfs state=restarted

-       hosts:  s2

        remote_user:    root

        tasks:

        -       name:   安装nfs-utils

                yum:    name=nfs-utils   state=latest

        -       name:   创建挂载目录

                file:   path=/nfs   state=directory

        -       name:   挂载nfs文件

                command:        mount -t nfs 192.168.71.178:/static /nfs

关键字:ansible2

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: