Richard E
Richard E

Reputation: 384

ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path

I trying to create a simple paybook with a common role. Unfortunately I get stymied by ansible. I have looked up and down the internet for solution for this error.

The setup: I am running ansible 2.7.4 on Ubuntu 18.04

directory structure:

~/Ansible_Do
 playbook.yml
 inventory  (hosts file) 
    /roles
      /common 
        /defaults
            main.yml   (other variables)
        /tasks
            main.yml
            richard_e.yml
        /vars
            vars_and_stuff.yml   (vault)

I have a simple playbook.yml

---
# My playbook 1
- hosts: test

- name: Go to common role to run tasks.
  roles:
    - common

  tasks:
  - name: echo something
    shell: echo $(ip addr | grep inet)
...

I run this command to start the playbook:

~/Ansible_Do$ ansible-playbook -vv --vault-id @prompt -i ~/Ansible_Do/inventory playbook.yml

I enter the vault password continuing the playbook.

The playbook starts pulls facts from the test group of servers. Then reads the role and works to /roles/common. That calls the /common/tasks/main.yml file. This is where the error happens.

The error appears to have been in '/home/~/Ansible_Do/roles/common/tasks/main.yml': line 8, column 3

# Common/tasks file
---
- name: Bring variable from vault
  include_vars:
    file: vars_and_stuff.yml
    name: My_password

- name: Super Richard   <======  Error 
  become: yes  
  vars:
    ansible_become_pass: "{{ My_password }}"

- import_tasks: ./roles/common/tasks/ricahrd_e.yml
...

The ./roles/common/tasks/ricahrd_e.yml is a simple testing task.

---
- name: say hi
  debug:
    msg: "Active server."
...

The error on "- name". I have checked online and in the Ansible docs to see if there is a key I'm missing. I found an example for include_vars in a /role/tasks (https://gist.github.com/halberom/ef3ea6d6764e929923b0888740e05211) showing proper syntax (I presume) in a simple role. The code works as parts, but not together.

I have reached what I can understand. I feel that is error is utterly simple and I am missing something (forest for the trees).

Upvotes: 1

Views: 7277

Answers (2)

Richard E
Richard E

Reputation: 384

After a bit of work I got the playbook to work. Knowing that 'become' is not a task was the start. I also found out how to pull the proper vars from the vault.

# My first playbook 1
- hosts: test
  become: yes

  vars_files:
  - ./roles/common/vars/vars_and_stuff.yml

  vars:
    ansible_become_pass: "{{ My_password }}"

  roles:
    - common

  tasks:
  - name: echo something
    shell: echo $(ip addr | grep inet)

The vars file access the vault and then vars: pulls the password used by become. With become in force I ran the other tasks in the common role with a last standalone task. Lastly, don't try to - name: at the top level of the playbook as it trigger a hosts undefined error.

Upvotes: 1

Thomas Hirsch
Thomas Hirsch

Reputation: 2308

The error means exactly what it says, except the "module name" is not misspelled in your case, but missing altogether.

This...

- name: Super Richard   <======  Error 
  become: yes  
  vars:
    ansible_become_pass: "{{ My_password }}"

... is not a valid task definition, it does not declare an action.
An action in Ansible is a call to a module, hence "misspelled module name".
The error comes after name, because that's where Ansible expects the name of the "module" that you want to call, e.g. shell in your first example.

You are probably assuming that become is a "module", but it is not.
It is a "playbook keyword", in this case applied on the task level, which has the effect that you become another user for this task only. But as the task has no action, you get this error.

See docs:
Playbook keywords
Understanding privilege escalation

Upvotes: 1

Related Questions