0
在這裏我們有一個劇本的EC2模塊:ansible EC2 with_items failling
---
# This playbook creates dev-test instances at AWS.
- name: test creation
hosts: localhost
gather_facts: False
tasks:
- name: instance creation
ec2:
key_name: dev-key
group_id: sg-55667788
instance_type: t2.micro
image: ami-cd0f5cb6
wait: yes
wait_timeout: 300
volumes:
- device_name: /dev/sda1
volume_type: gp2
volume_size: 32
delete_on_termination: True
- device_name: /dev/xvdb
volume_type: gp2
volume_size: 1
delete_on_termination: True
- device_name: /dev/xvdc
volume_type: gp2
volume_size: 200
delete_on_termination: True
vpc_subnet_id: "{{ item.vpc_subnet_id }}"
zone: "{{ item.zone }}"
region: us-east-1
assign_public_ip: no
private_ip: "{{ item.private_ip }}"
instance_tags:
Name: "{{ item.tag_name }}"
user_data: |
#!/bin/bash
mkswap /dev/xvdb
swapon /dev/xvdb
echo "/dev/xvdb none swap sw 0 0" >> /etc/fstab
echo "n
e
1
n
l
w
" | fdisk /dev/xvdc
with_items:
- { vpc_subnet_id: 'subnet-11223344', zone: 'us-east-1d', private_ip: '172.31.5.15', tag_name: 'dev-test.vpc-01' }
- { vpc_subnet_id: 'subnet-44332211', zone: 'us-east-1e', private_ip: '172.31.7.13', tag_name: 'dev-test.vpc-01' }
而且這裏的錯誤輸出:
[email protected]:~$ ansible-playbook --check create-ec2.yml
[WARNING]: Could not match supplied host pattern, ignoring: all
[WARNING]: provided hosts list is empty, only localhost is available
PLAY [instance creation] *********************************************************************************************************
TASK [instance creation] ************************************************************************************************************
fatal: [localhost]: FAILED! => {"failed": true, "msg": "The task includes an option with an undefined variable. The error was: 'item' is undefined\n\nThe error appears to have been in 'create-ec2.yml': line 8, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: cria instancia\n ^here\n\nexception type: <class 'ansible.errors.AnsibleUndefinedVariable'>\nexception: 'item' is undefined"}
to retry, use: --limit @create-ec2.retry
PLAY RECAP ***********************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1
我沒有看到那裏的錯誤是。這個項目在哪裏未定義?