Centos安装Ansible及构建环境

共 2050字,需浏览 5分钟

 ·

2021-03-21 15:34

简介

现有2台虚机:104、105,在104上安装ansible环境,并通过104上的ansible远程在105安装docker!

安装Ansible

yum install -y http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

yum install ansible -y

ansible --version

设置虚机间的认证密钥

ssh-keygen

ssh-copy-id 172.16.10.105

ansible 172.16.10.105 -m ping


配置ansible主机hosts

vim /etc/ansible/hosts

[websrvs]
172.16.10.105

ansible 172.16.10.105 -m ping


部署docker的yml文件

- name: 检查用户
user: name=jeemp state=present
register: p

- name: 添加EPEL仓库
yum: name=epel-release state=present

- name: 安装基础软件
yum:
name:
- gcc
- gcc-c++
- libtool
- make
- automake
- autoconf
- pcre
- pcre-devel
- zlib
- zlib-devel
- openssl-devel
- vim

- name: 安装docker环境依赖
shell: sudo yum install -y yum-utils device-mapper-persistent-data lvm2 &&
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo &&
sudo yum install docker-ce docker-ce-cli containerd.io -y &&
sudo yum install docker-ce-18.06.3.ce containerd.io

- name: 启动docker服务
shell: systemctl enable docker.service && systemctl start docker

- name: 临时关闭 selinux
shell: "setenforce 0"
failed_when: false

- name: 永久关闭 selinux
lineinfile:
dest: /etc/selinux/config
regexp: "^SELINUX="
line: "SELINUX=disabled"

- name: 配置limits.
lineinfile: dest=/etc/security/limits.conf line={{ item }}
with_items:
- '* - nofile 65535'
- '* soft nofile 65535'
- '* hard nofile 65535'
ignore_errors: True

- name: 临时关闭swap
shell: swapoff -a
ignore_errors: yes

- name: 永久关闭swap
lineinfile:
dest: /etc/fstab
state: absent
regexp: "swap"
ignore_errors: true

- name: 关闭firewalld
service:
name: firewalld
state: stopped
enabled: false
ignore_errors: yes

- name: 关闭iptables
service:
name: iptables
state: stopped
enabled: false
ignore_errors: yes

执行ansible剧本

ansible-playbook xxx.yml

可以去105验证docker是否安装成功


浏览 25
点赞
评论
收藏
分享

手机扫一扫分享

分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

分享
举报