1.   YUM在线安装

1.1  查看确认系统版本

[root@kylin-server1 ~]# nkvers
############## Kylin Linux Version
#################
Release:
Kylin Linux Advanced Server release V10
(Tercel)
 
Kernel:
4.19.90-23.8.v2101.ky10.x86_64
 
Build:
Kylin Linux Advanced Server
release V10 (SP1) /(Tercel)-x86_64-Build20/20210518
#################################################

  

1.2  确认系统YUM源配置

[root@kylin-server1 ~]# cd /etc/yum.repos.d/
[root@kylin-server1 yum.repos.d]# ls
kylin_x86_64.repo
[root@kylin-server1 yum.repos.d]# vim kylin_x86_64.repo
[root@kylin-server1 yum.repos.d]# cat kylin_x86_64.repo
###Kylin Linux Advanced Server 10 - os repo###

[ks10-adv-os]
name = Kylin Linux Advanced Server 10 - Os
baseurl = http://update.cs2c.com.cn:8080/NS/V10/V10SP1.1/os/adv/lic/base/$basearch/
gpgcheck = 1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-kylin
enabled = 1

[ks10-adv-updates]
name = Kylin Linux Advanced Server 10 - Updates
baseurl = http://update.cs2c.com.cn:8080/NS/V10/V10SP1.1/os/adv/lic/updates/$basearch/
gpgcheck = 1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-kylin
enabled = 1

[ks10-adv-addons]
name = Kylin Linux Advanced Server 10 - Addons
baseurl = http://update.cs2c.com.cn:8080/NS/V10/V10SP1.1/os/adv/lic/addons/$basearch/
gpgcheck = 1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-kylin
enabled = 0
[root@kylin-server1 yum.repos.d]#


1.3  Yum安装ansible-2.8.8

[root@kylin-server1 ~]# yum install ansible
Last metadata expiration check: 0:23:38 ago on 2024年07月11日 星期四 14时03分05秒.
Dependencies resolved.
========================================================================================================================================
 Package                             Architecture            Version                            Repository                         Size
========================================================================================================================================
Installing:
 ansible                             noarch                  2.8.8-1.p01.ky10                   ks10-adv-updates                   15 M
Installing dependencies:
 libsodium                           x86_64                  1.0.16-7.ky10                      ks10-adv-os                       146 k
 python3-babel                       noarch                  2.7.0-1.ky10                       ks10-adv-os                       5.9 M
 python3-bcrypt                      x86_64                  3.1.4-7.ky10                       ks10-adv-os                        39 k
 python3-markupsafe                  x86_64                  1.0-3.ky10                         ks10-adv-os                        28 k
 python3-paramiko                    noarch                  2.4.3-1.ky10.ky10                  ks10-adv-os                       281 k
 python3-pyasn1                      noarch                  0.3.7-8.ky10                       ks10-adv-os                       215 k
 python3-pynacl                      x86_64                  1.2.1-4.ky10                       ks10-adv-os                        77 k
 python3-pyyaml                      x86_64                  5.1.2-1.ky10                       ks10-adv-os                       187 k
 sshpass                             x86_64                  1.06-8.ky10                        ks10-adv-os                        24 k
 python3-jinja2                      noarch                  2.11.2-2.p01.ky10                  ks10-adv-updates                  223 k

Transaction Summary
========================================================================================================================================
Install  11 Packages

