I am unable to helm provision configmap. it is setting an entry in localhost and then running binary of sonarscanner but getting error and I think it is syntax related. any hints? line 32: could not find expected ':' i have no clue what it is implying to fix it.
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Values.sonarscanner.name }}-{{ .Values.sonarscanner.label }}
namespace: {{ .Release.Name }}
data:
SONAR_HOST_URL: "-Dsonar.host.url=http://{{ .Values.sonarqube.name }}-{{ .Values.service.label }}.{{ .Values.namespace }}:{{ .Values.sonarqube.containerPort }}"
SONAR_PROJECT_KEY: "-Dsonar.projectKey={{ .Values.sonarqube.project }}"
CODE_PATH: "-Dsonar.sources=."
CODE_REPO_URL: {{ .Values.repo.url }}
CODE_REPO_NAME: {{ .Values.repo.name }}
SONAR_PROJECT_NAME: "-Dsonar.projectName={{ .Values.sonarqube.project }}"
RU: {{ .Values.code.httpU }}
RT: {{ .Values.code.httpT }}
SONAR_TOKEN: {{ .Values.code.sonarT }}
repo_checkout.sh: |-
#!bin/bash
set -xe
apt-get update && apt install dnsutils iputils-ping git curl -yq
#Containers that fail to resolve repo url can use below step.
repo_url=$(nslookup CODE_REPO_URL | grep Non -A 2 | grep Name | cut -d: -f2)
repo_ip=$(nslookup CODE_REPO_URL | grep Non -A 2 | grep Address | cut -d: -f2)
if grep $repo_url /etc/hosts; then
echo "git dns entry exists locally"
else
echo "Adding dns entry for git inside container"
echo $repo_ip $repo_url >> /etc/hosts
fi
cat /etc/hosts
git clone "https://$RU:RT#$CODE_REPO_URL/r/a/$CODE_REPO_NAME" && (cd "$CODE_REPO_NAME" && mkdir -p .git/hooks && curl -Lo `git rev-parse --git-dir`/hooks/commit-msg https://$RU:RT#$CODE_REPO_URL/r/tools/hooks/commit-msg; chmod +x `git rev-parse --git-dir`/hooks/commit-msg)
output
in ./helmfile.yaml: command "/usr/local/bin/helm" exited with non-zero status:
PATH:
/usr/local/bin/helm
ARGS:
0: helm (4 bytes)
1: template (8 bytes)
2: sonarqube (9 bytes)
3: /var/folders/nf/7ghp7kvd76n7jyzdc34kfkqm0000gp/T/tmp.X5Vhyiol (61 bytes)
4: --namespace (11 bytes)
5: sonarqube (9 bytes)
6: --values (8 bytes)
7: /var/folders/nf/7ghp7kvd76n7jyzdc34kfkqm0000gp/T/helmfile1184228953/sonarqube-sonarqube-values-c8cb44f76 (104 bytes)
8: --values (8 bytes)
9: /var/folders/nf/7ghp7kvd76n7jyzdc34kfkqm0000gp/T/helmfile2806006960/sonarqube-sonarqube-values-7c87b8b85f (105 bytes)
10: --include-crds (14 bytes)
11: --kube-version=1.13.5 (21 bytes)
ERROR:
exit status 1
EXIT STATUS
1
STDERR:
Error: YAML parse error on sonarqube/templates/sonarscanner-cronjob.yaml: error converting YAML to JSON: yaml: line 21: could not find expected ':'
Use --debug flag to render out invalid YAML
COMBINED OUTPUT:
Error: YAML parse error on sonarqube/templates/sonarscanner-cronjob.yaml: error converting YAML to JSON: yaml: line 21: could not find expected ':'
Use --debug flag to render out invalid YAML
task failed: command "helmfile --selector name=sonarqube --quiet template --include-crds --args --kube-version=1.13.5" failed: exit status 1
I checked all the files under /template for line 21 as per line 21: could not find expected ':'and figured out that helm never complained about a configmap file where a key was referred from values on line 21.
but it never pointed out which file it was. luckily it atleast denoted ln21 and when i looked into all files, i saw that in another configmap file at ln21 there was no valuable entry.
this is how i debugged it and fixed it.
Related
I am trying to write a playbook which needs to
check if the resources exists in a namespace.
If not, 'deploy' it and if exists 'skip' the deployment as it is already available.
I am able to achieve the skip step but not the deploy step if is not exists.
- name: To check if the resource exists
shell: |
set -e -o pipefail;
kubectl get pods -n test | grep postgres
changed_when: false
register: checkpod
args:
executable: /bin/bash
- name: Print checkpod
debug:
msg: "{{ checkpod.stdout_lines }}"
- name: Task to run the optional to install postgres
shell: ansible-playbook -i ~/playbooks/deploy.yml
when: checkpod | length == 0
My error is this
"stderr": "No resources found in ama namespace.", "stderr_lines": ["No resources found in test namespace."], "stdout": "", "stdout_lines": []}
I have this job yaml which work well:
apiVersion: batch/v1
kind: Job
metadata:
name: cli-commands
spec:
template:
spec:
containers:
- name: cli-commands
image: ubuntu:22.04
command: [ 'bash', '-c']
args:
- DEBIAN_FRONTEND=noninteractive apt update && apt install -y curl && curl -sL https://aka.ms/InstallAzureCLIDeb | bash &&
echo installation successful &&
az storage directory create --account-name {{ .Values.env.secret.azurestorageaccountname | b64dec}} --name {{ .Release.Namespace }}
--share-name {{ .Values.systemFilesPath | default (.Values.serviceName) }}
--account-key *****
restartPolicy: Never
The issue is:
I need to change this part of code (first version):
--share-name {{ .Values.systemFilesPath | default (.Values.serviceName) }}
into this (second version):
--share-name {{ .Values.systemFilesPath | default coreregciqa/(.Values.serviceName) }}
but the second version doesn't work and throws this error:
bad character U+002F '/'
How can I resolve that?
All what I want to do is to create a default value which looks like that (for example):
coreregciqa/mono ,but I dont know how to deal with the '/' in this case.
My first version works well because I don't have the '/' there, but my second version doesn't work.
I need your advice please.
Thanks a lot.
Default needs a value after it, and it can't automatically complete the splicing, you need to explicitly call the function to connect the string.
Like this:
--share-name {{ .Values.systemFilesPath | default (printf "coreregciqa/%s" .Values.serviceName) }}
I have a tcpdump.yaml file that I and the rest of my team are able to run just fine in a terminal in VSCode (and Atom) on Mac, but when I try to run the same playbook on my Windows laptop, I get several fatal errors related to variable. This playbook runs without error on the other machines for our team, and I am waiting for my Mac to come in, but I would like to get this working in the mean time.
fatal: [sample-dev-04]: FAILED! => {"msg": "Unexpected templating type error occurred on ({{ tcpdump.stdout_lines | regex_search('10.[0-9]+.[0-9]+.[0-9]+') }}): expected string or bytes-like object"}
fatal: [sample-dev-04]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'tcpdump_switch' is undefined\n\nThe error appears to be in '/home/testuser/.ansible/testcode/Playbooks/tcpdump.yaml': line 21, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Print tcpdump relevant information\n ^ here\n"}
Here is the code in question. The first 3 tasks run without error; problems start with the Set_fact variables and Print tcpdump relevant information tasks (errors above respectively). I also get the same second error above in the resultant phpipam_tcpdump.yaml.
I am running Ubuntu 20.04 in WSL2 in Windows 10 21.04, GNU bash, version 5.0.17(1).
---
- name: Set default_mac
set_fact:
default_mac: "{{ ansible_facts.default_ipv4.macaddress }}"
- name: Set default_interface
set_fact:
default_interface: "{{ ansible_facts.default_ipv4.interface }}"
- name: Run tcpdump on default network interface
command: tcpdump -nn -v -i "{{ default_interface }}" -s 1500 -c 1 'ether[20:2] == 0x2000'
register: tcpdump
- name: Set_fact variables
set_fact:
tcpdump_switch: "{{ tcpdump.stdout_lines | regex_search('10.[0-9]+.[0-9]+.[0-9]+') }}"
tcpdump_port: "{{ tcpdump.stdout_lines | regex_search('GigabitEthernet+[0-9]+/[0-9]+/[0-9]+') }}"
tcpdump_vlan: "{{ tcpdump.stdout_lines | regex_search('bytes: [0-9]+') | regex_replace('bytes: ') }}"
- name: Print tcpdump relevant information
no_log: false
debug:
msg:
- "MAC: {{ default_mac }}"
- "Nework interface: {{ default_interface }}"
- "Switch IP: {{ tcpdump_switch }}"
- "Port: {{ tcpdump_port }}"
- "Vlan: {{ tcpdump_vlan }}"
- name: Include phpipam_tcpdump.yaml
include: ./phpipam_tcpdump.yaml
Team, using jenkins for helm deploy of a chart where plugins are installed as part of it.
Am, using ConfigMap to install fluentd plugins, and getting this error on Jenkins any hint?
Error: UPGRADE FAILED: unable to decode "": Object 'Kind' is missing in '{"install-plugins.sh":"#!/bin/sh\n fluent-gem install fluent-plugin-gelf-hs -v 1.0.4\n \n fluent-gem install fluent-plugin-kubernetes_metadata_filter -v 1.0.0\n \n fluent-gem install fluent-plugin-systemd -v 0.3.1\n \n fluent-gem install fluentd -v 1.0.2\n \n fluent-gem install gelf -v 3.0.0\n \n fluent-gem install json -v 2.1.0\n \n fluent-gem install oj -v 2.18.3"}'
err: exit status 1
Below is dry run but jenkins throwing above error
install-plugins.sh: |-
#!/bin/sh
fluent-gem install fluent-plugin-gelf-hs -v 1.0.4
fluent-gem install fluent-plugin-kubernetes_metadata_filter -v 1.0.0
My ConfigMap.yaml looks like below in helm chart
{{- range $plugin,$version := .Values.plugins.pluginsList }}
fluent-gem install -v {{ $plugin }} {{ $version }}
{{ end -}}
Not sure about the gem install format though.
You configmap.yaml should contain full Configmap object
apiVersion: v1
kind: ConfigMap
metadata:
name: configmap
data:
install-plugins.sh: |-
#!/bin/sh
{{- range $plugin,$version := .Values.plugins.pluginsList }}
fluent-gem install -v {{ $plugin }} {{ $version }}
{{ end -}}
I'm trying to pass in a command argument in Kubernetes Daemonset with Helm Charts which performs export of an new environment variable passed in from a cURL result.
command: ["/bin/bash","-c","export MACHINE_TYPE=$(curl --unix-socket /var/run/docker.sock http://docker/containers/rancher-agent/json | grep -oP 'CATTLE_HOST_LABELS=.+?\w+' | awk -F '=' '{print $2}')"]
The result should be that the variable is set in the container e.g. MACHINE_TYPE=compute
I have also tried using command + args like so:
command: ["/bin/bash","-c"]
args: ["export MACHINE_TYPE=$(`curl --unix-socket /var/run/docker.sock http://docker/containers/rancher-agent/json | grep -oP 'CATTLE_HOST_LABELS=.+?\w+' | awk -F = '{print $2}'`)"]
When I try to deploy the daemonset, I get an error message
"Error: YAML parse error on /templates/daemonset.yaml: error converting YAML to JSON: yaml: line 46: found unknown escape character"
The export command works if I run it from within the container.
My aim is to be able to set a final container environment variable (LABEL) from the daemonset.yaml which is concatenate of two environment variables e.g.
containers:
- name: {{ .Chart.Name }}
image: "{{.Values.image.repository}}:{{.Values.image.tag}}"
imagePullPolicy: {{.Values.image.pullPolicy}}
env:
- name: LABEL
value: $MACHINE_TYPE-$HOSTNAME
command: ["/bin/bash","-c"]
args: ["export MACHINE_TYPE=$(`curl --unix-socket /var/run/docker.sock http://docker/containers/rancher-agent/json | grep -oP 'CATTLE_HOST_LABELS=.+?\w+' | awk -F = '{print $2}'`)"]
so the 'env' output in the container for LABEL variable would be
LABEL=compute-ip-x-x-x-x.ap-southeast-2.compute.internal
I know that the value value: $MACHINE_TYPE-$HOSTNAME will not work, so hoping for assistance with that as well.
found unknown escape character 'w'
... rep -oP 'CATTLE_HOST_LABELS=.+?\w+' | awk -F '=' '{print $2}')"]
^)
The error message appears to be pretty straightforward: backslash is magic in a double-quoted string
If you use the more straightforward yaml structure, without using the double-quoted strings, you can use the single backslash as you wish:
command:
- /bin/bash
- -c
- export MACHINE_TYPE=$(curl --unix-socket /var/run/docker.sock http://docker/containers/rancher-agent/json | grep -oP 'CATTLE_HOST_LABELS=.+?\w+' | awk -F '=' '{print $2}')
and benefiting from the infinitely more legible syntax
Separately,
final container environment variable (LABEL) from the daemonset.yaml
In that case, you want the valueFrom: fieldPath: status.nodeName in your env: block to set HOSTNAME, and then (as you are currently doing) build up the LABEL from its MACHINE_TYPE component right before executing the actual in-container command. You cannot (that I am aware of) declare LABEL in the kubernetes descriptor's env block because you are mixing metaphors trying to run a command in a container that affects the kubernetes descriptor for that command.
I know that the value value: $MACHINE_TYPE-$HOSTNAME will not work, so hoping for assistance with that as well. Thanks in advance.
There are plenty of existing SO answers about that, but the syntax is $(MACHINE_TYPE)-$(HOSTNAME) assuming those two env-vars are declared in the Pod's env: block, and not otherwise