AWS error while parsing .config YAML file in .ebextension - amazon-web-services

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:

Related

How to Use a Loop to Render Multiple Templates with multiple variables

I have a task to install monitoring agent in multiple hosts.
we are using three templates(yml files) during this installations. these template contain multiple tags. such as app name, teamdl, server IP, datacenter and so on...
for bulk installation we are using csv file which contains value for each tag.
Ask is to use each item in the csv file and use them as variable for all three templates.
I am able to read these items, but not able to use them. please support.
main.yml
- name: copy the csv file
copy:
src: "/u00/ansible/Playbooks/test.csv". # present in ansible controller
dest: "/u00/app/monitor/test.csv" #target server
become: yes
become_user: root
vars:
contents: "{{ lookup('file', '/u00/app/monitor/test.csv').split('\n') }}"
- name: Update config yml files
template: src={{item.src}} dest={{item.dest}}
loop:
- { src: '/u00/ansible/Playbooks/files/infra.yml_template', dest: '/u00/app/monitor/infra.yml' }
infra.yml_template -
custom_attributes:
application : {{ item.Application }}
env : {{ item.env }}
datacenter : {{ item.Datacenter }}
log:
file: /u00/app/monitor/infra.log
format: text
level: smart
forward: false
stdout: false
smart_level_entry_limit: 500
rotate:
max_size_mb: 100
max_files: 5
compression_enabled: true
file_pattern: rotated.YYYY-MM-DD_hh-mm-ss.log
error -
TASK [infra-integration : copy the csv file] ********************************
[0;32mok: [testserver1][0m
[0;32mok: [Testserver2][0m
TASK [Infra-integration : Update config yml files] **************************
[0;31mAn exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.errors.AnsibleUndefinedVariable: 'dict object' has no attribute 'Application'[0m
[0;31mfailed: [testserver1] (item={'src': '/u00/ansible/Playbooks/files/infra.yml_template', 'dest': '/u00/app/monitor/infra.yml'}) => {"ansible_loop_var": "item", "changed": false, "item": {"dest": "/u00/app/monitor/infra.yml", "src": "/u00/ansible/Playbooks/files/infra.yml_template"}, "msg": "AnsibleUndefinedVariable: 'dict object' has no attribute 'Application'"}[0m
Expectation is to read csv file and use variables in three different template located at three different location.

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

Deploying to elastic beanstalk using gulp - Static files permissions issue

Recently I've had to change from using eb deploy to using a gulp task to deploy my project to AWS elastic beanstalk.
The reason for this is that I need to babel transform ES6 files to ES5. I don not want to commit the transformed files to our git and eb deploy uses the git-archive command to make the zip to deploy.
The transform and deploy works, I'm running into an issue with static files.
gulp.task('ebDeploy', function() {
return gulp.src([
'./.ebextensions/**', // Include the .ebextensions folder
'./**/*.js', // Match all .js files
'!./es6/**/*', // Exclude files in /es6 dir
'!node_modules', '!node_modules/**', // Exclude the node_modules folder and contained files
'*.js', // Include JS Files in the base dir
'package.json', // Include this specific file in base dir
'./config/**', // Include everything under /config
'./public/**', './public/**/*', // Include everything under /public
'./views/**/*.ejs' // Include all .ejs files under /views
], { base: './' })
.pipe(print())
.pipe(gulpEbDeploy({
//name: 'my-application', // optional: If not set, the name from package.json will be used
//version: '1.0.0', // optional: If not set, the version from package.json will be used
timestamp: true, // optional: If set to false, the zip will not have a timestamp
waitForDeploy: true, // optional: if set to false the task will end as soon as it starts deploying
amazon: {
// accessKeyId: "< your access key (fyi, the 'short' one) >", // optional
// secretAccessKey: "< your secret access key (fyi, the 'long' one) >", // optional
// signatureVersion: "v4", // optional
region: 'eu-west-2',
bucket: 'elasticbeanstalk',
applicationName: 'foo',
environmentName: 'bar'
}
}))
});
I have checked the zip that get's uploaded and it contains all the correct files. However it seems that eb deploy does something to permissions that i need to duplicate.
When I use eb deploy (after committing the /build files which I'm trying to prevent)
Everything works fine.
When I use my gulp task: I get the following error when trying to access static files.
06:49:28.81 server.js:98 | Global Error Handler
06:49:28.81 server.js:99 | { Error: EACCES: permission denied, stat '/var/app/current/public/css/default.css'
at Error (native)
errno: -13,
code: 'EACCES',
syscall: 'stat',
path: '/var/app/current/public/css/default.css',
expose: false,
statusCode: 500,
status: 500 }
What do I need to do to make these files work as intended.

YAML exception: Invalid Yaml

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

running template on ansible 2.0.1.0 results in IOError: [Errno 2] No such file or directory: u'

Evening all,
I have the following set for the template
- name: Copy and create config
template:
vars:
appname: CTR DEVCUL
tiername: CTR CUI
hostname: ansible_fqdn.split('.')[0]
src: /absolute/path/to/template.xml.j2
dest: /absolute/path/to/config.xml
mode: 0644
when I try executing i get IOError: [Errno 2] No such file or directory: u'/absolute/path/to/template.xml.j2
why is this u' being added and how do i get rid of it?
u'' is just a string literal, like r''; it's an artifact of how Ansible is printing out the string.
Are you really sure the file exists at that path?