Total download size: 22 M
Installed size: 109 M
Is this ok [y/N]: y
Downloading Packages:
(1/11): python3-bcrypt-3.1.4-7.ky10.x86_64.rpm                                                          369 kB/s |  39 kB     00:00
(2/11): libsodium-1.0.16-7.ky10.x86_64.rpm                                                              1.0 MB/s | 146 kB     00:00
(3/11): python3-markupsafe-1.0-3.ky10.x86_64.rpm                                                        587 kB/s |  28 kB     00:00
(4/11): python3-pyasn1-0.3.7-8.ky10.noarch.rpm                                                          1.0 MB/s | 215 kB     00:00
(5/11): python3-paramiko-2.4.3-1.ky10.ky10.noarch.rpm                                                   1.1 MB/s | 281 kB     00:00
(6/11): python3-pynacl-1.2.1-4.ky10.x86_64.rpm                                                          960 kB/s |  77 kB     00:00
(7/11): python3-pyyaml-5.1.2-1.ky10.x86_64.rpm                                                          2.1 MB/s | 187 kB     00:00
(8/11): sshpass-1.06-8.ky10.x86_64.rpm                                                                  311 kB/s |  24 kB     00:00
(9/11): python3-babel-2.7.0-1.ky10.noarch.rpm                                                           5.5 MB/s | 5.9 MB     00:01
(10/11): python3-jinja2-2.11.2-2.p01.ky10.noarch.rpm                                                    211 kB/s | 223 kB     00:01
(11/11): ansible-2.8.8-1.p01.ky10.noarch.rpm                                                            8.7 MB/s |  15 MB     00:01
----------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                    10 MB/s |  22 MB     00:02
警告:/var/cache/dnf/ks10-adv-os-f2cd14101054813a/packages/libsodium-1.0.16-7.ky10.x86_64.rpm: 头V3 RSA/SHA1 Signature, 密钥 ID 7a486d9f: NOKEY
Kylin Linux Advanced Server 10 - Os                                                                     133 kB/s | 1.7 kB     00:00
Importing GPG key 0x7A486D9F:
 Userid     : "NeoKylin (release key) <support@cs2c.com.cn>"
 Fingerprint: B814 9E68 5286 4585 CE41 143B 41F8 AEBE 7A48 6D9F
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-kylin
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                1/1
  Installing       : sshpass-1.06-8.ky10.x86_64                                                                                    1/11
  Installing       : python3-pyyaml-5.1.2-1.ky10.x86_64                                                                            2/11
  Installing       : python3-pyasn1-0.3.7-8.ky10.noarch                                                                            3/11
  Installing       : python3-markupsafe-1.0-3.ky10.x86_64                                                                          4/11
  Installing       : python3-bcrypt-3.1.4-7.ky10.x86_64                                                                            5/11
  Installing       : python3-babel-2.7.0-1.ky10.noarch                                                                             6/11
  Installing       : python3-jinja2-2.11.2-2.p01.ky10.noarch                                                                       7/11
  Installing       : libsodium-1.0.16-7.ky10.x86_64                                                                                8/11
  Installing       : python3-pynacl-1.2.1-4.ky10.x86_64                                                                            9/11
  Installing       : python3-paramiko-2.4.3-1.ky10.ky10.noarch                                                                    10/11
  Installing       : ansible-2.8.8-1.p01.ky10.noarch                                                                              11/11
  Running scriptlet: ansible-2.8.8-1.p01.ky10.noarch                                                                              11/11
  Verifying        : libsodium-1.0.16-7.ky10.x86_64                                                                                1/11
  Verifying        : python3-babel-2.7.0-1.ky10.noarch                                                                             2/11
  Verifying        : python3-bcrypt-3.1.4-7.ky10.x86_64                                                                            3/11
  Verifying        : python3-markupsafe-1.0-3.ky10.x86_64                                                                          4/11
  Verifying        : python3-paramiko-2.4.3-1.ky10.ky10.noarch                                                                     5/11
  Verifying        : python3-pyasn1-0.3.7-8.ky10.noarch                                                                            6/11
  Verifying        : python3-pynacl-1.2.1-4.ky10.x86_64                                                                            7/11
  Verifying        : python3-pyyaml-5.1.2-1.ky10.x86_64                                                                            8/11
  Verifying        : sshpass-1.06-8.ky10.x86_64                                                                                    9/11
  Verifying        : ansible-2.8.8-1.p01.ky10.noarch                                                                              10/11
  Verifying        : python3-jinja2-2.11.2-2.p01.ky10.noarch                                                                      11/11

