2
votes

I'm trying to deploy ec2 instances with ansible.

I keep getting an error that says:

FAILED! => {"msg": "running list needs to be a list of instances to run: None",

site.yml

---
- hosts: hornet
  user: root
  sudo: false
  gather_facts: False
  serial: 1
  roles:
    -  role: ec2

roles/ec2/tasks/main.yml

---
- include_vars: "env.yml"
- name: create an EC2 instance
  local_action:
    module: ec2
    key_name: "{{ key_name }}"
    region: "{{ region }}"
    instance_type: "{{ instance_type }}"
    image: "{{ image }}"
    group_id: "{{ security_group }}"
    wait: yes
    private_ip: "{{ privip }}"
    assign_public_ip: True
    state: running
    instance_tags: { "{{ ectags }}","name: {{ inventory_hostname }}"}
    count: 1
    register: basic_ec2

I have two hosts in the hosts file.

[hornet]
awo-p01-hm02 privip=`UniqueIP` ectags="{purpose:hornetMQ}"
awo-p01-hm03 privip=`UniqueIP` ectags="{purpose:hornetMQ}"
1
please show your hosts file.tedder42

1 Answers

6
votes

I suspect you actually want state: present. state: running is for starting existing instances (that you pass with instance_ids: [ ... ]).

Horribly confusing and poorly documented, I know. The ec2 module tries to do too many things. :(