---
- name: Provision EC2 instance and configure Nginx
  hosts: localhost
  gather_facts: no
  tasks:
    - name: Launch EC2 instance
      amazon.aws.ec2_instance:
        instance_type: t2.micro
        image_id: "ami-062cddb9d94dcf95d"  # Amazon Linux 2 AMI ID
        region: ap-northeast-2
        security_groups:
          - web-server-sg  # 기존의 'group'을 'security_groups'로 변경
        key_name: ansible-key
        count: 1
        wait: yes
        tags:
          Name: web-server  # 기존의 'instance_tags'를 'tags'로 변경
        network:
          assign_public_ip: yes
      register: ec2_instance

    - name: Add new EC2 instance to the inventory
      add_host:
        name: "{{ ec2_instance.instances[0].public_ip_address }}"  # 'public_ip'를 'public_ip_address'로 수정
        groups: web_servers