ERROR! no activity was found in the task. ansible

I recently started using Ansible, and I have a playbook file, the contents are as follows:

...# Code to start an EC2 instance in the same playbook
...# Then trying to install Nginx on the same server:

  - hosts: webserver
    become: yes
    remote_user: ubuntu
    tasks:
      - name: Install Nginx
        apt: pkg=nginx state=installed update_cache=true
        notify:
          - start nginx

And I get the following error when starting using

ansible-playbook -i hosts ec2_launch.yml

ERROR! no activity was found in the task. it is often indicated by the name of the module with an error or the wrong path to the module.

The offending line appears to be:

  - hosts: webserver
    ^ here

Something is missing for me, I can’t understand what needs to be updated. Maybe I can not start the instance and install Nginx in the same game?

Thanks in advance.

+4
source share
1 answer

Update this to show how this problem was resolved:

---
  - name: Provision an EC2 Instance
    hosts: local
    connection: local
    gather_facts: True
    tags: provisioning
    # Necessary Variables for creating/provisioning the EC2 Instance
    vars:
      instance_type: t2.micro
      security_group: Webserver  # Change the security group name here
      image: amiID # Change the AMI, from which you want to launch the server
      region: eu-central-1 # Change the Region
      keypair: keypair # Change the keypair name
      count: 1

    # Task that will be used to Launch/Create an EC2 Instance
    tasks:
      - name: Launch the new EC2 Instance
        local_action: ec2 
                      group={{ security_group }} 
                      instance_type={{ instance_type}} 
                      image={{ image }} 
                      wait=true 
                      region={{ region }} 
                      keypair={{ keypair }}
                      count={{count}}
        register: ec2

      - name: Add new instance to host group
        add_host: hostname={{ item.public_ip }} groupname=launched
        with_items: ec2.instances

      - name: Wait for SSH to come up
        local_action: wait_for 
                      host={{ item.public_ip }} 
                      port=22 
                      state=started
        with_items: ec2.instances

      - name: Add tag to Instance(s)
        local_action: ec2_tag resource={{ item.id }} region={{ region }} state=present
        with_items: ec2.instances
        args:
          tags:
            Name: webserver

  - name: Install Nginx on this new instance
    hosts: launched
    become: yes
    remote_user: ubuntu
    tasks:
      - name: Install Nginx
        apt: pkg=nginx state=installed update_cache=true
        notify:
          - start nginx

Ansible -, , .

0

All Articles