If I have a local rpm in my ansible-playbook can I do yum install in one step? - redhat

I have downloaded a rpm in my ansible-playbook:
(djangoenv)~/P/c/apache-installer ❯❯❯ tree .
.
├── defaults
│   └── main.yml
├── files
│   ├── apache2latest.tar
│   ├── httpd_final.conf
│   ├── httpd_temp.conf
│   └── sshpass-1.05-9.1.i686.rpm
├── handlers
│   └── main.yml
├── hosts
├── meta
│   └── main.yml
├── README.md
├── tasks
│   └── main.yml
├── templates
├── tests
│   ├── inventory
│   └── test.yml
└── vars
└── main.yml
My question is why can't I just install it using:
- yum: name=files/sshpass-1.05-9.1.i686.rpm
? It complains that files/sshpass-1.05-9.1.i686.rpm is not found in the system. Now I am doing it in two steps:
- copy: src=files/sshpass-1.05-9.1.i686.rpm dest=/tmp/sshpass-1.05-9.1.i686.rpm force=no
- yum: name=/tmp/sshpass-1.05-9.1.i686.rpm state=present

No, there is no simple way around coping the package to the remote host before installing. Ansible yum module expects a local file when you define a file in the name parameter.
IMHO it is not a good idea to keep packages inside the Ansible code base. Because they are binary and not exactly part of the actual Ansible code. It would be cleaner to setup a private repository and store those files there. That is the only way around coping a package in this situation I'm aware of.

Related

Using GitHub Actions in a Single Repository with Multiple Projects

I am fairly competent in using GitHub actions to build a variety of languages, orchestrate deployments, and I've even done cross-repository actions using web-hooks, so I'd say that I'm pretty familiar with working with them.
I often find myself doing a lot of scratch projects to test out an API or making a demo, and these don't usually merit their own repositories, but I'd like to save them for posterity, rather than just making Gists out of them, Gists being largely impossible to search. I'd like to create a scratch repository, with folders per language, like:
.
└── scratch
├── go
│   ├── dancing
│   │   ├── LICENSE-APACHE
│   │   ├── LICENSE-MIT
│   │   ├── main.go
│   │   └── README.md
│   ├── gogettur
│   │   ├── LICENSE-APACHE
│   │   ├── LICENSE-MIT
│   │   ├── main.go
│   │   └── README.md
│   └── streeper
│   ├── LICENSE-APACHE
│   ├── LICENSE-MIT
│   ├── main.go
│   └── README.md
├── node
│   └── javawhat
│   ├── index.js
│   ├── LICENSE-APACHE
│   ├── LICENSE-MIT
│   └── README.md
└── rust
├── logvalanche
│   ├── Cargo.toml
│   ├── LICENSE-APACHE
│   ├── LICENSE-MIT
│   ├── README.md
│   └── src
├── streamini
│   ├── Cargo.toml
│   ├── LICENSE-APACHE
│   ├── LICENSE-MIT
│   ├── README.md
│   └── src
└── zcini
├── Cargo.toml
├── LICENSE-APACHE
├── LICENSE-MIT
├── README.md
└── src
I'd like to generalize GitHub actions per language, for Go, use go test ./... and go build, for Rust cargo test and cargo build, etc.
I know that what I could do is have a workflow for each created project, but this would be tedious, I'd end up copying and pasting most of the time, and every build would run on every change in the entire repository, and I don't want to be building node/javawhat if only rust/zcini has changed.
Therefore I have a few questions:
Is it possible to have a workflow only run when certain files have changed, rather than running everything every single time?
Is there a way to generalize my workflows so that every dir in rust/ uses the same generic workflow, or will I need one workflow per project in the repository?

yocto do_unpack() - same directory names in different layers

