CentOS 6.5安装自动化工具Ansible和图形化工具Tower

一、CentOS 6.5安装ansible并测试

1、查看系统版本:

[root@ansible-server etc]# lsb_release -a

LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch

Distributor ID: CentOS

Description:    CentOS release 6.5 (Final)

Release:        6.5

Codename:      Final

2、安装ansible配置yum配置

163源

[root@ansible-server yum.repos.d]# vi CentOS-Base.repo

[163base]

name=CentOS-$releasever - Base - 163.com

baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os

gpgcheck=1

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#released updates

[163updates]

name=CentOS-$releasever - Updates - 163.com

baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates

gpgcheck=1

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful

[163extras]

name=CentOS-$releasever - Extras - 163.com

baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras

gpgcheck=1

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

epel源

[root@ansible-server yum.repos.d]# cat epel.repo

[epel]

name=CentOS-$releasever - epel

baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/6/x86_64/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os

gpgcheck=0

3、安装ansible

[root@ansible-server ~]# yum install ansible

4、ansible安装后测试

测试机器作为被控制端为SUSE11的虚拟机

查看配置文件

[root@ansible-server ~]# cd /etc/ansible/

[root@ansible-server ansible]# ls

ansible.cfg  hosts  roles

配置ansible hosts文件

[root@ansible-server ansible]# vi hosts

[slave]

192.168.1.210  ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass=suse

说明:

上面分别是被控制端IP地址、登陆用户名、ssh协议端口以及登陆密码

PING测试:

[root@ansible-server ansible]# ansible slave -m ping

paramiko: The authenticity of host '192.168.1.210' can't be established.

The ssh-rsa key fingerprint is 3eddc40386a9465452b12910a61a3c65.

Are you sure you want to continue connecting (yes/no)?

yes

192.168.1.210 | SUCCESS => {

"changed": false,

"ping": "pong"

第一次登陆还需要手动输入“yes”添加信任,如果避免这一步的话也可以,需要配置ansible的配置文件ansible.cfg

hosts文件再添加一台机器

[root@ansible-server ansible]# vi hosts

[slave]

192.168.1.210  ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass=suse

192.168.1.211  ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass=suse

修改配置文件,打开host_key_checking这一行的注释

[root@ansible-server ansible]# vi ansible.cfg

#host_key_checking = False

host_key_checking = False

测试如下所示

[root@ansible-server ansible]# ansible 192.168.1.211 -m ping

192.168.1.211 | SUCCESS => {

"changed": false,

"ping": "pong"

第一次登陆不需要手动输入

二、安装tower

1、资源下载

https://www.ansible.com/license

此链接下载免费控制10个机器的授权,需要填写邮箱等信息,授权文件会发到你的邮箱,安装tower后登陆到web界面添加授权文件就可以开始你的tower之旅了

https://www.ansible.com/tower-trial

此链接是下载免费测试的tower安装引导文件,叫做安装引导文件是我自己想出的名字,因为安装tower是由一大堆的ansible-playbook文件组合到一块去取网络资源安装的

2、解压缩tower引导文件

[root@ansible-server ~]# cd /home/ansible/

[root@ansible-server ansible]# ls

ansible-tower-setup-latest.tar.gz

[root@ansible-server ansible]# tar zxf ansible-tower-setup-latest.tar.gz

[root@ansible-server ansible]# cd ansible-tower-setup-3.0.3/

[root@ansible-server ansible-tower-setup-3.0.3]# ls

ansible.cfg  group_vars  inventory  README.md    roles

backup.yml  install.yml  licenses  restore.yml  setup.sh

3、配置安装tower的yum源

以centos系统默认的yum源替代163的yum源

[root@ansible-server yum.repos.d]# vi CentOS-Base.repo

[base]

name=CentOS-$releasever - Base

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os

#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#released updates

[updates]

name=CentOS-$releasever - Updates

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates

#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful

[extras]

name=CentOS-$releasever - Extras

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras

#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

epel源不变

4、部署tower

解压缩软件包

tar -zxf ansible-tower-setup-latest.tar.gz

设置主机信息

[root@ansible-server ansible]# cd ansible-tower-setup-3.0.3/

[root@ansible-server ansible-tower-setup-3.0.3]# ll

total 64

-rw-rw-r--.  1 1004 1004  203 Oct 31 21:58 ansible.cfg

-rw-rw-r--.  1 1004 1004  128 Oct 31 21:58 backup.yml

drwxrwxr-x.  2 1004 1004  4096 Oct 31 21:58 group_vars

-rw-rw-r--.  1 1004 1004  4781 Oct 31 21:58 install.yml

-rw-rw-r--.  1 1004 1004  194 Oct 31 21:58 inventory

-rw-r--r--.  1 root root  194 Dec 26 21:24 inventory.bak

drwxrwxr-x.  2 1004 1004 12288 Oct 31 21:58 licenses

-rw-rw-r--.  1 1004 1004  2510 Oct 31 21:58 README.md

-rw-rw-r--.  1 1004 1004  233 Oct 31 21:58 restore.yml

drwxrwxr-x. 18 1004 1004  4096 Oct 31 21:58 roles

-rwxrwxr-x.  1 1004 1004  9461 Oct 31 21:58 setup.sh

[root@ansible-server ansible-tower-setup-3.0.3]# sed -i "s#password=''#password='admin'#g" inventory

[root@ansible-server ansible-tower-setup-3.0.3]# sed -i "s#host=''#host='127.0.0.1'#g" inventory

[root@ansible-server ansible-tower-setup-3.0.3]# sed -i "s#port=''#port='5432'#g" inventory

配置软件源

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/14215.html