Saltstack load all files in pillars dir - salt-stack

I am having one large .yml config file, which gets loaded in pillar .sls file and later used in states. To refactor that config file and make it a bit readable, I would like to split it into multiple files, which would be placed in one directory.
Current structure of pillars is:
pillar
|- app_configuration.sls
|- config.yml
Desired structure is:
pillar
|- app_configuration.sls
|- config_files
|- config1.yml
|- config2.yml
|- config3.yml
Current code in app_configuration.sls loads yaml file config.yml like this:
{% import_yaml 'config.yml' as app_config %}
But with updated configuration structure I need to pass directory path config_files and traverse all files in that directory and merge their content together. How can such behavior be achieved in Saltstack? The most important thing for me is how to list all files in config_files directory. I've already managed to create a for loop with merging code in Jinja, but when I try to use salt.file.find function with relative path (config_files), it does not work. Only when I specify absolute path, which is really really long and it does not look right for me. I also thought about enumerating those config files, but I would like to avoid that, because when new config is added, it may happen, that it is forgotten to be added in enumeration. That is not really scalable.

There are two options for this, you can use include statement inside a pillar SLS file, or load files using top.sls pillar file.
Example of using top.sls for base environment for all minions:
base:
'*':
- app_configuration
- config_files.*
Or, without editing the top.sls file, include files from config_files directory in app_configuration.sls.
At the top of app_configuration.sls:
include:
- config_files.*
Another alternative is to use map.jinja files (see documentation on Formulas).

Related

Airflow Dag Folder - How to ignore notebook checkpoints

Airflow is being too clever and trying to pick up dags within the jupyter notebook checkpoints folder "dags/.ipynb_checkpoints/" which is throwing an error.
Is there a way to config airflow to ignore folders of a certain pattern? like I would .gitignore?
Thanks
You can create .airflowignore in dags folder:
.ipynb_checkpoints
From the docs:
A .airflowignore file specifies the directories or files in DAG_FOLDER that Airflow should intentionally ignore. Each line in .airflowignore specifies a regular expression pattern, and directories or files whose names (not DAG id) match any of the patterns would be ignored (under the hood, re.findall() is used to match the pattern). Overall it works like a .gitignore file.
.airflowignore file should be put in your DAG_FOLDER. For example, you can prepare a .airflowignore file with contents
project_a
tenant_[\d]
Then files like project_a_dag_1.py, TESTING_project_a.py, tenant_1.py, project_a/dag_1.py, and tenant_1/dag_1.py in your DAG_FOLDER would be ignored (If a directory’s name matches any of the patterns, this directory and all its subfolders would not be scanned by Airflow at all. This improves efficiency of DAG finding).
The scope of a .airflowignore file is the directory it is in plus all its subfolders. You can also prepare .airflowignore file for a subfolder in DAG_FOLDER and it would only be applicable for that subfolder.
Place a file named .airflowignore in the directory you want Airflow to ignore.

How to exclude a folder from rsync

I am using rsync to deploy a git branch with my production server. Currently, I got js files stored in two locations:
assets/js/
js/
When I run rsync using --exclude js, non of the both folders will be sync, while I want the assets/js/ folder to be synced and the js/ folder inside my root folder to be skipped. How can I achieve this?
You need to specify the pattern for those files and directories:
using:
CWRULE [PATTERN_OR_FILENAME]
CWRULE,MODIFIERS [PATTERN_OR_FILENAME]
so you would have something like
CW- js/
For even more detailed info you can see the man page at the section
Include/Exclude Pattern Rules
from this link, hope it helps

Gulp/Symfony2: How can I avoid overwriting my js/css imports when cache busting?

