我正在使用alpine运行一个docker容器。运行ansible脚本从AWS获取动态库存,它与python2配合得很好。但我要把它改成python3,这给我带来了问题。收到警告,无法解析
在python2中,我能够以这种方式运行python脚本/ec2.py
现在有了python3,我得到了这个错误:env: can't execute 'python': No such file or directory
[WARNING]: * Failed to parse ci/ec2.py with script
plugin: Inventory script (ci/ec2.py) had an execution
error: env: can't execute 'python': No such file or directory
[WARNING]: * Failed to parse ci/ec2.py with ini plugin:
ci/ec2.py:3: Error parsing host definition ''''': No
closing quotation
[WARNING]: Unable to parse ci/ec2.py as an inventory
source
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that
the implicit localhost does not match 'all'
Python 3
apk --update --no-cache add python3 py3-setuptools
pip3 install --upgrade pip
pip3 install awscli ansible boto
chmod 755 ec2.py
ansible-playbook provisioning/ec2New.yml -i ec2.py --private-key ssh-key.pem -e "type_inventory=${TYPE_INVENTORY}
ansible.cfg
[defaults]
host_key_checking = False
stdout_callback = yaml
ansible_python_interpreter = /usr/bin/python3
我使用python 2的旧配置
apk --update --no-cache add python py-pip
pip install --upgrade pip
pip install awscli ansible botocore boto
chmod 755 ec2.py
ansible-playbook provisioning/ec2New.yml -i ec2.py --private-key ssh-key.pem -e "type_inventory=${TYPE_INVENTORY}
旧ansible.cfg
defaults
host_key_checking = False
stdout_callback = yaml
如果您将ec2.py
文件中的第一行更改为:,我也遇到了上述相同的问题
#!/usr/bin/env python3
然后它应该按预期进行解析和工作。
我注意到你的评论,似乎python3
在shebang中被替换错了。
如果我将其替换为:/usr/bin/python3:无法打开文件"python":[Erno 2]没有这样的文件或目录–Diego2020年4月10日下午3:43
因此,如果您遵循上面的解决方案"应该";工作