Installed:
  ansible-2.8.8-1.p01.ky10.noarch          libsodium-1.0.16-7.ky10.x86_64                python3-babel-2.7.0-1.ky10.noarch
  python3-bcrypt-3.1.4-7.ky10.x86_64       python3-markupsafe-1.0-3.ky10.x86_64          python3-paramiko-2.4.3-1.ky10.ky10.noarch
  python3-pyasn1-0.3.7-8.ky10.noarch       python3-pynacl-1.2.1-4.ky10.x86_64            python3-pyyaml-5.1.2-1.ky10.x86_64
  sshpass-1.06-8.ky10.x86_64               python3-jinja2-2.11.2-2.p01.ky10.noarch

Complete!

 

1.4   测试使用

[root@kylin-server1 ~]# ansible localhost
-m ping
localhost | SUCCESS => {
   
"changed": false,
   
"ping": "pong"
}

2.   PIP在线安装

2.1  安装pip

[root@kylin-server1 ~]# yum install python3-pip
Last metadata expiration check: 0:00:30 ago on 2024年07月11日 星期四 15时30分07秒.
Dependencies resolved.
========================================================================================================================================
 Package                        Architecture              Version                             Repository                           Size
========================================================================================================================================
Installing:
 python3-pip                    noarch                    20.2.2-6.ky10                       ks10-adv-updates                    2.2 M

Transaction Summary
========================================================================================================================================
Install  1 Package

Total download size: 2.2 M
Installed size: 9.4 M
Is this ok [y/N]: y
Downloading Packages:
python3-pip-20.2.2-6.ky10.noarch.rpm                                                                    6.1 MB/s | 2.2 MB     00:00
----------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                   6.1 MB/s | 2.2 MB     00:00
警告:/var/cache/dnf/ks10-adv-updates-b74b513216569387/packages/python3-pip-20.2.2-6.ky10.noarch.rpm: 头V4 RSA/SHA1 Signature, 密钥 ID 7a486d9f: NOKEY
Kylin Linux Advanced Server 10 - Updates                                                                141 kB/s | 1.7 kB     00:00
Importing GPG key 0x7A486D9F:
 Userid     : "NeoKylin (release key) <support@cs2c.com.cn>"
 Fingerprint: B814 9E68 5286 4585 CE41 143B 41F8 AEBE 7A48 6D9F
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-kylin
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                1/1
  Installing       : python3-pip-20.2.2-6.ky10.noarch                                                                               1/1
  Running scriptlet: python3-pip-20.2.2-6.ky10.noarch                                                                               1/1
  Verifying        : python3-pip-20.2.2-6.ky10.noarch                                                                               1/1

Installed:
  python3-pip-20.2.2-6.ky10.noarch

Complete!

 

2.2  Pip 安装ansible-2.8.8

[root@kylin-server1 ~]# pip3 install ansible==2.8.8
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting ansible==2.8.8
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/68/43/92d5b1921f38b01a7af4e4b39233f25a4512b62fa69a8c757e76a4601596/ansible-2.8.8.tar.gz (12.7 MB)
     |████████████████████████████████| 12.7 MB 1.3 MB/s
Collecting jinja2
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/31/80/3a54838c3fb461f6fec263ebf3a3a41771bd05190238de3486aae8540c36/jinja2-3.1.4-py3-none-any.whl (133 kB)
     |████████████████████████████████| 133 kB 1.1 MB/s
Collecting PyYAML
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d7/8f/db62b0df635b9008fe90aa68424e99cee05e68b398740c8a666a98455589/PyYAML-6.0.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (670 kB)
     |████████████████████████████████| 670 kB 1.8 MB/s
