1.Ansible ubuntu安装记录

研究这个的目的是每个项目都需要安装一套甚至几套环境,所以想搞一些自动化配置提高效率

一、Ansible 简介

基于python开发的自动化运维工具,可以批量系统配置、批量程序部署、批量运行命令

二、安装

有两种安装方式,任选其一即可:
1.用python 包管理工具 pip 安装
2.用操作系统自带的包管理工具(yum、apt)安装

系统版本:

username@test:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04 LTS
Release:        20.04
Codename:       focal

1 pip 安装

默认ubuntu上未安装pip,所以需要先安装pip

1.1 安装pip

  1. 查看python3是否存在
username@test:~# python3 --version
Python 3.8.5
  1. 安装pip3
username@test:~# sudo apt install python3-pip
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-pip is already the newest version (20.0.2-5ubuntu1.1).
0 upgraded, 0 newly installed, 0 to remove and 179 not upgraded.
  1. 查看pip3版本
username@test:~# pip3 --version
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)

1.2 执行安装命令安装ansible

经过漫长的等待后,终于安装成功了

username@test:~# pip3 install ansible
Collecting ansible
  Downloading ansible-2.10.6.tar.gz (29.6 MB)
     |████████████████████████████████| 29.6 MB 56 kB/s
Collecting ansible-base<2.11,>=2.10.5
  Downloading ansible-base-2.10.5.tar.gz (5.7 MB)
     |████████████████████████████████| 5.7 MB 57 kB/s
Requirement already satisfied: PyYAML in /usr/lib/python3/dist-packages (from ansible-base<2.11,>=2.10.5->ansible) (5.3.1)
Requirement already satisfied: cryptography in /usr/lib/python3/dist-packages (from ansible-base<2.11,>=2.10.5->ansible) (2.8)
Requirement already satisfied: jinja2 in /usr/lib/python3/dist-packages (from ansible-base<2.11,>=2.10.5->ansible) (2.10.1)
Collecting packaging
  Downloading packaging-20.9-py2.py3-none-any.whl (40 kB)
     |████████████████████████████████| 40 kB 26 kB/s
Collecting pyparsing>=2.0.2
  Downloading pyparsing-2.4.7-py2.py3-none-any.whl (67 kB)
     |████████████████████████████████| 67 kB 59 kB/s
Building wheels for collected packages: ansible, ansible-base
  Building wheel for ansible (setup.py) ... |
done
  Created wheel for ansible: filename=ansible-2.10.6-py3-none-any.whl size=48356568 sha256=fbcbf206e23aa83bbe61af0eb790e649aad6d6f981895b60e41dc061105563c5
  Stored in directory: /root/.cache/pip/wheels/c0/27/b3/e03cd6cfc28af71d569ac66f1b92873ccf9fa1b71472f00cdc
  Building wheel for ansible-base (setup.py) ... done
  Created wheel for ansible-base: filename=ansible_base-2.10.5-py3-none-any.whl size=1870021 sha256=bf39eaecfedf602d5d92cdda86a5ea17421425c06811c579087a269b31dd88a0
  Stored in directory: /root/.cache/pip/wheels/42/c6/0c/3a4ca90e8116f3d585dff14283e48a6db9982d3f520654c46d
Successfully built ansible ansible-base
Installing collected packages: pyparsing, packaging, ansible-base, ansible

Successfully installed ansible-2.10.6 ansible-base-2.10.5 packaging-20.9 pyparsing-2.4.7

可以看到pip3安装的ansible版本为2.10.6

1.3 执行helloworld

username@test:~# ansible localhost -a "/bin/echo helloworld"
localhost | CHANGED | rc=0 >>
helloworld

2 apt 安装

2.1 执行安装命令

username@test:~# sudo apt-get install ansible
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
  cowsay sshpass
The following NEW packages will be installed:
  ansible
0 upgraded, 1 newly installed, 0 to remove and 179 not upgraded.
Need to get 0 B/5794 kB of archives.
After this operation, 58.0 MB of additional disk space will be used.
Selecting previously unselected package ansible.
(Reading database ... 41263 files and directories currently installed.)
Preparing to unpack .../ansible_2.9.6+dfsg-1_all.deb ...
Unpacking ansible (2.9.6+dfsg-1) ...
Setting up ansible (2.9.6+dfsg-1) ...
Processing triggers for man-db (2.9.1-1) ...

已经安装完成,可以看到apt安装的版本为2.9.6

2.2 执行helloworld

username@test:~# ansible localhost -a "/bin/echo helloworld"
localhost | CHANGED | rc=0 >>
helloworld

参考连接

http://www.ansible.com.cn/docs/intro_getting_started.html#id3

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值