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'

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目录


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
ansible all -m copy -a 'cp -r /root/docker.sh  /root/'
ansible all -m script  -a 'chmod +x docker.sh && bash docker.sh'

你可能感兴趣的:(linux,问题汇总,ansible)