YAML exception: Invalid Yaml - amazon-web-services

I am trying to implement encryption a Tomcat Server on AWS Elastic Beanstalk.
I have just followed this, and created a .ebextensions/https-instance.config file.
But when I deploy to the server, I get:
The configuration file .ebextensions/https-instance.config in
application version thewhozoo-1.0.0.25 contains invalid YAML or JSON.
YAML exception: Invalid Yaml: while scanning a simple key in
"", line 4, column 1: -----BEGIN CERTIFICATE----- ^ could not
found expected ':' in "", line 5, column 1:
MIIDnDCCAoACCQCzIxYAYJicIjANBgkq ... ^ , JSON exception: Invalid JSON:
Unexpected character (f) at position 0.. Update the configuration
file.
What I am doing incorrectly?
UPDATE
I changed the file to:
But get the following:
The configuration file .ebextensions/https-instance.config in
application version thewhozoo-1.0.0.31 contains invalid YAML or JSON.
YAML exception: Invalid Yaml: while parsing a block mapping in
"", line 7, column 5: mode: "000400" ^ expected ,
but found Scalar in "", line 32, column 6: -----END
CERTIFICATE----- ^ , JSON exception: Invalid JSON: Unexpected
character (p) at position 0.. Update the configuration file.

You'll have to indent your certificate data more than the column of content:
files:
/etc/pki/tls/certs/server.crt:
content: |
-----BEGIN CERTIFICATE----
MI.......
Wk.......
That is the way the literal scalar in block style works. As you can have empty lines in such a literal scalar, as well as (further) indented lines, the parser would otherwise not know that your scalar had ended or not (that is would not assume /etc/pki/tls/certs/server.key: to be part of the literal scalar).

Related

Ansible inventory file in google cloud won't parse with any playbooks

My inventory file won't work for any of my playbooks I've tested it on multiple playbooks including ones that have worked for me in the past. I can't seem to figure out what's misconfigured or where the issue might be. The inventory file is fairly simple, and I have all of the requisites for getting ansible to run, ansible is up to date, and I'm positive the credentials file is fine since it's been working on my terraform configuration. Any input is appreciated!
Inventory file:
plugin: gcp_compute
projects:
- projectName
auth_kind: serviceaccount
service_account_file: /home/.../.config/gcloud/application_default_credentials.json
keyed_groups:
- prefix: gcp
key: labels
- prefix: tags
key: tags
Error that comes up when I try to use inventory:
config file = None
configured module search path = ['/home/.../.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/.../.local/lib/python3.10/site-packages/ansible
ansible collection location = /home/.../.ansible/collections:/usr/share/ansible/collections
executable location = /home/.../.local/bin/ansible-playbook
python version = 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0] (/usr/bin/python3)
jinja version = 3.0.3
libyaml = True
No config file found; using defaults
host_list declined parsing /home/.../inventory.gcp.yaml as it did not pass its verify_file() method
redirecting (type: inventory) ansible.builtin.gcp_compute to google.cloud.gcp_compute
Using inventory plugin 'ansible_collections.google.cloud.plugins.inventory.gcp_compute' to process inventory source '/home/.../inventory.gcp.yaml'
toml declined parsing /home/.../inventory.gcp.yaml as it did not pass its verify_file() method
[WARNING]: * Failed to parse /home/.../inventory.gcp.yaml with script plugin: problem running
/home/.../inventory.gcp.yaml --list ([Errno 8] Exec format error:
'/home/.../inventory.gcp.yaml')
File "/home/.../.local/lib/python3.10/site-packages/ansible/inventory/manager.py", line 293, in parse_source
plugin.parse(self._inventory, self._loader, source, cache=cache)
...
plugin.parse(self._inventory, self._loader, source, cache=cache)
File "/home/.../.local/lib/python3.10/site-packages/ansible/plugins/inventory/yaml.py", line 114, in parse
raise AnsibleParserError('Plugin configuration YAML file, not YAML inventory')
[WARNING]: * Failed to parse /home/.../inventory.gcp.yaml with ini plugin: Invalid host pattern
'plugin:' supplied, ending in ':' is not allowed, this character is reserved to provide a port.
File "/home/.../.local/lib/python3.10/site-packages/ansible/inventory/manager.py", line 293, in parse_source
plugin.parse(self._inventory, self._loader, source, cache=cache)
File "/home/.../.local/lib/python3.10/site-packages/ansible/plugins/inventory/ini.py", line 137, in parse
raise AnsibleParserError(e)
[WARNING]: Unable to parse /home/.../inventory.gcp.yaml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit

pandoc error: [WARNING] Could not parse YAML metadata: Unexpected 'd'

