1: 因为本人的linux yum 安装ansible 有问题,就开始利用source code 来安装: www.python.org 下载--> download --> source code --> python3.7.3 --> Gzipped Source tar ball

2: 下载后 tar -zxvf python3.7.3.tgz, 解压后: ./configure

3: make

4: make install 因为这个是最新的python 版本,会报错: ModuNotFoundError: No Module named '_ctypes', 后来网上看了解决方法:yum install libffi-devel -y    然后再make install 就可以了。

5:提示 successful install pip

6: 然后在linux 中敲入pip 还是没有认识: command not found, 但是在/usr/local/bin下面已经有pip3 了,不知道是不是python version 3 的原因。检查一下PATH: echo $PATH ,发现/usr/local/bin 已经有了,后来的解决方法: ln -s /usr/local/bin/pip3 /usr/local/bin/pip, 然后敲入pip, OK!

7: 好,下面开始安装ansible: pip install ansible,  OK 啦!!! 检验一下: pip list 发现还有其他的有用的东东也安装好。

8:心中的喜悦阿,马上command 来测试一把: ansible all -m ping, 结果报错:

[WARNING]: Unable to parse /etc/ansible/hosts as an inventory source

 [WARNING]: No inventory was parsed, only implicit localhost is available

 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit
localhost does not match 'all'

9: 我看了一下ansible 的配置文件在:/usr/local/lib/python3.7/site-packages/ansible/galaxy/data/apb/tests/ansible.cfg, 结果在/usr/local/lib/python3.7/site-packages/ansible/galaxy/data/apb/tests/ 下面执行就OK, 发现是path 可能不对,就又建立了一个link: ln -s /usr/local/lib/python3.7/site-packages/ansible/galaxy/data/apb/tests/inventory /etc/ansible/hosts     (这个/etc/ansible 文件夹要手动建立, hosts 可以不用建立).

10: inentory 里面可以写 IP address ,也可以写 hostname, 如果是remote hostname 的话,要/etc/hosts 下面把remote host 的IP/hostname 都写对应好。这个文件中写hostname 有个好处就是user 易读,举个例子:server 端要从client 端拉取数据,就会在本地新建一个remote 的文件夹:ansible all -m fetch -a "src=/home/sheng/sulog dest=/tmp/", 下面看一下结果:

[root@oc2246430752 tests]# ansible all -m fetch -a "src=/home/sheng/p dest=/tmp/"
test | CHANGED => {
    "changed": true,
    "checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
    "dest": "/tmp/test/home/sheng/p",
    "md5sum": "d41d8cd98f00b204e9800998ecf8427e",
    "remote_checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
    "remote_md5sum": null
}

[root@oc2246430752 sheng]# pwd
/tmp/test/home/sheng

 

GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