ERROR! no action detected in task, ansible

1/16/2020

I am using ansible version 2.5.1 with python version 2.7.17 and I installed an open shift.

The playbook looks like this:

---
- hosts: node 1 
  tasks:
  - name: Create a k8s namespace
    k8s:
      name: CC_Namespace
      api_version: v1
      kind: Namespace
      state: present
  # Deployment Frontend 
  - name: Create a Frontend Deployment Object
    k8s:
      apiVersion: v1
      kind: Deployment
      metadata:
        name: nginx-frontend-deployment
        labels:
          app: nginx
      spec:
        replicas: 4
        selector:
          matchLabels:
            app: nginx
        template:
          metadata:
            labels:
              app: nginx
          spec:
            containers:
            - name: nginx
              image: nginx:1.7.9 
              ports:
              - containerPort: 80
          livenessProbe:
            exec:
              command:
              - /ready
          readinessProbe:
            exec:
              command:
              - /ready
  # Deployment Backend 
  - name: Create a Backend Deployment Object
    k8s:
      apiVersion: v1
      kind: Deployment
      metadata:
        name: nginx-backend-deployment
        labels:
          app: nginx
      spec:
        replicas: 6
        selector:
          matchLabels:
            app: nginx
        template:
          metadata:
            labels:
              app: nginx
          spec:
            containers:
            - name: nginx
              image: nginx:1.7.9 # change to Dockerfile  
              ports:
              - containerPort: 80
          livenessProbe:
            exec:
              command:
              - /ready
          readinessProbe:
            exec:
              command:
              - /ready
  # Service Backend
  - name: Create a Backend Service Object
    k8s:
      apiVersion: v1
      kind: Service
      metadata:
        name: cc-backend-service
      spec:
        selector:
          app: CCApp
        ports:
          - protocol: TCP
            port: 80
        type: ClusterIP
  # Serive Frontend
  - name: Create a Frontend Service Object
    k8s:
      apiVersion: v1
      kind: Service
      metadata:
        name: cc-frontend-service
      spec:
        selector:
          app: CCApp
        ports:
          - protocol: TCP
            port: 80
        type: NodePort

and this is the error:


[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

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

The error appears to have been in '/home/rocco/cc-webapp.yml': line 4, column 5, but may be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

tasks: - name: Create a k8s namespace ^ here


thanks for your help!

-- ally
ansible
kubernetes
yaml

1 Answer

1/16/2020

The minimum ansible version to have k8s module available is 2.6.

Ref: https://docs.ansible.com/ansible/latest/modules/k8s_module.html.

No choice, you have to upgrade.

Note: I tested your playbook syntax without any errors in ansible 2.9.2

-- Zeitounator
Source: StackOverflow