I am not sure why I get the following error message while converting markdown to PDF with a template:
[WARNING] Could not parse YAML metadata at line 10 column 1: Unexpected 'd'
Here is the command I use to build the document:
pandoc --template eisvogel -o output.pdf input.md
Here is the markdown file:
---
titlepage: true
title: Some title
author: [Author]
date: "2022-11-25"
colorlinks: true
disable-header-and-footer: true
---
# Quick Introduction
A famous guy once said:
The error occurs when I add the disable-header-and-footer: true. If this line is not here, then the Pandoc processes the document.
The space after the colon in the offending line is not a normal (ASCII) space but the Unicode character U+202F, "Narrow Non-Break Space". The YAML parser doesn't see a key-value pair but a single word because of that. Replace it with an ASCII space and everything should work.

Gradle copy task expand yaml file escape whole string

I have the following gradle task:
processResources {
inputs.properties(project.properties.findAll { it.value instanceof String })
filesMatching("**/*.yaml") {
filteringCharset = 'UTF-8'
expand project.properties
}
}
that I use to process a spring boot application.yaml file that contains variable placeholders.
How can I escape a whole log pattern without escaping every single special character, thus keeping the pattern clean?
application.yaml:
logging:
pattern:
console: %clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}
Tried using slashy strings with no success:
1.Tried:
/%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}/
Error:
Caused by: groovy.lang.GroovyRuntimeException: Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): startup failed:
SimpleTemplateScript8.groovy: 138: expecting '}', found 'HH' # line 138, column 60.
ATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.S
^
2.Tried:
$/%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}/$
Error:
Caused by: groovy.lang.GroovyRuntimeException: Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): startup failed:
SimpleTemplateScript10.groovy: 138: illegal string body character after dollar sign;
solution: either escape a literal dollar sign "\$5" or bracket the value expression "${5}" # line 138, column 15.
console: $/%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}/$
^
Given that your YAML files contains character which are interpreted as tokens by the expand method, relying on Groovy's SimpleTemplateEngine, you should use an alternative method like the filter methods.
The documentation shows a number of examples of filter. By using the underlying Ant ReplaceTokens you might have better luck, as it uses #token# as the notation.

Loading entire Json blob as is from S3 in AWS Redshift using COPY gives error

I am trying to load S3 data into redshift using COPY command using following jsonPaths
{
_meta-id : 1,
payload: {..}
}
In my redshift table, I want to store entire JSON doc as my second column
{
"jsonpaths": [
"$['_meta-id']",
"$"
]
}
This gives error
Invalid JSONPath format. Supported notations are 'dot-notation' and 'bracket-notation': $
Query:
copy table_name
from 's3://abc/2018/12/15/1'
json 's3://xyz/jsonPaths';
[Amazon](500310) Invalid operation: Invalid JSONPath format. Supported notations are 'dot-notation' and 'bracket-notation': $..
Details:
-----------------------------------------------
error: Invalid JSONPath format. Supported notations are 'dot-notation' and 'bracket-notation': $
code: 8001
context:
query: 21889
location: s3_utility.cpp:672
process: padbmaster [pid=11925]
-----------------------------------------------;
1 statement failed.
Can someone help?

AWS error while parsing .config YAML file in .ebextension

When deploying to Elasticbeanstalk, my deploy fails with a parsing error caused by a .config file i have in the .ebextension folder, but it seems ok to me. Anyone can tell me how to fix it?
The .config file looks like this:
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/01_copy_htaccess_after_deployment.sh":
mode: "000755",
owner: root,
group: root,
content: |
yes | /bin/cp /var/app/current/.htaccess.new /var/app/current/.htaccess
And the error:
The configuration file
.ebextensions/08_htaccess_create_script_post_deploy.config in
application version
git-bce52a5381c7ac6735249419c48b1fe116168610-1494415808045 contains
invalid YAML or JSON. YAML exception: Invalid Yaml: while parsing a
block mapping in "", line 3, column 10: mode: "000755", ^
expected , but found FlowEntry in "", line 3,
column 24: mode: "000755", ^ , JSON exception: Invalid JSON:
Unexpected character (f) at position 0.. Update the configuration
file.
according to the aws dcumentation you dont need to use comas behind mode owner and group. so your yml config file should look like this:
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/01_copy_htaccess_after_deployment.sh":
mode: "000755"
owner: root
group: root
content: |
yes | /bin/cp /var/app/current/.htaccess.new /var/app/current/.htaccess
and here is an example of the syntax
files:
"target file location on disk":
mode: "six-digit octal value"
owner: name of owning user for file
group: name of owning group for file
source: URL
authentication: authentication name:
"target file location on disk":
mode: "six-digit octal value"
owner: name of owning user for file
group: name of owning group for file
content: |
this is my content
encoding: encoding format
authentication: authentication name: