【问题标题】:ERROR! no action detected in task, ansible错误!任务中未检测到任何动作,ansible
【发布时间】:2020-05-03 15:06:57
【问题描述】:

我正在使用 ansible version 2.5.1 和 python version 2.7.17 并安装了一个开放式班次。

剧本如下所示:

---
- 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

这是错误:


[警告]:提供的主机列表为空,只有 localhost 可用。请注意,隐式 localhost 不匹配 'all'

错误!任务中未检测到任何操作。这通常表示模块名称拼写错误或模块路径不正确。

错误似乎出现在“/home/rocco/cc-webapp.yml”中:第 4 行第 5 列,但可能 根据确切的语法问题,位于文件中的其他位置。

违规行似乎是:

tasks:
- name: Create a k8s namespace
  ^ here

【问题讨论】:

    标签: kubernetes ansible yaml


    【解决方案1】:

    k8s 模块可用的最低 ansible 版本是 2.6。 (Reference)

    别无选择,你必须升级。

    注意:我在 ansible 2.9.2 中测试了您的剧本语法,没有任何错误

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-05
      • 2017-05-06
      • 1970-01-01
      • 1970-01-01
      • 2018-04-19
      • 2017-07-10
      • 1970-01-01
      相关资源
      最近更新 更多