How to duplicate base object in an overlay with kustomize? - kustomize

I have a base object (custom resource) that I need multiple times with a different name and one property added (or changed). So I have defined a base yaml file and referenced it in the overlay kustomization.yaml.
├── base
│ ├── kustomization.yaml
| └── base.ClusterOutput.yaml
└── my-env
└── kustomization.yaml
Now I need to update the metadata.name field and add a property which can be done with patches in kustomization.yaml
patches:
- patch: |-
- op: add
path: /spec/opensearch/logstash_prefix
value: <new-value>
- op: replace
path: /metadata/name
value: <new-name>
Until here it works as expected, but in some environments I need more than the one instance of the custom resource and I can't figure out, how to do that. I tried multiple patches, but they override each other and I end up with one object having the last patch.
I don't want to write multiple base objects, in some environments I need only one and they are equal apart from the name and the one property anyway.
Is there some way I can do this with kustomize?

Related

Handling variables in nested terraform structure

I've set up a terraform project with the following folder structure:
modules/environments/[$environment,all]/regions/[$region,all]
modules/resources/[$resource]
environments/[$environment]/[$region]
In modules/resources I have folders like api, load balancer, etc. In modules/environments/[$environment,all]/regions/[$region,all], I import the required modules from modules/resources/[$resource]. Given the environment is prod, in eu-west-1 for example, I import modules from modules/environments/[prod,all]/regions/[eu-west-1,all].
If I add a new variable, I have to update the variables.tf file in all the affected places, and in every main.tf, where I assign the variables to the modules. This is a lot of effort.
It would be a much easier scenario if I wouldn't have to assign the variables in the "module" {} level, but it would automatically get the variables from the .tfvars file that is being used when planning or applying, but it's not the case.
Is there any workoaround for this?

How to make subdirectory collections in Jekyll?

I have a Jekyll site and I want to make collections but with subdirectories
For example, I have kind of this structure:
......
_projects/ # "mysite.domain/projects", contains list of available projects (based on these directory)
├── lineageos # "mysite.domain/projects/lineageos"
├── twrp # "mysite.domain/projects/twrp"
└── ungap # "mysite.domain/projects/ungap"
Is there a way to achieve this? I have read the Jekyll collections docs, but I can't understand it all and apply it for this.
Thanks! Let me know if you need more details.
Note: The things that making me confused is config file and markdown/layout structure for this kind of collections. So it will very appreciated if you tell me about this with detail :)
You have to include the projects folder in the _config.yml and set the output to true. The sort_by is optional.
The collection folder must start with underscore _ so rename the folder to "_projects" instead of projects.
collections:
projects:
output: true
sort_by: title
See the hint box of the jekyll docu - collections
Be sure to name your directories correctly
The folder must be named identically to the collection you defined in your _config.yml file, with the addition of the preceding _ character.

In what order will facts found in files under a module/lib/facter/* be loaded on a puppet client?

I have the following file structure:
lib
└── facter
├── rackspace.rb
├── system_load.rb
└── users.rb
I want to use a custom fact value found in system_load.rb (let's call this :system_me fact) in another custom fact that I am writing and defined in users.rb. Like this:
# users.rb
Facter.add('sogood') do
you = ''
me = Facter.value(:system_me)
if me == 'foo'
you = 'bar'
end
setcode do
you
end
end
However, I am worried on what happens if system_me fact value doesn't exist yet before client tries to run sogood.
So my question is:
Are fact files like the one seen in the lib folder structure above loaded in alphabetical order of the filename (rackspace.rb -> system_load.rb -> users.rb) when I run puppet apply —facterpath=module/lib/facter ?
If a fact resolution attempts to obtain the Facter.value() for another fact that has not yet been loaded then Facter will immediately attempt to load the needed fact. That means that
No, fact files are not necessarily loaded in alphabetical order, but
you nevertheless should not need to worry about fact loading order.
You do need to avoid creating dependency loops among facts, but custom facts relying on built-in facts will never cause such a loop.

Can I select hierarchy based on it's name in hiera.yaml file in puppet?

I am using hiera5 and I want to read hierarchies from one of the groups based on their names.
For e.g. Currently I have:
version: 5
defaults:
datadir: "/"
data_hash: yaml_data
hierarchy:
- name: "ABC"
paths:
- "env/env-data1.yaml"
- "env/env-data2.yaml"
- "env/env-data3.yaml"
I want to add multiple hierarchies like this:
hierarchy:
- name: "ABC"
paths:
- "env/env-data1.yaml"
- "env/env-data2.yaml"
- "env/env-data3.yaml"
- name: "DEF"
paths:
- "env/env-data4.yaml"
- "env/env-data5.yaml"
- "env/env-data6.yaml"
- name: "GHI"
paths:
- "env/env-data7.yaml"
- "env/env-data8.yaml"
- "env/env-data9.yaml"
And read files from just one of the groups at a time lets say just 'ABC'.
Is there a way I can pass hierarchy name as parameter while calling puppet script ?
Additional Info:
I am running a shell script from jenkins which triggers the puppet script.
puppet apply --hiera_config=${WORKSPACE}/hiera.yaml ${WORKSPACE}/puppet-script.pp
Thanks in advance!
I want to add multiple hierarchies like this: [...]
The syntax is fine, but it does not describe multiple hierarchies. It describes one multi-level hierarchy (which is in fact the usual case). Having multiple levels is what makes it hierarchical -- it is the distinguishing characteristic of Hiera relative to other external-data mechanisms that Puppet has had.
And read files from just one of the groups at a time lets say just 'ABC'.
Nope, not happening. Hiera does not work that way.
Is there a way I can pass hierarchy name as parameter while calling puppet script ?
No, but you can specify a different hiera.yaml configuration file, as you already demonstrate. If you want different hierarchies for different runs then define each in its own (full) configuration file, and choose the appriate config file for each use.

Puppet how to run all manifests in directory

So I have a directory of puppet manifests that I want to run.
Is it possible to do something like:
include /etc/puppet/users/server522/*.pp
and have puppet run them?
I've tried
include users::server522::*
and several other variations
I always get an error about puppet being unable to find it.
Is there anyway to do this?
So my final solution to this was write a script that would take the directory listing and for each .pp file add an include into the server522.pp file. Quite annoying that puppet won't include an entire directory.
What are you trying to do here, and are you sure you're doing it the correct way? To wit, if you have multiple manifests corresponding to multiple servers, you need to define the nodes for each server. If OTOH you're trying to apply multiple manifests to a single node it's not clear why you would be doing that, instead of just using your defined classes. A little more information would be helpful here.
I do not see the point of each user having its own manifest. I would rather create script that would automatically build one manifest file, basing on data from some source, for instance from HEAD of git repository containing CSV file with current list of users.
If you realy want to use separate manifest file for every user you may consider having seprate module for every user:
manifests
default.pp <-- here comes default manifest
module_for_user_foo/
manifests/
init.pp <-- here comes your 'foo' user
module_for_user_bar/
manifests/
init.pp <-- here comes your 'bar' user
Now you may copy modules containing manifests.

Resources