During experiments with Yocto's Advanced Kernel Metadata I got into a situation where I would like to have the .scc, .patch and .cfg files organized into a directory structure as mentioned in the syntax section, and to keep that structure in all the layers (consider 2 layers here - meta-main_layer and meta-bsp_layer):
meta-main_layer
└── recipes-kernel
└── linux
└── linux-yocto.bb
└── linux-yocto
├── cfg
│   ├── main_frag_1.cfg
│   └── main_frag_1.scc
├── features
│   ├── main_feature_1.cfg
│   ├── main_feature_1.patch
│   └── main_feature_1.scc
└── patches
├── main_patch_1.patch
└── main_patch_1.scc
meta-bsp_layer
└── recipes-kernel
└── linux
└── linux-yocto.bbappend
└── linux-yocto
├── bsp
│   └── bsp_definition.scc
├── cfg
│   ├── bsp_frag_1.cfg
│   └── bsp_frag_1.scc
├── features
│   ├── bsp_feature_1.cfg
│   ├── bsp_feature_1.patch
│   └── bsp_feature_1.scc
└── patches
├── bsp_patch_1.patch
└── bsp_patch_1.scc
meta-main_layer/recipes-kernel/linux/linux-yocto.bb contains:
FILESEXTRAPATHS_prepend := "${THISDIR}:"
...
SRC_URI = "file://linux-yocto;type=kmeta \
"
Edit:
And meta-bsp_layer/recipes-kernel/linux/linux-yocto.bbappend:
FILESEXTRAPATHS_prepend := "${THISDIR}:"
...
SRC_URI += " file://linux-yocto;type=kmeta \
"
... end of edit
This means that after parsing the recipes, the SRC_URI will contain file://linux-yocto;type=kmeta twice, and FILESEXTRAPATHS=meta-bsp_layer/recipes-kernel/linux:meta-main_layer/recipes-kernel/linux:. The way I understand it, the do_unpack() task goes through the files in SRC_URI and for each of them, it searches FILESEXTRAPATHS for that file, and it takes the first one it finds. That means that in my case, only the files from meta-bsp_layer are taken, as its path is the first in FILESEXTRAPATHS, and the files from the meta-main_layer are ignored.
What I would like to achieve is that instead of taking the files from only the first path found in FILESEXTRAPATHS, do_unpack() would go through all of the paths in FILESEXTRAPATHS and merge the directories of the same name (cfg, features and patches) from both layers. Without that, I don't see any big benefits of using the Advanced Kernel Metadata mechanism. Could anyone advise how to get this done?
PS: I'm using Yocto Zeus.

How can I make test data files accessible to pytest tests when run with tox?