Requirement already satisfied: cryptography in /usr/lib64/python3.7/site-packages (from ansible==2.8.8) (2.6.1)
Collecting MarkupSafe>=2.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/4a/1d/c4f5016f87ced614eacc7d5fb85b25bcc0ff53e8f058d069fc8cbfdc3c7a/MarkupSafe-2.1.5-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25 kB)
Requirement already satisfied: asn1crypto>=0.21.0 in /usr/lib/python3.7/site-packages (from cryptography->ansible==2.8.8) (0.24.0)
Requirement already satisfied: six>=1.4.1 in /usr/lib/python3.7/site-packages (from cryptography->ansible==2.8.8) (1.12.0)
Requirement already satisfied: cffi!=1.11.3,>=1.8 in /usr/lib64/python3.7/site-packages (from cryptography->ansible==2.8.8) (1.11.5)
Requirement already satisfied: pycparser in /usr/lib/python3.7/site-packages (from cffi!=1.11.3,>=1.8->cryptography->ansible==2.8.8) (2.19)
Using legacy 'setup.py install' for ansible, since package 'wheel' is not installed.
Installing collected packages: MarkupSafe, jinja2, PyYAML, ansible
    Running setup.py install for ansible ... done
Successfully installed MarkupSafe-2.1.5 PyYAML-6.0.1 ansible-2.8.8 jinja2-3.1.4

 

3.   离线安装

3.1  下载ansible所需要的依赖包

[root@kylin-server2 ~]# ll ansible-pkgs/
总用量 22252
-rw-r--r-- 1 root root 15321140  7月 11 14:39 ansible-2.8.8-1.p01.ky10.noarch.rpm
-rw-r--r-- 1 root root   149100  7月 11 14:39 libsodium-1.0.16-7.ky10.x86_64.rpm
-rw-r--r-- 1 root root  6189420  7月 11 14:39 python3-babel-2.7.0-1.ky10.noarch.rpm
-rw-r--r-- 1 root root    40260  7月 11 14:39 python3-bcrypt-3.1.4-7.ky10.x86_64.rpm
-rw-r--r-- 1 root root   228612  7月 11 14:39 python3-jinja2-2.11.2-2.p01.ky10.noarch.rpm
-rw-r--r-- 1 root root    29108  7月 11 14:39 python3-markupsafe-1.0-3.ky10.x86_64.rpm
-rw-r--r-- 1 root root   287484  7月 11 14:39 python3-paramiko-2.4.3-1.ky10.ky10.noarch.rpm
-rw-r--r-- 1 root root   220644  7月 11 14:39 python3-pyasn1-0.3.7-8.ky10.noarch.rpm
-rw-r--r-- 1 root root    78680  7月 11 14:39 python3-pynacl-1.2.1-4.ky10.x86_64.rpm
-rw-r--r-- 1 root root   191612  7月 11 14:39 python3-pyyaml-5.1.2-1.ky10.x86_64.rpm
-rw-r--r-- 1 root root    25088  7月 11 14:39 sshpass-1.06-8.ky10.x86_64.rpm

3.2 RPM安装ansible-2.8.8

[root@kylin-server2 ansible-pkgs]# rpm -ivh *.rpm
警告:ansible-2.8.8-1.p01.ky10.noarch.rpm: 头V4 RSA/SHA1 Signature, 密钥 ID 7a486d9f: NOKEY
Verifying...                          ################################# [100%]
准备中...                          ################################# [100%]
正在升级/安装...
   1:sshpass-1.06-8.ky10              ################################# [  9%]
   2:python3-pyyaml-5.1.2-1.ky10      ################################# [ 18%]
   3:python3-pyasn1-0.3.7-8.ky10      ################################# [ 27%]
   4:python3-markupsafe-1.0-3.ky10    ################################# [ 36%]
   5:python3-bcrypt-3.1.4-7.ky10      ################################# [ 45%]
   6:python3-babel-2.7.0-1.ky10       ################################# [ 55%]
   7:python3-jinja2-2.11.2-2.p01.ky10 ################################# [ 64%]
   8:libsodium-1.0.16-7.ky10          ################################# [ 73%]
   9:python3-pynacl-1.2.1-4.ky10      ################################# [ 82%]
  10:python3-paramiko-2.4.3-1.ky10.ky1################################# [ 91%]
  11:ansible-2.8.8-1.p01.ky10         ################################# [100%]

 

3.3    测试使用

[root@kylin-server2 ansible-pkgs]# ansible
localhost -m ping
localhost | SUCCESS => {
   
"changed": false,
   
"ping": "pong"
}

  

3.3.1     常见问题

