I frequently use blocks of code in my asciidoc. The biggest issue I have is that shell commands beginning with '#' (because they use a root's shell) are rendered as comments in the asciidoc. For example:
[source,shell]
----
# firewall-cmd --permanent --new-zone dockerc
----
This make the reading a bit confusing. Is there a way to use a shell piece of code, overriding the 'behaviour' ?
Thanks
Maybe you need to set a source-highlighter
For me the following example worked for HTML:
= Foo
:source-highlighter: coderay
[source,shell]
----
# firewall-cmd --permanent --new-zone dockerc
--------
Or can you post a screenshot of how your output looks like?
Related
I am working on a complete kickstart script for setting up servers and adding them finally to my Nagios configuration. Adding the newly created / kickstarted servers is not an issue, however how do I remove old ones (if they previously existed)?
Current situation
This is what I am currently using:
checknagios=$(ssh root#10.20.30.40 "cat /usr/local/nagios/etc/objects/vz_nodes_hosts.cfg | grep $HOST" 2>&1)
It currently only adds new / kickstarted servers to the vz_nodes_hosts.cfg file. If the hosts exists it will simply output a message (so I have to remove and add it manually). I want this procedure automated so if the hosts already exists in vz_nodes_hosts.cfg I want it removed.
I have three examples at the moment of a previously added host:
Example 1
define host{
use linux-server
host_name server100
alias server100
address 33.33.44.44
}
(actually the above server has an incorrect setup, but I want to make sure these entries also get removed completely)
Example 2
define host{
use linux-server
host_name servernonraid200
alias servernonraid200
address 55.55.66.66
hostgroups vz_nodes,vz_partion
}
Example 3
define host{
use linux-server
host_name serverraid300
alias serverraid300
address 77.77.88.88
hostgroups vz_nodes,vz_partion,raid_megacli
}
Now what would be the best way, if the hostname matches
This is what I currently have (it only reports a message, instead of removing an old entry):
if [[ "$checknagios" == *"$HOST"* ]]; then
echo -e "This hardware node already exists in Nagios? Please check manually."
else
ssh root#10.20.30.40 "echo 'define host{' >> /usr/local/nagios/etc/objects/vz_nodes_hosts.cfg"
ssh root#10.20.30.40 "echo ' use linux-server' >> /usr/local/nagios/etc/objects/vz_nodes_hosts.cfg"
ssh root#10.20.30.40 "echo ' host_name $HOST' >> /usr/local/nagios/etc/objects/vz_nodes_hosts.cfg"
ssh root#10.20.30.40 "echo ' alias $HOST' >> /usr/local/nagios/etc/objects/vz_nodes_hosts.cfg"
ssh root#10.20.30.40 "echo ' address $NODEIP' >> /usr/local/nagios/etc/objects/vz_nodes_hosts.cfg"
(and here after it checks if a RAID controller is present and adds it to the hostgroups of nagios)
So what do I want to achieve?
When the hosts already exists in vz_nodes_hosts.cfg file, it should remove it (everything related to it). I am guessing I have to use sed somehow, however I have no clue on how to remove all those related lines. Also another issue is, is that it sometimes 6 lines (see example 1) and sometimes 7 lines (see examples 2 & 3).
The only method of checking is to check if the host_name (or alias) is already in vz_nodes_hosts.cfg. If it is there, I want to remove everything related to it (6 or 7 lines).
Is this possible? If it's difficult or (maybe) even impossible it should remove the 7 lines (as seen in examples 2 and 3). I doubt the 6 lines will happen a lot and only happens when something is missing, but in time this will get obviously less and less as I am working all the time on this script and tweaking it.
I hope I explained it correcly and hoping someone can help or shed some light on this issue. Thanks in advance.
Okay I managed to get it removed and hopefully it will help others.
I am now using the follwing piece of code to replace a match based on the hostname used:
awk '!/servernonraid200/' RS= ORS="\n\n" /usr/local/nagios/etc/objects/vz_nodes_hosts.cfg > /tmp/vz_nodes_hosts.cfg && mv -f /tmp/vz_nodes_hosts.cfg /usr/local/nagios/etc/objects/vz_nodes_hosts.cfg
Before command:
define host{
use linux-server
host_name server100
alias server100
address 33.33.44.44
}
define host{
use linux-server
host_name servernonraid200
alias servernonraid200
address 55.55.66.66
hostgroups vz_nodes,vz_partion
}
define host{
use linux-server
host_name serverraid300
alias serverraid300
address 77.77.88.88
hostgroups vz_nodes,vz_partion,raid_megacli
}
After command:
define host{
use linux-server
host_name server100
alias server100
address 33.33.44.44
}
define host{
use linux-server
host_name serverraid300
alias serverraid300
address 77.77.88.88
hostgroups vz_nodes,vz_partion,raid_megacli
}
So that's a big succes for me...!
However
It seems awk does not play nice with variables, so running the command with a variable like this:
awk -v '!/$HOST/' RS= ORS="\n\n" /usr/local/nagios/etc/objects/vz_nodes_hosts.cfg > /tmp/vz_nodes_hosts.cfg && mv -f /tmp/vz_nodes_hosts.cfg /usr/local/nagios/etc/objects/vz_nodes_hosts.cfg
Does not. I tried using awk -v, but that didn't prove helpful.
I will try to find a solution and improve my answer, so it might help others. If someone else has an idea on how tix this in the meantime, please do share. I will update the answer as well...!
Update 2 - Fixed!
Okay, I think I managed to fix the previous issue by using single quotes (sometimes the answer seems so easy)
The full working code is:
awk '!/'$HOST'/' RS= ORS="\n\n" /usr/local/nagios/etc/objects/vz_nodes_hosts.cfg > /tmp/vz_nodes_hosts.cfg && mv -f /tmp/vz_nodes_hosts.cfg /usr/local/nagios/etc/objects/vz_nodes_hosts.cfg
This will remove the correct host from the .cfg file with using a variable!
I hope this helps someone. If anyone has a better approach, please advice. :-)
I set myself a small project that involved StevenBlack's host file. I know that he provides a way to make your own hosts file with his Python script, however I wanted to set myself a challenge.
The problem is as follows:
I have a script that gets the Fakenews+Gambling+Social hosts file.
However, I still want to access Reddit. And to make it worse, the file gets constantly updated. Meaning that I can't remove the lines with sed -e '123,456d'.
I think I got pretty close. But I'm not sure, here is the command
cat ./hosts | grep "# Reddit" -A10 | sed -e '1,11d'
While it does indeed remove the Reddit entries, I have no idea how to put it back together. Meaning, that with the command above I can indeed filter out the Reddit lines, but I don't know how to put back into the hosts file and not create an empty file.
It's my first post and I'm very bad at explaining problems. If there is any need for clarification, just say it. Also English isn't my first language, so that doesn't help.
EDIT: Example
cd /home/myname/Documents/git
wget https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-social/hosts
At this point, I have the raw hosts file. Now I want to filter out Reddit. The entries I want to remove are:
Reddit
0.0.0.0 reddit.com
0.0.0.0 www.reddit.com
0.0.0.0 i.reddit.com
0.0.0.0 redd.it
And now comes the problem. I don't know how to remove them from the hosts file, since the lines are changing constantly.
My approach was cat ./hosts | grep "# Reddit" -A10 | sed -e '1,11d', which is in hindsight pretty useless.
You can filter them as you download:
wget "$url" -O- | grep -v 'redd.\?it' > hosts
Is there a way to check playbook syntax and variables?
I'm trying to dry-run(--check) but for some reasons it works really slow. It looks like it tries to perform an action instead of just check the syntax
I want to omit en errors like this:
..."msg": "AnsibleUndefinedVariable: ERROR! 'application_name' is undefined"}
This is expected behaviour according to the documentation:
When ansible-playbook is executed with --check it will not make any
changes on remote systems. Instead, any module instrumented to support
‘check mode’ (which contains most of the primary core modules, but it
is not required that all modules do this) will report what changes
they would have made rather than making them. Other modules that do
not support check mode will also take no action, but just will not
report what changes they might have made.
Old link (does not work anymore): http://docs.ansible.com/ansible/playbooks_checkmode.html
New link: https://docs.ansible.com/ansible/latest/user_guide/playbooks_checkmode.html#using-check-mode
If you would like to check the YAML syntax you can use syntax-check.
ansible-playbook rds_prod.yml --syntax-check
playbook: rds_prod.yml
I was looking for the same, but was not satisfied by the --syntax-check option, since it does not work its way down to the roles. A more complete check can be performed with ansible-lint which also includes style-checks. But if you turn off all style-checks, then you have a pretty complete syntax-check.
So do something like
ansible-lint -x $(echo $(ansible-lint -L | awk -F':' '{print $1}' | grep '^[^ ]') | tr ' ' ',') my_playbook.yml
Add a task to fail the playbook when variables aren't defined. This should be the first task run.
Another option is to ensure that all variables have a default value in the /defaults/ directory so that it never fails, but the variables can still be overwritten at other levels.
My preferd way is
pip install yamllint
yamllint -d "{extends: default, rules: {quoted-strings: enable}}" .
Since I really want to catch quote errors, e.g.
validate: bash -c ' ' \""
This is valid yaml, since yaml will just quote the string and turn it into:
validate: "bash -c ' ' \\\"\""
Whilst there was just clearly a quote missing at the beginning of the validate comand.
So a normal yaml checker will not detect this, yamllint wil not even detect this in it's default configuration, so turn on quoted-strings checker.
I'm trying to make some dzen2 stuff, but i have some hard time on one point. I want to eval color variable between conky and dzen2.
Something like that:
Colors :
#!/bin/zsh
#################################
## Colors for Dzen2 status bar ##
#################################
##
## TEST Colors
##
COLOR_TEST='#000000'
Conkyrc :
#################################
## Conky for Dzen2 Status Bar ##
#################################
background no
out_to_console yes
out_to_x no
override_utf8_locale yes
update_interval 1
total_run_times 0
TEXT
##
## TEST
##
^fg($$COLOR_TEST)
Script:
#!/bin/zsh
. ./colors
conky -c conkyrc | dzen2 -p
I tried eval/echo on conky, but nothing sucessfull.
If somebody have an idea, it will be really nice.
Thanks anyway
Have a good day
EDIT:
If we can't find a solution about the main question, what's the best idea?
Lua/Conky (I think it's not bad)
Shell/Dzen2 (Performance are not amazing last time i tried that)
A full program in C++ (A little overkill, and conky is generic)
How about to use ${execp my-dzen-help.sh getcolors }, in conky ?
#my-dzen-help.sh
getcolors(){
printf '^fg($$COLOR_TEST)'; # or what ....
}
i dont know about dzen, and i dont use zsh,
but i use lemonbar, and i use this, to pass some special UTF-8 chars,
to my lemonbar through conky :
${exec /bin/bash -c 'echo -en "%{T3}\\uf012%{T-}"'}
maybe this, gives you an idea, how to parse-out, variables, from inside a script.
After some thinking i come to a conclusion : create some tools like conky/dzen2 from scratch. Like this i'll have something ready for wayland and more easy to use.
So i'll try to get some time to make it, the most important part will be
"dzen2" with glfw/opengl.
-
But if somebody find an answer for the original question, i'm still curious !
I would like to specify numbered sections via Pandoc's support for YAML front matter. I know that the flag for the command-line usage is --number-sections, but something like
---
title: Test
number-sections: true
---
doesn't produce the desired result. I know that I am close because you can do this with the geometry package (e.g. geometry: margin=2cm). I wish there was a definitive guide on how Pandoc YAML front matter handling. For example, the following is very useful (avoids templates), but its discoverability is low:
header-includes:
- \usepackage{some latex package}
In order to turn on numbered-sections in latex output you need to use numbersections in your YAML block. If you ever want to "discover" things like this with pandoc just poke around the templates:
$ grep -i number default.latex
$if(numbersections)$
$ grep -i number default.html*
$
As you can see this option does not work with html.
Markdown and YAML I tested with:
---
title: Test
numbersections: true
---
# blah
Text is here.
## Double Blah
Twice the text is here
If you need it to work with more than beamer,latex,context,opendoc you will need to file a bug at github.
In order to show section number in the produced output pdf, there are two choices.
In YAML front matter
Add the following setting to begin of markdown file
---
numbersections: true
---
In command line
We can also use the command option to generate pdf with numbered section. According to Pandoc documentation, the correct options is --number-sections or simply -N,
pandoc test.md -o test.pdf --number-sections
# pandoc test.md -o test.pdf -N