• ansible的个人笔记使用记录-个人心得总结


    1.shell模块使用,shell模块------执行命令,支持特殊符

    ansible all -m shell  -a 'yum -y install nginx'
    ansible all -m shell  -a 'systemctl restart nginx'
    ansible all -m shell  -a ' systemctl stop nginx && yum -y remove nginx'
    
    • 1
    • 2
    • 3

    2. file模块,file模块------创建文件,目录等

    ansible all -m file -a 'path=/home/mqq state=directory'  #指定目录在/home目录下创建
    ansible all -m file -a 'path=mqq state=directory'  #默认在/root目录下创建
    ansible all -m shell  -a 'rm -fr /home/mqq' #删除/home下的目录mqq
    ansible all -a "ls -ld /root/mqq" #查看目录和目录的属性
    ansible all -m file -a 'path=/root/mqq/body.txt state=touch'  #创建一个空文件
    ansible all -m shell  -a 'ls -l /root/mqq/body.txt' 
    ansible all -m file -a 'src=/root/mqq/  path=/tmp/maqq  state=link' #创建快捷方式
    
    
    ansible all -m file -a 'path=/root/mqq/body.txt state=absent' #删除/root/mqq下的这个文件body.txt
    ansible all -m file -a 'path=/root/mqq state=absent' #删除/root下的mqq目录
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    2. script模块使用,script模块------分发脚本并执行

    vim  docker.sh #写入脚本
    #!/bin/bash
    #centos7 安装docker脚本
    
    
    systemctl stop docker
    yum remove docker \
                      docker-client \
                      docker-client-latest \
                      docker-common \
                      docker-latest \
                      docker-latest-logrotate \
                      docker-logrotate \
                      docker-selinux \
                      docker-engine-selinux \
                      docker-engine \
                      docker-ce
    
    
    rm -rf /etc/docker
    rm -rf /run/docker
    rm -rf /var/lib/dockershim
    rm -rf /var/lib/docker
    
    
    systemctl stop firewalld # 关闭
    systemctl disable firewalld # 禁止开机启动防火墙
    sed -i 's/enforcing/disabled/' /etc/selinux/config # 永久
    setenforce 0 # 临时
    yum install -y yum-utils device-mapper-persistent-data lvm2 wget curl
    
    wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
    
    yum-config-manager \
        --add-repo \
        https://download.docker.com/linux/centos/docker-ce.repo
        
    
    #yum list docker-ce --showduplicates | sort -r #查看yum仓库中可以安装的docker版本
    #yum -y install docker-ce-18.06.1.ce-3.el7 #安装指定的版本
    yum -y install docker-ce docker-ce-cli containerd.io #安装最新docker
    systemctl enable docker
    systemctl restart docker
    systemctl status docker
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    ansible all -m copy -a 'cp -r /root/docker.sh  /root/'
    ansible all -m script  -a 'chmod +x docker.sh && bash docker.sh'
    
    • 1
    • 2
  • 相关阅读:
    ResizeObserver观察元素宽度的变化
    MySQL的DDL语句
    Redis 是什么?
    万万没想到,我用文心一言开发了一个儿童小玩具
    Rust编程-泛型、Trait和生命周期
    VulnHub Metasploitable-2
    FRP之入门篇
    react的1.函数组件2.usestate3.useeffect4.ref5.fragment6.contex 代码加注释
    WebKit Insie: Active 样式表
    Spring IOC/DI和MVC及若依对应介绍
  • 原文地址:https://blog.csdn.net/qq_14910065/article/details/133035679