Access JSON values using Chef and test-kitchen - json

I'm new to Chef and Test-kitchen and I'm trying to use random JSON file as attribute or environment (preferably attribute), but unfortunately I can't access the JSON values from the recipes.
I'm using the following directory structure:
uat
├── attributes
│   ├── dev.json
│   ├── .kitchen
│   │   └── logs
│   │   └── kitchen.log
│   └── prod.json
├── Berksfile
├── Berksfile.lock
├── chefignore
├── environments
│   ├── dev.json
│   └── prod.json
├── Gemfile
├── Gemfile.lock
├── .kitchen
│   ├── default-windows.yml
│   └── logs
│   ├── default-windows.log
│   └── kitchen.log
├── .kitchen.yml
├── metadata.rb
└── recipes
   ├── default.rb
   ├── prep.rb
   └── service_install.rb
This is the .kitchen.yml:
---
driver:
name: machine
username: sample_user
password: sample_pass
hostname: 192.168.1.102
port: 5985
provisioner:
name: chef_zero
json_attributes: true
environments_path: 'environments/dev'
platforms:
- name: windows
suites:
- name: default
run_list:
- recipe[uat::default]
This is the dev.json:
{
"groupID": "Project-name",
"directoryName": "sample_folder",
"environmentType": "UAT",
}
This is the recipe prep.rb :
directory "C:/Users/test/#{node['directoryName']}" do
recursive true
action :create
end
If I create something.rb in attributes folder and with content: default['directoryName'] = 'sample_folder', it works like a charm, but I need to use a JSON file which to store parameters company wide.
Could you please help me find what I'm doing wrong.

So a couple of issues. First, the environments_path points at a folder, not the specific file, so that should just be environments/. Second, it has to be an actual environment object, see https://docs.chef.io/environments.html#json for a description of the schema. Third, you would need to actually apply the environment to the test node:
provisioner:
# Other stuff ...
client_rb:
chef_environment: dev

Related

HUGO: Content Links not working properly in deployed site

I am a beginner in Hugo. I generated a static site, added a theme, added some content. It works in my local. All the links behave as they are supposed to. Then I do "Hugo" to generate deployable files in public directoery. Now I placed this public folder in my server. The home page loads properly, but contents are redirecting to net domain site.
(copy site url and check in you your browser) => https://smehetre.xyz/
Config file below:
baseURL: https://smehtre.xyz/
languageCode: en-us
title: hello friend
theme: "PaperMod"
menu:
main:
- identifier: Search
name: Search
url: /search/
weight: 10
- identifier: Archives
name: Archives
url: /archives/
weight: 20
- identifier: Resume
name: Resume
url: /resume/
weight: 30
- identifier: About
name: About
url: /about/
weight: 40
Public folder deployed on my nginx server:
├── 404.html
├── about
│   └── index.html
├── archives
│   └── index.html
├── assets
│   ├── css
│   │   └── stylesheet.min.8e489ec970cd58539487a8f697c827fd0de4aa9f638217b7db51cbc230ff6f95.css
│   └── js
│   ├── highlight.min.2840b7fccd34145847db71a290569594bdbdb00047097f75d6495d162f5d7dff.js
│   └── search.min.994d971a9492abf73721874ff533ba36f8b86300a65b0f03c96111ab1f6f32b2.js
├── categories
│   ├── index.html
│   └── index.xml
├── index.html
├── index.json
├── index.xml
├── page
│   └── 1
│   └── index.html
├── posts
│   ├── index.html
│   ├── index.xml
│   ├── my-first-post
│   │   └── index.html
│   └── page
│   └── 1
│   └── index.html
├── search
│   └── index.html
├── sitemap.xml
└── tags
├── index.html
└── index.xml
Try to click on my first post, or Search or Archives or About page.
It redirects to https://net.domain.name/
Please HELP!!!
This looks like a DNS issue, not a Hugo issue.
According to the WhatsMyDNS Tool your Name Server isn't set at all anywhere (link).
According to ICANN, you've never actually registered your domain. Godaddy shows the same.
You need to actually purchase a domain before you can use it.
If you have purchased your domain, contact your registrar to figure out the issue.
If you haven't purchased it yet, make sure you do that.

ERROR: Unknown template parameter: StaticFiles