I want to run a test for a function which accepts a Path to a file as input via an argument: function(some_path_to_file) via tox. The file I want to pass to the function cannot be created temporarily during test setup (what I usually do via pytests builtin tmpdir fixtures) but resides in the package <package>/data directory besides the test directory <package>/tests (the location <package>/tests/data would probably be better). Because tox runs the tests in a virtualenv it's not clear to me how to make the test data file available to the test. I know that I can define the base temporary directory of pytest with the --basedir option but I did not get it working with tox yet.
tl;dr
The problem was a conversion of some_path_to_file from Path to str (to pass it to sqlite3.connect(database inside the function) using Path.resolve(. No need to configure pytests --basedir option and tox in any way.
This tripped me up as well. The way I was able to solve it was to specify the full path of the text file I wanted the testing function to read relative to the base directory.
So for example, my directory tree looks like this:
.
├── __init__.py
├── my_package
│   ├── __init__.py
│   └── calculate_stats.py
├── my_package.egg-info
│   ├── PKG-INFO
│   ├── SOURCES.txt
│   ├── dependency_links.txt
│   ├── requires.txt
│   └── top_level.txt
├── bin
│   └── calculate_stats
├── requirements
│   ├── default.txt
│   └── development.txt
├── setup.py
├── test
│   ├── __init__.py
│   ├── test_calculate_stats.csv
│   ├── test_calculate_stats.txt
│   └── test_calculate_stats.py
└── tox.ini
In the file test_calculate_stats.py I have the following line:
assert (calculate_stats.calculate_stats_to_csv("test/test_calculate_stats.txt", "test/test_calculate_stats.csv") == 60)
The calculate_stats_to_csv function reads in the test/test_calculate_stats.txt file, calculates some stats, and outputs them to test/test_calculate_stats.csv
Initially I had just specified the input file to be test_calculate_stats.txt because it's in the same directory as the file containing the testing function -- that's when I ran into the error.
tox predfines a number of substitutions. The directory of the virtualenv is {envdir}, site-packages is at {envsitepackagesdir}. Pass a value from the command line to your test script like this:
[testenv]
commands = pytest --basedir={envsitepackagesdir}/mypackage

How to include images in a jekyll project hosted on github?

I'm building a blog using jekyll and hosting it on github with gh-pages. The root of my project can be see seen below:
├── LICENSE
├── README.md
├── _config.yml
├── _img
│   ├── 2016-09-09\ 14.48.20.png
│   └── 2016-09-09\ 15.25.09.png
.
.
.
├── _posts
│   ├── 2016-09-08-seven-weeks-before-applying-to-devops-job.markdown
│   └── 2016-09-09-an-hour-with-ansible.md
.
.
.
├── _site
│   ├── 2016
│   │   └── 09
│   │   ├── 08
│   │   │   └── seven-weeks-before-applying-to-devops-job.html
│   │   └── 09
│   │   └── an-hour-with-ansible.html
│   ├── LICENSE
│   ├── README.md
│   ├── about
│   │   └── index.html
│   ├── css
│   │   └── main.css
│   ├── feed.xml
│   └── index.html
├── about.md
├── css
│   └── main.scss
├── feed.xml
└── index.html
The documentation gives the following example:
Because of Jekyll’s flexibility, there are many solutions to how to do this. One common solution is to create a folder in the root of the project directory called something like assets or downloads, into which any images, downloads or other resources are placed. Then, from within any post, they can be linked to using the site’s root as the path for the asset to include. Again, this will depend on the way your site’s (sub)domain and path are configured, but here are some examples (in Markdown) of how you could do this using the site.url variable in a post.
Including an image asset in a post:
... which is shown in the screenshot below:
![My helpful screenshot]({{ site.url }}/assets/screenshot.jpg)
I've tried several different ways but non are working once I push gh-pages up:
![]({{ site.github.url }}/_img/2016-09-09 14.48.20.png)
![]({{ site.url }}/_img/2016-09-09 15.25.09.png)
I've also tried "keeping" the _img directory by putting the following in my _config.yaml
# Build settings
markdown: kramdown
keep_files: ["_img"]
But this also is not working. So how do I include images in a jeykll project hosted on github?
Thanks for your help :)
Every folder beginning with an underscore won't be copied to the build destination. The most common way is to store images is to add them to a assets/img folder.
If you want to use _img you have to add to your _config.yml:
include:
- "_img"
Create a folder for your images, you can name it according to your wish (mine is "images")
Find the image address of that image that you want to include in your post
(You can do that by going to your folder image and right click on your image, then copy image address)
Now you use that address in your post without any problem.

How should I download specific file type from folder (and ONLY it's subfolders) using wget or httrack?

I'm trying to use HTTrack or Wget do download some .docx files from a website. I want to do this only for a folder and it's subfolders. Ex: www.examplewebsite.com/doc (this goes down 5 more levels)
How would be a good way to do this?
The previous proposed answer is ludicrous considering the "spider" option has ALWAYS specifically NOT DOWNLOADED, but instead followed.
Better late than never, but here is the command you seek to both mirror the desired file extension files locally, but then as a bonus pull down the target html and auto-adjust it so that if you open it locally and click the links, they will have been altered and adjusted accordingly to now point to the local drive.
wget -e robots=off -r -k -A docx,doc "https://<url>"
If this works for you, I would appreciate the answer points!
You can use --spider with -r (recursive option ) and have --accept to filter the files of your intrest
wget --spider -r --accept "*.docx" <url>
Usage
wget -r -np -A pdf,doc https://web.cs.ucla.edu/~harryxu/
Result
tree
└── web.cs.ucla.edu
├── ~harryxu
│   ├── papers
│   │   ├── chianina-pldi21.pdf
│   │   ├── dorylus-osdi21.pdf
│   │   ├── genc-pldi20.pdf
│   │   ├── jaaru-asplos21.pdf
│   │   ├── jportal-pldi21.pdf
│   │   ├── li-sigcomm20.pdf
│   │   ├── trimananda-fse20.pdf
│   │   ├── vigilia-sec18.pdf
│   │   ├── vora-asplos17.pdf
│   │   ├── wang-asplos17.pdf
│   │   ├── wang-osdi18.pdf
│   │   ├── wang-osdi20.pdf
│   │   ├── wang-pldi19.pdf
│   │   └── zuo-eurosys19.pdf