I have a gulp build process for my Symfony2 application and am trying to integrate cache busting, but have hit a roadblock. I use gulp-rev to append a hash to my concatenated javascript file and output a manifest file to map between the original and the hashed filename. I currently have a twig template that has a single script tag to import all my correctly built javascript files, but I need to find a way of updating that script tag to point at the version of the file with the correct hash, ensuring that a fresh version of the file is downloaded every time the hash changes.
I have thought of a number of solutions which I've described below, but none of them feel right. Does anyone have a better/correct solution, or some reasoning as to why I should go with one of the ways I have already thought of.
Use gulp-revreplace to replace the reference to app.js in my_template.html.twig to be a reference to app-8de7016eef.js as defined by the mapping in the manifest file. Problem: This will overwrite my actual template file if the command in run in my dev environment, leaving me with a dirty git tree and changes that shouldn't be committed.
Have gulp output an assets template file which is stored in public/html which is not committed to version control, and includes the correct script tag based on whether it was run on prod/dev environment (i.e. <script src='js/app.js'> on dev, and <script src='js/app-8de7016eef.js'> on prod. My main template can then #include 'public/html/assets.html.twig' and never needs to be overwritten. Problem: This gets increasingly complex when there are multiple templates that extend each other, and when there is both CSS and JS in separate blocks that need to be overwritten by other templates. It also feels messy to generate and output a twig file from my gulp task.
Use assetic to manage cache busting: instead of using gulp-rev I could use the {% javascripts 'public/js/app.js' %} <script src="{{ asset_url }}"></script> {% endjavascripts %} syntax of assetic and let that handle the cache busting for me. Problem: The whole point of using gulp was to move away from assetic, and if I have to use both gulp and assetic then the complexity is increased.
So has anyone solved the cache-busting with gulp and symfony problem? How did you do it?
You should make use of the two config directives:
framework.templating.assets_version
framework.templating.assets_version_format
You can read more about them in the documentation of the FrameworkBundle.
They do work with the regular {{ asset() }} function and don't require AsseticBundle.
Then just dump a parameter/config-file that assigns i.e. the md5sum of your compressed frontend source-files folder to assets_version in a git pre-commit hook.
.git/hooks/pre-commit
#!/usr/bin/env sh
echo "framework.templating.assets_version: $(tar -cf - ./src/Frontend | md5sum)" \
> app/config/assets_version.yml
app/config/config.yml
# ...
imports:
# ...
- { resource: './assets_version.yml' }

How to change the path before injection

Is it possible to change the path of the injected file before injection occurs?
I am using Grunt/Bower/Connect/Wiredep, and my directory structure is:
www
|- dev-dist/
|- node_modules/
|- src/
|- vendor/
|- bower.json
|- Gruntfile.js
|- package.json
(Note: in my .bowerrc file I've added directory: vendor)
When I run the custom task grunt serve:dev it will create the directory dev-dist, I will then copy my index.html (only) to the folder, after which I run the task wiredep.
After running wiredep, the src paths to my dependencies are all prefixed with '../vendor/'. The problem is that when I run connect I have the option base: ['vendor', 'dev-dist', 'src']. When everything is served, the relative path to vendor doesn't make any sense because the vendor dir is already served at the root.
Is there a way I can modify the path to the injected files before wiredep injects them? (So I can remove the '../vendor')
What I would like to have happen is from the same workspace be able to run grunt serve:* and specify dev/stage/prod environments. This is why I did not want to serve the whole www directory.
Is there a way to exclude folders from being served in connect? (So instead of specifying base:[...], I can just exclude the stage-dist / prod-dist folders)
Thanks,
JD
You can use the option ignorePath with a regular expression
ignorePath: /\.\.\//,
from the wiredep to remove the ../ from the path that is getting injected. The configuration details are available over here https://github.com/taptapship/wiredep#configuration
I haven't used connect yet, so I am not sure of your second part of the question.

changing home directory in R

In R, if I use the command
write.csv(res,"~/table1_n500.csv")
, then the result is saved in C:\Users\John Smith\Documents.
But I expected it to be saved in C:\Users\John Smith\.
Can I change this home directory (referred by ~ mark) to C:\Users\John Smith\?
From my personal experience, i usually import data from a file (for example in the directory C:\Users\John Smith\DATA)
then i will set working directory as
setwd("C:/Users/John Smith/DATA")
While i want to save the output file in other directory like "C:\Users\John Smith" but not in the data folder.
so i will set relative working directory like
setwd("../")
And when you type getwd()
you will get [1] "C:/Users/John Smith"
Wish this help.
There are two ways to deal with this problem.
1.) Use the function setwd() to set the working directory (or home directory). All save and read commands will look for files in that working directory. I use this only sparingly, and for quick tiny project.
2.) A more preferred approach is to define a variable like dataInputDir, and use function file.path(dataInputDir, <your filename>) to generate a file path. The advantage is that if you are reading (writing) data from (to) multiple directories, you can do this more efficiently:
file.path(dataInputDir1, <your file or dir name>)
file.path(dataInputDir2, <your file or dir name>)
file.path(dataOutputDir1, <your file or dir name>)
file.path(dataOutputDir2, <your file or dir name>)
This approach is really handy for large complicated projects, and is highly recommended.
This is also helpful, if your program is to be executed on multiple platform like Windows, Mac, Linux. You'll have to change the directory location only at one place, and everything else will work smoothly.
Additionally, following functions/handles will be useful for dealing with directory names:
Quick fix:
setwd("../") # setwd to parent folder of current working directory (getwd())
More robust:
setwd(dirname(dataInputDir)) # Setwd to parent folder of dataInputDir

Resources