Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CentOS 5。ansible_python_解释器=/usr/bin/python26。仍然无法使用yum:module_Python_Linux_Ansible - Fatal编程技术网

CentOS 5。ansible_python_解释器=/usr/bin/python26。仍然无法使用yum:module

CentOS 5。ansible_python_解释器=/usr/bin/python26。仍然无法使用yum:module,python,linux,ansible,Python,Linux,Ansible,仍然需要保留一些CentOS5主机,它们已将yum配置为使用CentOS vault repo,如下所示。在主机上使用yum时,这一点很好。 然而,当我尝试使用ansible时,比如: - name: "Install OS packages" yum: pkg={{item}} state=installed with_items: - dos2unix - vim 我得到消息:这个模块需要rpm的python2绑定。此模块需要pyt

仍然需要保留一些CentOS5主机,它们已将yum配置为使用CentOS vault repo,如下所示。在主机上使用yum时,这一点很好。 然而,当我尝试使用ansible时,比如:

   - name: "Install OS packages"
     yum: pkg={{item}} state=installed
     with_items: 
       - dos2unix
       - vim 
我得到消息:这个模块需要rpm的python2绑定。此模块需要python2 yum模块

注意:主机在default24旁边安装了python26 在清单文件中,主机名旁边有ansible_python_解释器=/usr/bin/python26,否则ansible甚至不能-m ping。其他ansible任务可与此主机配合使用

yum模块需要rpm-Python模块,该模块由rpm-Python包提供。在您的系统上,这是为Python 2.4安装的;您还没有为Python 2.6安装它。这是一个必须从源代码编译的二进制模块,它是rpm发行版的一部分

如果您需要支持CentOS 5,最简单的解决方案可能是使用命令模块代替yum模块:


由于ansible的本机yum:module看起来不容易解决这个问题,所以我是这样做的:

- block:                                                                                                                                
    - debug: msg="Special actions for centos 5,  vault and epel repo"                                                             
    - copy:                                                                                                                             
        src: "CentOS-Vault.repo"                                                                                                        
        dest: /etc/yum.repos.d/CentOS-Vault.repo                                                                                        
    - copy:                                                                                                                             
        src: "epel-release-5-4.noarch.rpm"                                                                                              
        dest: /tmp/epel-release-5-4.noarch.rpm                                                                                          
    - shell: "rpm -ivh /tmp/epel-release-5-4.noarch.rpm"                                                                                
      ignore_errors: true                                                                                                               
      register: epelrpmres                                                                                                              
      changed_when: "'is already installed' not in epelrpmres.stderr"                                                                   
    - shell: >                                                                                                                          
        yum --disablerepo=* --enablerepo=C5*,epel* -y install                                                                           
        dos2unix moreutils vim-minimal vim-enhanced tmux tcping                                                                         
        rsync openssh-clients htop screen tar                                                                                           
      register: yumresult                                                                                                               
      changed_when: "'Nothing to do' not in yumresult.stdout"                                                                           
  when: "ansible_distribution_major_version in ['5']" 

希望这能帮助其他人…

似乎是说RPM和yum绑定丢失了,而不是Python丢失了。事实上,我自己也得到了类似的shell:说明谢谢你的解释,可惜ansible doc网站没有提到它
- block:                                                                                                                                
    - debug: msg="Special actions for centos 5,  vault and epel repo"                                                             
    - copy:                                                                                                                             
        src: "CentOS-Vault.repo"                                                                                                        
        dest: /etc/yum.repos.d/CentOS-Vault.repo                                                                                        
    - copy:                                                                                                                             
        src: "epel-release-5-4.noarch.rpm"                                                                                              
        dest: /tmp/epel-release-5-4.noarch.rpm                                                                                          
    - shell: "rpm -ivh /tmp/epel-release-5-4.noarch.rpm"                                                                                
      ignore_errors: true                                                                                                               
      register: epelrpmres                                                                                                              
      changed_when: "'is already installed' not in epelrpmres.stderr"                                                                   
    - shell: >                                                                                                                          
        yum --disablerepo=* --enablerepo=C5*,epel* -y install                                                                           
        dos2unix moreutils vim-minimal vim-enhanced tmux tcping                                                                         
        rsync openssh-clients htop screen tar                                                                                           
      register: yumresult                                                                                                               
      changed_when: "'Nothing to do' not in yumresult.stdout"                                                                           
  when: "ansible_distribution_major_version in ['5']"