[jing@CJVM01 ~]$ cat /etc/redhat-release
CentOS Linux release 8.0.1905 (Core)
[jing@CJVM01 ~]$ rpm -qa | grep python
python3-libxml2-2.9.7-5.el8.x86_64
python3-dateutil-2.6.1-6.el8.noarch
python3-libcomps-0.1.8-13.el8.x86_64
python3-pyyaml-3.12-12.el8.x86_64
python3-pycparser-2.14-14.el8.noarch
python3-rhnlib-2.8.6-8.module_el8.0.0+180+337688dc.noarch
python3-sssdconfig-2.0.0-43.el8_0.3.noarch
python3-hawkey-0.22.5-5.el8_0.x86_64
python3-rpm-4.14.2-11.el8_0.x86_64
python3-rhn-client-tools-2.8.16-13.module_el8.0.0+180+337688dc.x86_64
python3-dnf-plugin-spacewalk-2.8.5-11.module_el8.0.0+180+337688dc.noarch
platform-python-pip-9.0.3-13.el8.noarch
python3-six-1.11.0-8.el8.noarch
python3-decorator-4.2.1-2.el8.noarch
python3-dmidecode-3.12.2-13.el8.x86_64
python3-configobj-5.0.6-11.el8.noarch
python3-iniparse-0.4-31.el8.noarch
python3-pyudev-0.21.0-7.el8.noarch
python3-libselinux-2.8-6.el8.x86_64
python3-slip-dbus-0.6.4-11.el8.noarch
python3-libstoragemgmt-clibs-1.6.2-9.el8.x86_64
python3-perf-4.18.0-80.11.2.el8_0.x86_64
python3-schedutils-0.6-5.el8.x86_64
python3-newt-0.52.20-9.el8.x86_64
python3-asn1crypto-0.24.0-3.el8.noarch
python3-ply-3.9-7.el8.noarch
python3-cffi-1.11.5-5.el8.x86_64
python3-pyOpenSSL-18.0.0-1.el8.noarch
python3-setuptools-39.2.0-4.el8.noarch
python36-3.6.8-2.module_el8.0.0+33+0a10c0e1.x86_64
python3-syspurpose-1.23.8-35.el8.x86_64
python3-pyasn1-0.3.7-6.el8.noarch
python3-firewall-0.6.3-7.el8.noarch
python3-libdnf-0.22.5-5.el8_0.x86_64
python3-librepo-1.9.2-1.el8.x86_64
python3-dnf-4.0.9.2-5.el8.noarch
python3-dnf-plugins-core-4.0.2.2-3.el8.noarch
platform-python-setuptools-39.2.0-4.el8.noarch
python3-libs-3.6.8-4.el8_0.x86_64
python3-dbus-1.2.4-14.el8.x86_64
python3-linux-procfs-0.6-6.el8.noarch
python3-slip-0.6.4-11.el8.noarch
python3-libstoragemgmt-1.6.2-9.el8.noarch
python3-netifaces-0.10.6-4.el8.x86_64
python3-idna-2.5-5.el8.noarch
python3-cryptography-2.3-2.el8.x86_64
python3-pip-9.0.3-13.el8.noarch
python3-hwdata-2.3.6-3.el8.noarch
python3-gobject-base-3.28.3-1.el8.x86_64
python3-gpg-1.10.0-6.el8.0.1.x86_64
platform-python-3.6.8-4.el8_0.x86_64
[jing@CJVM01 ~]$ ansible --version
-bash: ansible: command not found
[jing@CJVM01 ~]$ sudo yum install epel-release
[sudo] password for jing:
CentOS-8 - AppStream 3.4 kB/s | 3.5 kB 00:01
CentOS-8 - Base 3.1 kB/s | 3.1 kB 00:01
CentOS-8 - Extras 644 B/s | 1.5 kB 00:02
Dependencies resolved.
Package Arch Version Repository Size
Installing:
epel-release noarch 8-11.el8 extras 24 k
Transaction Summary
Install 1 Package
Total download size: 24 k
Installed size: 35 k
Is this ok [y/N]: y
Downloading Packages:
epel-release-8-11.el8.noarch.rpm 23 kB/s | 24 kB 00:01
Total 9.8 kB/s | 24 kB 00:02
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : epel-release-8-11.el8.noarch 1/1
Running scriptlet: epel-release-8-11.el8.noarch 1/1
Verifying : epel-release-8-11.el8.noarch 1/1
Installed:
epel-release-8-11.el8.noarch
Complete!
[jing@CJVM01 ~]$ sudo yum install ansible
Extra Packages for Enterprise Linux Modular 8 - 270 kB/s | 979 kB 00:03
Extra Packages for Enterprise Linux 8 - x86_64 2.8 MB/s | 11 MB 00:03
Dependencies resolved.
Package Arch Version Repository Size
Installing:
ansible noarch 2.9.27-1.el8 epel 17 M
Installing dependencies:
python3-babel noarch 2.5.1-7.el8 AppStream 4.8 M
python3-jinja2 noarch 2.10.1-3.el8 AppStream 538 k
python3-jmespath noarch 0.9.0-11.el8 AppStream 45 k
python3-markupsafe x86_64 0.23-19.el8 AppStream 39 k
python3-pytz noarch 2017.2-9.el8 AppStream 54 k
libsodium x86_64 1.0.18-2.el8 epel 162 k
python3-bcrypt x86_64 3.1.6-2.el8.1 epel 44 k
python3-pynacl x86_64 1.3.0-5.el8 epel 100 k
sshpass x86_64 1.06-9.el8 epel 27 k
Installing weak dependencies:
python3-paramiko noarch 2.4.3-1.el8 epel 289 k
Transaction Summary
Install 11 Packages
Total download size: 23 M
Installed size: 121 M
Is this ok [y/N]: y
Downloading Packages:
(1/11): python3-jinja2-2.10.1-3.el8.noarch.rpm 522 kB/s | 538 kB 00:01
(2/11): python3-jmespath-0.9.0-11.el8.noarch.rp 43 kB/s | 45 kB 00:01
(3/11): python3-markupsafe-0.23-19.el8.x86_64.r 7.0 MB/s | 39 kB 00:00
(4/11): python3-pytz-2017.2-9.el8.noarch.rpm 1.1 MB/s | 54 kB 00:00
(5/11): python3-babel-2.5.1-7.el8.noarch.rpm 4.2 MB/s | 4.8 MB 00:01
(6/11): python3-bcrypt-3.1.6-2.el8.1.x86_64.rpm 511 kB/s | 44 kB 00:00
(7/11): libsodium-1.0.18-2.el8.x86_64.rpm 859 kB/s | 162 kB 00:00
(8/11): python3-pynacl-1.3.0-5.el8.x86_64.rpm 817 kB/s | 100 kB 00:00
(9/11): sshpass-1.06-9.el8.x86_64.rpm 695 kB/s | 27 kB 00:00
(10/11): python3-paramiko-2.4.3-1.el8.noarch.rp 998 kB/s | 289 kB 00:00
(11/11): ansible-2.9.27-1.el8.noarch.rpm 2.7 MB/s | 17 MB 00:06
Total 2.6 MB/s | 23 MB 00:08
warning: /var/cache/dnf/epel-6519ee669354a484/packages/ansible-2.9.27-1.el8.noarch.rpm: Header V4 RSA/SHA256 Signature, key ID 2f86d6a1: NOKEY
Extra Packages for Enterprise Linux 8 - x86_64 1.6 MB/s | 1.6 kB 00:00
Importing GPG key 0x2F86D6A1:
Userid : "Fedora EPEL (8) [email protected]"
Fingerprint: 94E2 79EB 8D8F 25B2 1810 ADF1 21EA 45AB 2F86 D6A1
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
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-9.el8.x86_64 1/11
Installing : python3-bcrypt-3.1.6-2.el8.1.x86_64 2/11
Installing : libsodium-1.0.18-2.el8.x86_64 3/11
Installing : python3-pynacl-1.3.0-5.el8.x86_64 4/11
Installing : python3-paramiko-2.4.3-1.el8.noarch 5/11
Installing : python3-pytz-2017.2-9.el8.noarch 6/11
Installing : python3-babel-2.5.1-7.el8.noarch 7/11
Installing : python3-markupsafe-0.23-19.el8.x86_64 8/11
Installing : python3-jinja2-2.10.1-3.el8.noarch 9/11
Installing : python3-jmespath-0.9.0-11.el8.noarch 10/11
Installing : ansible-2.9.27-1.el8.noarch 11/11
Running scriptlet: ansible-2.9.27-1.el8.noarch 11/11
Verifying : python3-babel-2.5.1-7.el8.noarch 1/11
Verifying : python3-jinja2-2.10.1-3.el8.noarch 2/11
Verifying : python3-jmespath-0.9.0-11.el8.noarch 3/11
Verifying : python3-markupsafe-0.23-19.el8.x86_64 4/11
Verifying : python3-pytz-2017.2-9.el8.noarch 5/11
Verifying : ansible-2.9.27-1.el8.noarch 6/11
Verifying : libsodium-1.0.18-2.el8.x86_64 7/11
Verifying : python3-bcrypt-3.1.6-2.el8.1.x86_64 8/11
Verifying : python3-paramiko-2.4.3-1.el8.noarch 9/11
Verifying : python3-pynacl-1.3.0-5.el8.x86_64 10/11
Verifying : sshpass-1.06-9.el8.x86_64 11/11
Installed:
ansible-2.9.27-1.el8.noarch python3-paramiko-2.4.3-1.el8.noarch
python3-babel-2.5.1-7.el8.noarch python3-jinja2-2.10.1-3.el8.noarch
python3-jmespath-0.9.0-11.el8.noarch python3-markupsafe-0.23-19.el8.x86_64
python3-pytz-2017.2-9.el8.noarch libsodium-1.0.18-2.el8.x86_64
python3-bcrypt-3.1.6-2.el8.1.x86_64 python3-pynacl-1.3.0-5.el8.x86_64
sshpass-1.06-9.el8.x86_64
Complete!
[jing@CJVM01 ~]$ ansible --version
ansible 2.9.27
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/jing/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.6/site-packages/ansible
executable location = /usr/bin/ansible
python version = 3.6.8 (default, Oct 7 2019, 17:58:22) [GCC 8.2.1 20180905 (Red Hat 8.2.1-3)]
[jing@CJVM01 ~]$
[jing@CJVM01 ~]$ vi hosts
[jing@CJVM01 ~]$ more hosts
[centos]
192.168.0.4
[win]
192.168.0.6
[centos:vars]
ansible_ssh_port=22
ansible_ssh_user=jing
ansible_ssh_pass=ansible@2022
[win:vars]
ansible_user=jing
ansible_password=ansible@2022
ansible_connection=winrm
ansible_port=5985
ansible_winrm_server_cert_validation=ignore
[jing@CJVM01 ~]$ vi test.yml
[jing@CJVM01 ~]$ more test.yml
- hosts: centos
tasks:- name: show version
debug:
msg: "{{ansible_distribution_major_version}}"
[jing@CJVM01 ~]$
- name: show version
[jing@CJVM01 ~]$ ansible-playbook -i hosts test.yml
PLAY [centos] ******************************************************************
TASK [Gathering Facts] *********************************************************
fatal: [192.168.0.4]: FAILED! => {"msg": "Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not suppor t this. Please add this host's fingerprint to your known_hosts file to manage t his host."}
PLAY RECAP *********************************************************************
192.168.0.4 : ok=0 changed=0 unreachable=0 failed=1 s kipped=0 rescued=0 ignored=0
[jing@CJVM01 ~]$ ssh [email protected]
The authenticity of host '192.168.0.4 (192.168.0.4)' can't be established.
ECDSA key fingerprint is SHA256:Jb8qtPUsty44NfkinoF/svwjZms0/2kA+AxJbODzwTo.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.4' (ECDSA) to the list of known hosts.
Password:
Activate the web console with: systemctl enable --now cockpit.socket
Last login: Tue Jan 18 02:02:24 2022 from 223.64.123.112
[jing@AnsibleVM01 ~]$ exit
logout
Connection to 192.168.0.4 closed.
[jing@CJVM01 ~]$ ansible-playbook -i hosts test.yml
PLAY [centos] *****************************************************************************************
TASK [Gathering Facts] ********************************************************************************
ok: [192.168.0.4]
TASK [show version] ***********************************************************************************
ok: [192.168.0.4] => {
"msg": "8"
}
PLAY RECAP ********************************************************************************************
192.168.0.4 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
[jing@CJVM01 ~]$ vi test_win.yml
[jing@CJVM01 ~]$ more test_win.yml
- hosts: win
tasks:- name: Check Win Connectivity
win_ping:
register: ping_result - debug: msg="Unble to reach endpoint"
when: '"unreachable" in ping_result' - debug: msg="Able to reach endpoint"
when: '"ping" in ping_result'
[jing@CJVM01 ~]$
- name: Check Win Connectivity
[jing@CJVM01 ~]$ ansible-playbook -i hosts test_win.yml
PLAY [win] ********************************************************************************************
TASK [Gathering Facts] ********************************************************************************
fatal: [192.168.0.6]: FAILED! => {"msg": "winrm or requests is not installed: No module named 'winrm'"}
PLAY RECAP ********************************************************************************************
192.168.0.6 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
[jing@CJVM01 ~]$
[jing@CJVM01 ~]$ sudo pip3 install --upgrade pip
WARNING: Running pip install with root privileges is generally not a good idea. Try pip3 install --user
instead.
Collecting pip
Downloading https://files.pythonhosted.org/packages/a4/6d/6463d49a933f547439d6b5b98b46af8742cc03ae83543e4d7688c2420f8b/pip-21.3.1-py3-none-any.whl (1.7MB)
100% |████████████████████████████████| 1.7MB 671kB/s
Installing collected packages: pip
Successfully installed pip-21.3.1
[jing@CJVM01 ~]$ pip list
Package Version
ansible 2.9.27
asn1crypto 0.24.0
Babel 2.5.1
bcrypt 3.1.6
cffi 1.11.5
configobj 5.0.6
cryptography 2.3
decorator 4.2.1
gpg 1.10.0
idna 2.5
iniparse 0.4
Jinja2 2.10.1
jmespath 0.9.0
MarkupSafe 0.23
netifaces 0.10.6
paramiko 2.4.3
pciutils 2.3.6
perf 0.1
pip 21.3.1
ply 3.9
pyasn1 0.3.7
pycparser 2.14
PyGObject 3.28.3
PyNaCl 1.3.0
pyOpenSSL 18.0.0
python-dateutil 2.6.1
python-dmidecode 3.12.2
python-linux-procfs 0.6
pytz 2017.2
pyudev 0.21.0
PyYAML 3.12
rhnlib 2.8.6
rpm 4.14.2
schedutils 0.6
setuptools 39.2.0
six 1.11.0
slip 0.6.4
slip.dbus 0.6.4
sos 3.6
SSSDConfig 2.0.0
syspurpose 1.23.8
WALinuxAgent 2.2.32.2
[jing@CJVM01 ~]$
[jing@CJVM01 ~]$ pip --version
pip 21.3.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
[jing@CJVM01 ~]$ pip install pywinrm
Defaulting to user installation because normal site-packages is not writeable
Collecting pywinrm
Downloading pywinrm-0.4.2-py2.py3-none-any.whl (44 kB)
|████████████████████████████████| 44 kB 1.1 MB/s
Collecting requests>=2.9.1
Downloading requests-2.27.1-py2.py3-none-any.whl (63 kB)
|████████████████████████████████| 63 kB 719 kB/s
Collecting requests-ntlm>=0.3.0
Downloading requests_ntlm-1.1.0-py2.py3-none-any.whl (5.7 kB)
Requirement already satisfied: six in /usr/lib/python3.6/site-packages (from pywinrm) (1.11.0)
Collecting xmltodict
Downloading xmltodict-0.12.0-py2.py3-none-any.whl (9.2 kB)
Collecting charset-normalizer~=2.0.0
Downloading charset_normalizer-2.0.10-py3-none-any.whl (39 kB)
Collecting certifi>=2017.4.17
Downloading certifi-2021.10.8-py2.py3-none-any.whl (149 kB)
|████████████████████████████████| 149 kB 65.8 MB/s
Collecting urllib3<1.27,>=1.21.1
Downloading urllib3-1.26.8-py2.py3-none-any.whl (138 kB)
|████████████████████████████████| 138 kB 83.6 MB/s
Requirement already satisfied: idna<4,>=2.5 in /usr/lib/python3.6/site-packages (from requests>=2.9.1->pywinrm) (2.5)
Collecting ntlm-auth>=1.0.2
Downloading ntlm_auth-1.5.0-py2.py3-none-any.whl (29 kB)
Requirement already satisfied: cryptography>=1.3 in /usr/lib64/python3.6/site-packages (from requests-ntlm>=0.3.0->pywinrm) (2.3)
Requirement already satisfied: asn1crypto>=0.21.0 in /usr/lib/python3.6/site-packages (from cryptography>=1.3->requests-ntlm>=0.3.0->pywinrm) (0.24.0)
Requirement already satisfied: cffi!=1.11.3,>=1.7 in /usr/lib64/python3.6/site-packages (from cryptography>=1.3->requests-ntlm>=0.3.0->pywinrm) (1.11.5)
Requirement already satisfied: pycparser in /usr/lib/python3.6/site-packages (from cffi!=1.11.3,>=1.7->cryptography>=1.3->requests-ntlm>=0.3.0->pywinrm) (2.14)
Installing collected packages: urllib3, charset-normalizer, certifi, requests, ntlm-auth, xmltodict, requests-ntlm, pywinrm
Successfully installed certifi-2021.10.8 charset-normalizer-2.0.10 ntlm-auth-1.5.0 pywinrm-0.4.2 requests-2.27.1 requests-ntlm-1.1.0 urllib3-1.26.8 xmltodict-0.12.0
[jing@CJVM01 ~]$
[jing@CJVM01 ~]$ ansible-playbook -i hosts test_win.yml
PLAY [win] ********************************************************************************************
TASK [Gathering Facts] ********************************************************************************
ok: [192.168.0.6]
TASK [Check Win Connectivity] *************************************************************************
ok: [192.168.0.6]
TASK [debug] ******************************************************************************************
skipping: [192.168.0.6]
TASK [debug] ******************************************************************************************
ok: [192.168.0.6] => {
"msg": "Able to reach endpoint"
}
PLAY RECAP ********************************************************************************************
192.168.0.6 : ok=3 changed=0 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0
[jing@CJVM01 ~]$
标签:11,log,noarch,el8,ansible,64,install,python3,x86 From: https://www.cnblogs.com/z20240722/p/18315846