I get the following error when I try to deploy to aws Elastic Beanstalk.
Printing Status:
INFO: createEnvironment is starting.
INFO: Using elasticbeanstalk-us-west-2-695359152326 as Amazon S3 storage bucket for environment data.
ERROR: InvalidParameterValue: Unknown template parameter: StaticFiles
ERROR: Failed to launch environment.
I am using a preconfigured dockerpython template with the following structure.
.
├── application.config
├── application.py
├── Dockerfile
├── Dockerrun.aws.json
├── iam_policy.json
├── LICENSE.txt
├── misc
├── NOTICE.txt
├── README.md
├── requirements.txt
├── static
│   ├── bootstrap
│   ├── images
│   └── jquery
└── templates
├── aboutus.html
├── clients.html
├── commonheaderincludes.html
├── commonhtmlheader.html
├── footer.html
├── header.html
├── index.html
└── services.html
Please help.

Ansible, role not found error

I try to play following playbook against localhost to provision Vagrant machine
---
- hosts: all
become: yes
roles:
- base
- jenkins
I have cloned necessary roles from github and they resides in a relative path roles/{role name}
Executing following command: ansible-playbook -i "localhost," -c local playbook.yml outputs this error:
==> default: ERROR! the role 'geerlingguy.java' was not found in /home/vagrant/provisioning/roles:/home/vagrant/provisioning:/etc/ansible/roles:/home/vagrant/provisioning/roles
==> default:
==> default: The error appears to have been in '/home/vagrant/provisioning/roles/jenkins/meta/main.yml': line 3, column 5, but may
==> default: be elsewhere in the file depending on the exact syntax problem.
==> default:
==> default: The offending line appears to be:
==> default:
==> default: dependencies:
==> default: - geerlingguy.java
==> default: ^ here
I cloned the missing dependency from github, and tried to reside it in relative path of roles/java and roles/geerlingguy/java, but either didn't solve the problem, and error stays the same.
I want to keep all roles locally in the synced provisioning folder, without using ansible-galaxy runtime, to make the provisioning method as self contained as possible.
Here is the provision folder structure as it is now
.
├── playbook.yml
└── roles
├── base
│   └── tasks
│   └── main.yml
├── java
│   ├── defaults
│   │   └── main.yml
│   ├── meta
│   │   └── main.yml
│   ├── README.md
│   ├── tasks
│   │   ├── main.yml
│   │   ├── setup-Debian.yml
│   │   ├── setup-FreeBSD.yml
│   │   └── setup-RedHat.yml
│   ├── templates
│   │   └── java_home.sh.j2
│   ├── tests
│   │   └── test.yml
│   └── vars
│   ├── Debian.yml
│   ├── Fedora.yml
│   ├── FreeBSD.yml
│   ├── RedHat.yml
│   ├── Ubuntu-12.04.yml
│   ├── Ubuntu-14.04.yml
│   └── Ubuntu-16.04.yml
└── jenkins
├── defaults
│   └── main.yml
├── handlers
│   └── main.yml
├── meta
│   └── main.yml
├── README.md
├── tasks
│   ├── main.yml
│   ├── plugins.yml
│   ├── settings.yml
│   ├── setup-Debian.yml
│   └── setup-RedHat.yml
├── templates
│   └── basic-security.groovy
├── tests
│   ├── requirements.yml
│   ├── test-http-port.yml
│   ├── test-jenkins-version.yml
│   ├── test-plugins-with-pinning.yml
│   ├── test-plugins.yml
│   ├── test-prefix.yml
│   └── test.yml
└── vars
├── Debian.yml
└── RedHat.yml
You should install or clone all required roles in the /roles folder (or in the system folder)
ansible-galaxy install -p ROLES_PATH geerlingguy.java
should fix this specific problem.
However, the best practice should be the use of a requirements.yml file where you require all the needed roles and then install them with ansible-galaxy directly in your playbook.
- name: run ansible galaxy
local_action: command ansible-galaxy install -r requirements.yml --ignore-errors
Simple symbolic link works like a charm without any installations:
$ mkdir /home/USER/ansible && ln -s /home/USER/GIT/ansible-root/roles
Here is the solution: the required path for the role is roles/geerlingguy.java/, not roles/geerlingguy/java/

Using Jekyll's Collection relative_directory for organizing pages/collections

