准备工作
发行版:RHEL/CentOS/Debian/Ubuntu Linux
Jinja2:Python 的一个对设计师友好的现代模板语言
PyYAML:Python 的一个 YAML 编码/反编码函数库
paramiko:纯 Python 编写的 SSHv2 协议函数库 (译者注:原文对函数库名有拼写错误)
httplib2:一个功能全面的 HTTP 客户端函数库
本文中列出的绝大部分操作已经假设你将在 bash 或者其他任何现代的 shell 中以 root 用户执行。
使用git方式安装
看来看去貌似git方式比较省事,也便于以后升级。
cd ~ git clone git://github.com/ansible/ansible.git source ./hacking/env-setup silent #从git更新ansible git pull --rebase git submodule update --init --recursive b
当你从一个 git checkout 中运行 ansible 的时候,请记住你每次用它之前都需要设置你的环境,或者你可以把这个设置过程加入你的 bash rc 文件中(/etc/bashrc):
# 加入 BASH RC echo "source ~/ansible/hacking/env-setup silent" >> ~/.bashrc source ~/.bashrc
添加必须组件:
yum install python-jinja2 python-yaml -y
使用 SSH 公钥认证 管理受控服务器
1、使用命令 ssh-keygen -t rsa 生成本机公钥、私钥,一路回车即可
[root@ansible ~]# ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: 01:ac:55:38:e7:10:b1:ae:27:0e:98:54:b9:10:fc:da root@9ifast The key's randomart image is: +--[ RSA 2048]----+ |.. .+=. | | .. . *o. | | ..o o.=. | | o.o. .. | | .o. . S | |.+ E . | |o . o . | | o o | | . | +-----------------+ [root@9ifast ~]# ll .ssh/ total 16 -rw-------. 1 root root 3573 May 29 00:53 authorized_keys -rw------- 1 root root 1675 Jul 4 20:29 id_rsa -rw-r--r-- 1 root root 393 Jul 4 20:29 id_rsa.pub -rw-r--r-- 1 root root 807 Jun 21 19:27 known_hosts
2、ssh-copy-id 将本机公钥传送至受控服务器(免密码登陆)
ssh-copy-id -i /root/.ssh/id_rsa.pub "-p 22 [email protected]"
以上命令执行后将会要求输入 1.1.1.1 的密码,输入即可。
3、将添加了key的服务器加入ansible_hosts列表,默认在 /etc/ansible/hosts
[root@ansible ~]# cat /etc/ansible/hosts [test] 1.1.1.1
4、测试使用
[root@ansible ~]# ansible all -m shell -a 'echo 1' 1.1.1.1 | UNREACHABLE! => { "changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 1.1.1.1 port 22: Connection timed out\r\n", "unreachable": true } [root@ansible ~]# ansible test -m shell -a 'echo 1' 1.1.1.1 | UNREACHABLE! => { "changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 1.1.1.1 port 22: Connection timed out\r\n", "unreachable": true } [root@ansible ~]# ansible 1.1.1.1 -m shell -a 'echo 1' 1.1.1.1 | UNREACHABLE! => { "changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 1.1.1.1 port 22: Connection timed out\r\n", "unreachable": true }
以上3种用法,分别表示:
all:所有列表种的机器
test:[test]组中的机器
1.1.1.1:单台机器
Centos6 升级 python3
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz tar -xzf Python-3.6.2.tgz cd Python-3.6.2 ./configure --prefix=/usr/local/python36 make && make install mv /usr/bin/python /usr/bin/python_bak ln -s /usr/local/python36/bin/python3.6 /usr/bin/python vim /usr/bin/yum vim /usr/libexec/urlgrabber-ext-down #把最上面的一行配置回python_bak就行了 #!/usr/bin/python => #!/usr/bin/python_bak
© 著作权归作者所有
下一篇: 今天吃什么
文章评论(0)