问题1:

[root@kylin-server2 ansible-pkgs]# ansible server -m ping
[WARNING]: Platform linux on host 192.168.111.112 is using the discovered Python interpreter at /usr/bin/python, but future
installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.8/reference_appendices/interpreter_discovery.html for more information.

192.168.111.112 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}
[WARNING]: Platform linux on host 192.168.111.113 is using the discovered Python interpreter at /usr/bin/python, but future
installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.8/reference_appendices/interpreter_discovery.html for more information.

192.168.111.113 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}

解决方法:

[root@kylin-server2 ansible-pkgs]# vim /etc/ansible/ansible.cfg

[defaults]

# some basic default values...

#inventory      = /etc/ansible/hosts
#library        = /usr/share/my_modules/
#module_utils   = /usr/share/my_module_utils/
#remote_tmp     = ~/.ansible/tmp
#local_tmp      = ~/.ansible/tmp
#plugin_filters_cfg = /etc/ansible/plugin_filters.yml
#forks          = 5
#poll_interval  = 15
#sudo_user      = root
#ask_sudo_pass = True
#ask_pass      = True
#transport      = smart
#remote_port    = 22
#module_lang    = C
#module_set_locale = False
interpreter_python = auto_legacy_silent


[root@kylin-server2 ansible-pkgs]# ansible server -m ping
192.168.111.113 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}
192.168.111.112 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}

问题2:

[root@kylin-server2 ~]# ansible server -m ping
192.168.111.112 | FAILED! => {
    "msg": "Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this.  Please add this host's fingerprint to your known_hosts file to manage this host."
}
192.168.111.113 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}

 解决方法:

[root@kylin-server2 ~]# vim /etc/ansible/ansible.cfg
# uncomment this to disable SSH key host checking
host_key_checking = False

[root@kylin-server2 ~]# ansible server -m ping
192.168.111.113 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}
192.168.111.112 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}

 问题3:

[root@kylin-server1 ~]# ansible localhost -m shell -a "uname -a "

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

[WARNING]: Skipping plugin (/usr/local/lib/python3.7/site-packages/ansible/plugins/filter/core.py) as it seems to be invalid: cannot
import name 'environmentfilter' from 'jinja2.filters' (/usr/local/lib/python3.7/site-packages/jinja2/filters.py)

[WARNING]: Skipping plugin (/usr/local/lib/python3.7/site-packages/ansible/plugins/filter/mathstuff.py) as it seems to be invalid:
cannot import name 'environmentfilter' from 'jinja2.filters' (/usr/local/lib/python3.7/site-packages/jinja2/filters.py)

localhost | CHANGED | rc=0 >>
Linux kylin-server1 4.19.90-23.8.v2101.ky10.x86_64 #1 SMP Mon May 17 17:08:34 CST 2021 x86_64 x86_64 x86_64 GNU/Linux

 解决方法:

[root@kylin-server1 ~]# pip3 install jinja2==3.0.0
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting jinja2==3.0.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/48/9b/dc3bbfc44d851632df958acf9d47e4de662c6bbd238e46798d555d427b27/Jinja2-3.0.0-py3-none-any.whl (133 kB)
     |████████████████████████████████| 133 kB 1.3 MB/s
Requirement already satisfied: MarkupSafe>=2.0.0rc2 in /usr/local/lib64/python3.7/site-packages (from jinja2==3.0.0) (2.1.5)
Installing collected packages: jinja2
  Attempting uninstall: jinja2
    Found existing installation: Jinja2 2.11.3
    Uninstalling Jinja2-2.11.3:
      Successfully uninstalled Jinja2-2.11.3
Successfully installed jinja2-3.0.0
[root@kylin-server1 ~]# ansible localhost -m shell -a "uname -a "
[WARNING]: No inventory was parsed, only implicit localhost is available

localhost | CHANGED | rc=0 >>
Linux kylin-server1 4.19.90-23.8.v2101.ky10.x86_64 #1 SMP Mon May 17 17:08:34 CST 2021 x86_64 x86_64 x86_64 GNU/Linux