ansible ec2_group module failed to create new security group

1.6k views Asked by At

I have recently started learning ansible so it might sound like a noob question. I wrote a simple playbook(example.yml) which will create a security group in AWS ec2 using ansible's ec2_group module.

The playbook is -

---
- name: Add a security group to ec2
  hosts: local
  connection: local
  tasks:
    local_action:
      module: ec2_group
      name: TestSecurityGroup001
      description: A new ec2 security group via ansible playbook
      region: us-east-1
      rules:

        - proto: tcp
          from_port: 80
          to_port: 80
          cidr_ip: 0.0.0.0/0

        - proto: tcp
          from_port: 22
          to_port: 22
          cidr_ip: 10.0.0.0/8

        - proto: udp
          from_port: 10050
          to_port: 10050
          cidr_ip: 10.0.0.0/8

        - proto: udp
          from_port: 10051
          to_port: 10051
          group_id: abc123

When I do

$ ansible-playbook example.yml

PLAY [Add a security group to ec2] ******************************************** 

GATHERING FACTS *************************************************************** 
ok: [localhost]

PLAY RECAP ******************************************************************** 
localhost                  : ok=1    changed=0    unreachable=0    failed=0   

Now when I list the security groups

$ aws ec2 describe-security-groups --region=us-east-1 --group-name=TestSecurityGroup001
$ A client error (InvalidGroup.NotFound) occurred: The security group 'TestSecurityGroup001' does not exist

Can someone tell me what should be done to fix this.

1

There are 1 answers

1
Lorin Hochstein On

I think you're missing a - in your playbook, ansible expects tasks to be a list. Try this:

 tasks:
    - local_action:

instead of:

 tasks:
    local_action: