我正在使用ansible剧本在数字海洋中创建Droplet,并希望在启动时使用ansible对其进行配置。 Droplet创建成功,但是当我尝试在启动时对其进行配置时,它给了python依赖性问题。我知道它,但是现在我很困惑如何在启动时或即时安装它?以下是我的烦人剧本:
---
- hosts: localhost
tasks:
- name: Create new DO Droplet
digital_ocean:
state: present
command: droplet
name: ansibletest
api_token: xyz123
size_id: '1gb'
region_id: ams3
image_id: '39739486'
ssh_key_ids: '23625890'
register: my_droplet
- name: print info about my_droplet
local_action:
module: debug
msg= "ID is {{ my_droplet.droplet.id }} IP is {{ my_droplet.droplet.ip_address }}"
- name: Add new droplet to host group
local_action: add_host hostname={{ my_droplet.droplet.ip_address }} groupname=launched
- name: Wait for SSH to come up
local_action: wait_for host={{ my_droplet.droplet.ip_address }} port=22 delay=60 timeout=320 state=started
- hosts: launched
become: true
gather_facts: True
tasks:
- name: installing redis server
apt: name=redis-server state=latest
下面是我得到的错误,它与远程客户端上的python依赖关系有关。
fatal: [188.26.76.45]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 188.166.71.116 closed.\r\n", "module_stdout": "/bin/sh: 1: /usr/bin/python: not found\r\n", "msg": "MODULE FAILURE", "rc": 127}
我没有在AWS中解决此问题,因为EC2实例具有python2.7。您能否帮我解决此问题,以便我可以在启动时使用Ansible配置数字海洋飞沫。任何指导将不胜感激。
我已经使用以下命令运行了剧本: ansible-playbookdrop.yml-密钥文件“ /etc/ansible/tek.pem”
谢谢。
答案 0 :(得分:0)
您可以使用raw:
模块配置实例,该模块仅需要ssh访问。
您可以在kubespray bootstrap
role中看到这种情况的示例,但是tl; dr是:
- hosts: launched
gather_facts: no
become: yes
tasks:
- raw: |
set -e
# but you are responsible for your own idempotent behavior
if [ -x /usr/bin/python ]; then exit 0; fi
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y python
# now, in theory, you can resume using ansible modules
# and can do the equivalent of "gather_facts: yes"
- setup:
- # etc etc