Home > Net >  Create namespace with Ansibl. Export NAMESPACE=awx
Create namespace with Ansibl. Export NAMESPACE=awx

Time:10-26

Hello!

I tired to create some playbook for deploying "AWX Operator" and Kubernetes using manual of installation Install AWX Operator

I have the command:

export NAMESPACE=awx
kubectl create ns ${NAMESPACE}

I created tasks:

- name: Echo export NAMESPACE awx
  shell: "export NAMESPACE=awx"
  environment:
    NAMESPACE: awx

- name: my_env_var 
  shell: "kubectl create ns NAMESPACE"

But I get an error:

fatal: [jitsi]: FAILED! => {"changed": true, "cmd": "kubectl create ns NAMESPACE", "delta": "0:00:00.957414", "end": "2021-10-22 13:25:16.822714", "msg": "non-zero return code", "rc": 1, "start": "2021-10-22 13:25:15.865300", "stderr": "The Namespace \"NAMESPACE\" is invalid: metadata.name: Invalid value: \"NAMESPACE\": a lowercase RFC 1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name',  or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')", "stderr_lines": ["The Namespace \"NAMESPACE\" is invalid: metadata.name: Invalid value: \"NAMESPACE\": a lowercase RFC 1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name',  or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')"], "stdout": "", "stdout_lines": []}

Could you please help me with advice? Thank you.

CodePudding user response:

You have everything written in this error :)

There is a problem with the command

kubectl create ns NAMESPACE

You want to create a namespace called NAMESPACE which is wrong. You cannot use capital letters in the name of the namespace. You can get hint from this message:

Invalid value: \"NAMESPACE\": a lowercase RFC 1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name',  or '123-abc'

How to solve it? You need to change this line:

shell: "kubectl create ns NAMESPACE"

You need to proper set your namespace without capital letters.

Examples:

shell: "kubectl create ns my-namespace"
shell: "kubectl create ns my-name"
shell: "kubectl create ns whatever-you-want"
  • Related