Ansible playbook to automate security configurations of an EC2 instance

0 votes

I am creating an Ansible playbook that would automate the security configurations of creating an EC2 Intance. This is my playbook, but I get a lot of errors when I try to execute it.

- hosts:localhost
  tasks:
    - name:Setting up Security/Firewall Group
      ec2_group:
         name:aws-security
         description:Rules Allowing Traffic on port 22 and 80
         region: us-west-2
         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: 0.0.0.0/0
         rules_egress:
          - proto: all
            cidr_ip: 0.0.0.0/0
Jan 24, 2019 in Ansible by Kiara
747 views

1 answer to this question.

0 votes

Hey @Kiara, your indentation is very wrong. Yaml files are very sensitive with spacing and indentation. 

Also keep your host as 'all'

- hosts: all
  tasks:
    - name: Setting up Security/Firewall Group
      ec2_group:
         name: aws_security_group
         description: Rules Allowing Traffic on port 22 and 80
         region: us-west-2
         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: 0.0.0.0/0
         rules_egress:
          - proto: all
            cidr_ip: 0.0.0.0/0
answered Jan 24, 2019 by Harsh

Related Questions In Ansible

0 votes
1 answer

How to launch an EC2 instance using Ansible Playbook?

Hi@akhtar, Ansible has one module named ec2. This ...READ MORE

answered Aug 12, 2020 in Ansible by MD
• 95,460 points
1,937 views
0 votes
1 answer

How to check the syntax of an Ansible playbook?

Hi@akhtar, Ansible has lots of commands, that help ...READ MORE

answered Sep 15, 2020 in Ansible by MD
• 95,460 points
12,672 views
0 votes
1 answer

How to do SSH in EC2 instance using Ansible Playbook?

Hi@akhtar, To configure your inventory dynamically you need ...READ MORE

answered Sep 21, 2020 in Ansible by MD
• 95,460 points
2,392 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
3,921 views
+2 votes
1 answer
0 votes
1 answer

Role of subelement module in an Ansible playbook

Hey @Rahul thanks for a better question ...READ MORE

answered Jan 16, 2019 in Ansible by Emily
2,296 views
0 votes
1 answer

Is it possible to run an Ansible Playbook in python script?

Hey @Cerci, Of course its possible. You ...READ MORE

answered Jan 17, 2019 in Ansible by Nicolas
15,525 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP