【ansible】ansible指定interpreter的python版本

ansible 通过 ansible_python_interpreter=/path/to/ 指定interpreter的python版本。

Interpreter Discovery
https://docs.ansible.com/ansible/latest/reference_appendices/interpreter_discovery.html

# yum -y install    ansible

上次元数据过期检查:1:56:05 前,执行于 2024年04月12日 星期五 08时40分12秒。
依赖关系解决。
=========================================================================================================================
 Package                         Architecture          Version                          Repository                  Size
=========================================================================================================================
安装:
 ansible                         noarch                2.8.8-1.p01.ky10                 ks10-adv-os                 15 M
安装依赖关系:
 libsodium                       x86_64                1.0.18-1.ky10                    ks10-adv-os                152 k
 python3-bcrypt                  x86_64                3.2.0-1.ky10                     ks10-adv-os                 40 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-5.ky10                     ks10-adv-os                 77 k
 python3-pyyaml                  x86_64                5.3.1-4.ky10                     ks10-adv-os                189 k
 sshpass                         x86_64                1.06-8.ky10                      ks10-adv-os                 24 k

事务概要
=========================================================================================================================
安装  8 软件包

总下载:16 M
安装大小:82 M
下载软件包:
(1/8): python3-bcrypt-3.2.0-1.ky10.x86_64.rpm                                            480 kB/s |  40 kB     00:00
(2/8): python3-paramiko-2.4.3-1.ky10.ky10.noarch.rpm                                     3.7 MB/s | 281 kB     00:00
(3/8): python3-pyasn1-0.3.7-8.ky10.noarch.rpm                                            3.9 MB/s | 215 kB     00:00
(4/8): python3-pynacl-1.2.1-5.ky10.x86_64.rpm                                            489 kB/s |  77 kB     00:00
(5/8): libsodium-1.0.18-1.ky10.x86_64.rpm                                                409 kB/s | 152 kB     00:00
(6/8): python3-pyyaml-5.3.1-4.ky10.x86_64.rpm                                            1.9 MB/s | 189 kB     00:00
(7/8): sshpass-1.06-8.ky10.x86_64.rpm                                                    235 kB/s |  24 kB     00:00
(8/8): ansible-2.8.8-1.p01.ky10.noarch.rpm                                               3.1 MB/s |  15 MB     00:04
-------------------------------------------------------------------------------------------------------------------------
总计                                                                                     3.3 MB/s |  16 MB     00:04
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
  准备中  :                                                                                                          1/1
  安装    : sshpass-1.06-8.ky10.x86_64                                                                               1/8
  安装    : python3-pyyaml-5.3.1-4.ky10.x86_64                                                                       2/8
  安装    : python3-pyasn1-0.3.7-8.ky10.noarch                                                                       3/8
  安装    : python3-bcrypt-3.2.0-1.ky10.x86_64                                                                       4/8
  安装    : libsodium-1.0.18-1.ky10.x86_64                                                                           5/8
  安装    : python3-pynacl-1.2.1-5.ky10.x86_64                                                                       6/8
  安装    : python3-paramiko-2.4.3-1.ky10.ky10.noarch                                                                7/8
  安装    : ansible-2.8.8-1.p01.ky10.noarch                                                                          8/8
  运行脚本: ansible-2.8.8-1.p01.ky10.noarch                                                                          8/8
  验证    : ansible-2.8.8-1.p01.ky10.noarch                                                                          1/8
  验证    : libsodium-1.0.18-1.ky10.x86_64                                                                           2/8
  验证    : python3-bcrypt-3.2.0-1.ky10.x86_64                                                                       3/8
  验证    : python3-paramiko-2.4.3-1.ky10.ky10.noarch                                                                4/8
  验证    : python3-pyasn1-0.3.7-8.ky10.noarch                                                                       5/8
  验证    : python3-pynacl-1.2.1-5.ky10.x86_64                                                                       6/8
  验证    : python3-pyyaml-5.3.1-4.ky10.x86_64                                                                       7/8
  验证    : sshpass-1.06-8.ky10.x86_64                                                                               8/8

已安装:
  ansible-2.8.8-1.p01.ky10.noarch             libsodium-1.0.18-1.ky10.x86_64       python3-bcrypt-3.2.0-1.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-5.ky10.x86_64
  python3-pyyaml-5.3.1-4.ky10.x86_64          sshpass-1.06-8.ky10.x86_64

完毕!

#  ansible -i hosts.txt all -m  shell  -a 'date'
[WARNING]: Platform linux on host app02 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.1.101 | CHANGED | rc=0 >>
2024年 04月 12日 星期五 10:49:08 CST

看安装ansible的yum使用的python版本

# cat /usr/bin/yum
#!/usr/bin/python3
# The dnf executable script.
#
# Copyright (C) 2012-2016 Red Hat, Inc.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions of
# the GNU General Public License v.2, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY expressed or implied, including the implied warranties of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
# Public License for more details.  You should have received a copy of the
# GNU General Public License along with this program; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.  Any Red Hat trademarks that are incorporated in the
# source code or documentation are not subject to the GNU General Public
# License and may only be used or replicated with the express permission of
# Red Hat, Inc.
#

from __future__ import unicode_literals
import sys


def suppress_keyboard_interrupt_message():
    """Prevent unsightly KeyboardInterrupt tracebacks.

    Nothing will be printed to the terminal after an uncaught
    :class:`exceptions.KeyboardInterrupt`.

    """
    old_excepthook = sys.excepthook

    def new_hook(type, value, traceback):
        if type != KeyboardInterrupt:
            old_excepthook(type, value, traceback)
        else:
            pass

    sys.excepthook = new_hook


# do this ASAP to prevent tracebacks after ^C during imports
suppress_keyboard_interrupt_message()

if __name__ != "__main__":
    sys.stderr.write('The executable DNF module must not be imported.')
    sys.exit(1)

here = sys.path[0]
if here != '/usr/bin':
    # git checkout
    import os
    dnf_toplevel = os.path.dirname(here)
    sys.path[0] = dnf_toplevel

from dnf.cli import main
main.user_main(sys.argv[1:], exit_code=True)

系统python环境:

# which python
python                    python2.7-debug-config    python3.7                 python3-chardetect
python2                   python2-config            python3.7-config          python3-config
python2.7                 python2-debug             python3.7m                python-config
python2.7-config          python2-debug-config      python3.7m-config         python-debug
python2.7-debug           python3                   python3.7m-x86_64-config  python-debug-config


# ls -l /usr/bin/python
lrwxrwxrwx 1 root root 7  6月 10  2022 /usr/bin/python -> python2

# ls -l /usr/bin/python3
lrwxrwxrwx 1 root root 9  6月 10  2022 /usr/bin/python3 -> python3.7

如何给ansible指定interpreter的python版本?

配置文件:

[defaults]
ansible_python_interpreter=/usr/bin/python
[defaults]
ansible_python_interpreter=/usr/bin/python3

命令行:

ansible  -i hosts   all  -m   shell    -a    'date'     -e   'ansible_python_interpreter=/usr/bin/python3'
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,835评论 4 364
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,598评论 1 295
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,569评论 0 244
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,159评论 0 213
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,533评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,710评论 1 222
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,923评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,674评论 0 203
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,421评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,622评论 2 245
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,115评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,428评论 2 254
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,114评论 3 238
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,097评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,875评论 0 197
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,753评论 2 276
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,649评论 2 271

推荐阅读更多精彩内容