美文网首页
【ansible】ansible指定interpreter的py

【ansible】ansible指定interpreter的py

作者: Bogon | 来源:发表于2024-04-11 10:52 被阅读0次

    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'
    

    相关文章

      网友评论

          本文标题:【ansible】ansible指定interpreter的py

          本文链接:https://www.haomeiwen.com/subject/luicxjtx.html