ansible动态主机拒绝使用自定义解释器
我正在尝试在AWS上提供带有ec2模块的新机器 并在本地更新我的主机文件,以便下一个任务已经使用主机文件 因此,设置不是问题,甚至是本地主机文件的创建:ansible动态主机拒绝使用自定义解释器,ansible,ansible-inventory,Ansible,Ansible Inventory,我正在尝试在AWS上提供带有ec2模块的新机器 并在本地更新我的主机文件,以便下一个任务已经使用主机文件 因此,设置不是问题,甚至是本地主机文件的创建: - name: Provision a set of instances ec2: key_name: AWS region: eu-west-1 group: default instance_type: t2.micro image: am
- name: Provision a set of instances
ec2:
key_name: AWS
region: eu-west-1
group: default
instance_type: t2.micro
image: ami-6f587e1c # For Ubuntu 14.04 LTS use ami-b9b394ca # For Ubuntu 16.04 LTS use ami-6f587e1c
wait: yes
volumes:
- device_name: /dev/xvda
volume_type: gp2
volume_size: 50
wait: true
count: 2
vpc_subnet_id: subnet-xxxxxxxx
assign_public_ip: yes
instance_tags:
Name: Ansible
register: ec2
- name: Add all instance private IPs to host group
add_host:
hostname: "{{ item.private_ip }}"
ansible_ssh_user: ubuntu
groups: aws
with_items: "{{ ec2.instances }}"
- local_action: file path=./hosts state=absent
ignore_errors: yes
- local_action: file path=./hosts state=touch
- local_action: lineinfile line="[all]" insertafter=EOF dest=./hosts
- local_action: lineinfile line="{{ item.private_ip }} ansible_python_interpreter=/usr/bin/python3" insertafter=EOF dest=./hosts
with_items: "{{ ec2.instances }}"
- name: Wait for SSH to come up
wait_for:
host: "{{ item.private_ip }}"
port: 22
delay: 60
timeout: 600
state: started
with_items: "{{ ec2.instances }}"
- name: refreshing inventory cache
meta: refresh_inventory
- hosts: all
gather_facts: False
tasks:
- command: hostname -i
但是,下一个任务是简单打印hostname-i(仅用于测试)
失败,因为在Ubuntu 16.04 LTS Python 2.7上找不到它(有python3)
为此,我在动态主机文件中添加了以下行:
ansible_python_interpreter=/usr/bin/python3
但ansible似乎忽略了它,直接转到了缺少的Python2.7
我已尝试重新加载库存文件
meta: refresh_inventory
但这也没有帮助。
我做错了什么?我不确定刷新为什么不起作用,但我建议在
add\u host
部分进行设置,它可以接受任何变量
- name: Add all instance private IPs to host group
add_host:
hostname: "{{ item.private_ip }}"
ansible_ssh_user: ubuntu
groups: aws
ansible_python_interpreter: "/usr/bin/python3"
with_items: "{{ ec2.instances }}"
我还发现调试这个任务很有用
- debug: var=hostvars[inventory_hostname]
注意ansible中对Python3的支持仍然有点脆弱:@SztupY-是的,我知道,我只是想知道如果其他人需要使用python2.x中没有的Ubuntu16.04,他们会怎么做?