I thought that setting the relative_directory (Jekyll Collection Docs) (github PR) property being set would help me keep my files organized without compromising my desired output, but it seems to be ignored/not used for producing files. I don't want my collections to be in the root directory, because I find it confusing to have ~10 collection folders adjacent to _assets, _data, _includes, _layouts, and others.
Fixes or alternative solutions are welcomed, as long as long as the output is the same, and my pages are in their own directory, without needing to put permalink front-matter on every single page.
_config.yaml
collections:
root:
relative_directory: '_pages/root'
output: true
permalink: /:path.html
root-worthy:
relative_directory: '_pages/root-worthy'
output: true
permalink: /:path.html
docs:
relative_directory: '_pages/docs'
output: true
permalink: /docs/:path.html
Directory Structure:
├── ...
├── _layouts
├── _pages
│   ├── root
│   │ ├── about.html
│   │ └── contact.html
│   ├── root_worthy
│   │ ├── quickstart.html
│   │ └── seo-worthy-page.html
│   └── docs
│   ├── errors.html
│   └── api.html
├── _posts
└── index.html
Desired output:
├── ...
├── _site
│   ├── about.html
│   ├── contact.html
│   ├── quickstart.html
│   ├── seo-worthy-page.html
│   └── docs
│   ├── errors.html
│   └── api.html
└── ...
It seems that the PR you mention is still not merged.
For 3.1.6 and next 3.2, jekyll code is still :
#relative_directory ||= "_#{label}"
But the requester made a plugin that looks like this :
_plugins/collection_relative_directory.rb
module Jekyll
class Collection
def relative_directory
#relative_directory ||= (metadata['relative_directory'] && site.in_source_dir(metadata['relative_directory']) || "_#{label}")
end
end
end

Aurelia: issue configuring bundled asset paths

I'm starting to build a front-end in Aurelia that is integrated into a Clojure project. I checked out some example projects and while I did find them useful for an overview, I've noticed that a lot of the out-of-the-box configurations assume the project is at root (which is understandable).
When I try to integrate this into my project and change the paths accordingly, the bundle is looking for resources in the wrong place - with a path that matches their location in the project, but not within the server's public directory.
For example, I have configured the application to bundle files that are in ./resources/public/, which is where the built files are located (I'm using several pre-processors), and these files are bundled correctly; however, when I load the page, I get the following error in my JS console:
system.src.js:4597 GET https://localhost:8443/resources/public/dist/aurelia.js 404 (Not Found)
The correct path is localhost:8443/dist/aurelia.js - I have a feeling that the /resources/public is coming from some configuration files, but if I change those the bundling breaks.
Relevant paths in the project are (truncated for brevity):
MyProject
├── gulp
│   ├── bundles.js
│   ├── paths.js
│   └── tasks
│   ├── build.js
│   ├── bundle.js
├── gulpfile.js
├── package.json
├── resources
│   ├── public
│   │   ├── config.js
│   │   ├── css
│   │   ├── dist
│   │   │   ├── app-build.js
│   │   │   └── aurelia.js
│   │   ├── fonts
│   │   ├── html
│   │   ├── img
│   │   ├── index.html
│   │   ├── js
│   │   │   ├── app.js
│   │   └── jspm_packages
│ │ ├── system.js
│ │ ├── github
│ │ └── npm
│   └── src
│   ├── fonts
│   ├── img
│   ├── js
│   ├── pug
│   └── stylus
Here are some of the pertinent configurations, trimmed for brevity:
./config.js
baseURL: "/",
...
paths: {
"*": "resources/public/*",
"github:*": "jspm_packages/github/*",
"npm:*": "jspm_packages/npm/*"
}
Note that if I change the path for "*" (or remove it entirely), I get the following error when running gulp build:
Error on dependency parsing for npm:jquery#2.2.4/src/intro.js at
file:///Users/jszpila/Work/MyProject/resources/public/jspm_packages/npm/jquery#2.2.4/src/intro.js
MultipleErrors:
compiler-parse-input:47:1: Unexpected token End of File
compiler-parse-input:47:1: Unexpected token End of File
compiler-parse-input:47:1: Unexpected token End of File
./package.json
"jspm": {
"directories": {
"baseURL": "resources/public"
},
"devDependencies": {
"aurelia-animator-css": "npm:aurelia-animator-css#^1.0.0-beta.1.1.2",
"aurelia-bootstrapper": "npm:aurelia-bootstrapper#^1.0.0-beta.1.1.4",
"aurelia-fetch-client": "npm:aurelia-fetch-client#^1.0.0-beta.1.1.1",
...
}
},
./gulp/bundles.js
"bundles": {
"dist/app-build": {
"includes": [
"[**/*.js]",
"**/*.html!text",
"**/*.css!text"
],
"options": {
"inject": true,
"minify": true,
"depCache": true,
"rev": false
}
},
"dist/aurelia": {
"includes": [
...
"fetch",
"jquery"
],
"options": {
"inject": true,
"minify": true,
"depCache": false,
"rev": false
}
}
}
./gulp/tasks/bundle.js
var config = {
force: true,
baseURL: './resources/public/',
configPath: './resources/public/config.js',
bundles: bundles.bundles
};
So I think it's safe to assume that this incorrect path is coming from one of those configurations; however, they are correct for the tooling - just not the bundle. Can I configure the bundling tool paths and the application tool paths separately, or am I overlooking a misconfiguration?
Thanks in advance for any help!