自動化運維工具ansible-如何設置客戶端多python版本問題


問題:在使用ansible進行管理客戶主機時,發現客戶主機安裝了多個版本的python,並且默認版本為3.0

 

shell>>cat list

192.168.2.9

 

shell>>ansible all -m ping -i list --ask-pass -u test

會報如下錯誤信息:

192.168.2.9 | FAILED >> {
                                       "failed": true, 
                                       "msg": "  File \"/home/test/.ansible/tmp/ansible-1382616743.5-201381009945012/ping\", line 340\n    except OSError, e:\n                  ^\nSyntaxError: invalid syntax\n",
                                       "parsed": false

                                       }

原因很簡單:python版本的不兼容性導致的語法錯誤;

 

ansible額外提供了一個變量:ansible_python_interpreter

 

添加參數:

shell>>cat list

192.168.2.9  ansible_python_interpreter=/usr/bin/python2.4

 

shell>>ansible all -m ping -i list --ask-pass -u test

 

192.168.2.9 | success >> {
    "changed": false,
    "ping": "pong"
}

 

OK返回正確的ping結果,成功運行


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM