How to make two columns from one list - wiki

I have one list and I want to make two columns from him, something like this:
I have this:
====== Known Errors ======
1.
2.
3.
.....
47.
and I want this
====== Known Errors ======
1. 28.
2. 29.
3. 30.
.... ....
27. 47.
and my code is this :
====== Known Errors ======
- [[testlabplus/known_errors/table_not_accessible|Control table not acessible]]
- [[testlabplus/known_errors/calendar_view|Calendar view used by multiple users]]
- [[testlabplus/known_errors/Unknown_Publisher|Unknown Publisher]]
- [[testlabplus/known_errors/error_during_update|Error during the update of TLP to a new version/SP]]
- [[testlabplus/known_errors/calendar_view/doc_new_version|Create new version of a document]]
- [[testlabplus/known_errors/export_ms_proj|Export to MS Project]]
- [[testlabplus/known_errors/save_filter_in_resource|Save filter in Resource planning]]
- [[testlabplus/known_errors/new_order|Create new order]]
- [[testlabplus/known_errors/open_test_report|Open test report]]
- [[testlabplus/known_errors/app_startup|Application startup]]
- [[testlabplus/known_errors/app_startup_tlp|Application 'TLP.exe' startup ]]
- [[testlabplus/known_errors/proj_code_on_order|Project code on an order]]
FIXME

Wiki documentation offers use directive columns_list.
In your case:
====== Known Errors ======
{{columns_list|2|
- [[testlabplus/known_errors/table_not_accessible|Control table not acessible]]
- [[testlabplus/known_errors/calendar_view|Calendar view used by multiple users]]
- [[testlabplus/known_errors/Unknown_Publisher|Unknown Publisher]]
- [[testlabplus/known_errors/error_during_update|Error during the update of TLP to a new version/SP]]
- [[testlabplus/known_errors/calendar_view/doc_new_version|Create new version of a document]]
- [[testlabplus/known_errors/export_ms_proj|Export to MS Project]]
- [[testlabplus/known_errors/save_filter_in_resource|Save filter in Resource planning]]
- [[testlabplus/known_errors/new_order|Create new order]]
- [[testlabplus/known_errors/open_test_report|Open test report]]
- [[testlabplus/known_errors/app_startup|Application startup]]
- [[testlabplus/known_errors/app_startup_tlp|Application 'TLP.exe' startup ]]
- [[testlabplus/known_errors/proj_code_on_order|Project code on an order]]
}}
For external links:
{{columns_list|2|
- [//testlabplus/known_errors/table_not_accessible Control table not acessible]
- [//testlabplus/known_errors/calendar_view Calendar view used by multiple users]
- [//testlabplus/known_errors/Unknown_Publisher Unknown Publisher]
- [//testlabplus/known_errors/error_during_update Error during the update of TLP to a new version/SP]
- [//testlabplus/known_errors/calendar_view/doc_new_version Create new version of a document]
- [//testlabplus/known_errors/export_ms_proj Export to MS Project]
- [//testlabplus/known_errors/save_filter_in_resource Save filter in Resource planning]
- [//testlabplus/known_errors/new_order Create new order]
- [//testlabplus/known_errors/open_test_report Open test report]
- [//testlabplus/known_errors/app_startup Application startup]
- [//testlabplus/known_errors/app_startup_tlp Application 'TLP.exe' startup ]
- [//testlabplus/known_errors/proj_code_on_order Project code on an order]
}}

Related

Promtail force lowercase on log_level: "error" from (?P<log_error>(error|Error|ERROR))

I'm trying to create two labels(/values) to filter my logs on: warning and error. For graphing and logline panels.
I'm thinking log_level: warning or log_level: error. However, log_error: and log_warning: would also work. But with the code below, grafana/loki groups amd distinguishes my label values based on all the different variations.
- match:
selector: '{job="varlogs"}'
stages:
- regex:
expression: '.*(?P<log_error>(error|Error|ERROR)).*'
- labels:
log_error:
- match:
selector: '{job="varlogs"}'
stages:
- regex:
expression: '.*(?P<log_warning>(warn|Warn|WARN|warning|Warning|WARNING)).*'
- labels:
log_warning:
This works on the Loki side: {host="$host", filename=~"$log_type"} |~"(?i)error". But I prefer them straight as labels before they come in.
Anybody got tips to force lowercase (on the promtail side)?
If I'm reading the question correctly, the reason the sample config produces labels with varying case is that it uses dynamic labels taken from a named group in the regex. Consequently, if a log line contained (e.g.) "Error", it would have a log_error label "Error" (rather than "error", which is desired). Instead of a dynamic label, you should be able to use a static label. Additionally, it should be possible to add the case-insensitive flag to the patterns so that the case variants don't need to be specified. Perhaps something like:
- match:
selector: '{job="varlogs"}'
stages:
- regex:
expression: '(?i).*\berror\b.*'
- labels:
log_level: error
- match:
selector: '{job="varlogs"}'
stages:
- regex:
expression: '(?i).*\bwarn(ing)\b.*'
- labels:
log_level: warning
This could then be queried with:
{host="$host", filename=~"$log_type", log_level="warning"}
Alternatively, instead of testing for a specific label value, the presence of the label itself can be tested for by matching it against a .+ regex (this is suggested by the Prometheus querying documentation, which is referenced by the Grafana Loki log stream selector documentation). With the config in the question, you'd use:
{host="$host", filename=~"$log_type", log_error=~".+"}
Caveat: untested. I'm not a Grafana Loki user, nor do I have access to a server.

Performing regex_findall and split() on the same line

Here is the output that I'm trying to parse:
hostname#show bgp vrf vrfname summary | i 1.1
BGP Route Distinguisher: 1.1.1.1:0
BGP router identifier 1.1.1.1, local AS number 2222
1.1.1.3 0 64512 349608 316062 896772 0 0 2w4d 1
I have the following regex that succesfully matches just the last line. Now I need to split that line and view the last index. In this case it is "1", but I will want to fail if that value is "0".
- name: debug test
debug:
msg: "{{show_bgp_sessions.data | regex_findall('\\d+\\.\\d+\\.\\d+\\.\\d+\\s\\s.*')}}"
I tried adding a split in a couple different formats at the end of the "msg" line so that I can grab the last index to compare it in the failed_when statement:
msg: "{{show_bgp_sessions.data | regex_findall('\\d+\\.\\d+\\.\\d+\\.\\d+\\s\\s.*') | split(' ')}}"
But I'm getting the following error msg:
"template error while templating string: no filter named 'split'. String:
I've also tried to use a few different forms of "ends_with" to verify the last index in the string as I've used that a lot in my python experience, but I can't get it to work in ansible.
I can't create a new task to parse the data and perform the split seperately because I need to run this verification through a loop.
When you select the line, reverse the string, and split the first item. For example
msg: "{{ (my_line|reverse).split()|first }}"
Possibly the regex provided by #Thefourthbird is a better solution.
But for your issue at hand, this is caused by the fact that there is indeed no filter split in Jinja, see the list there: https://jinja.palletsprojects.com/en/2.11.x/templates/#list-of-builtin-filters.
The reason why there is no such a filter is simple: split() is a function of the Python String, and since Jinja is Python, you can just use it as is.
Also mind that, since regex_findall is meant for multiple matches, you'll have to select the first element of the list, for example, with the filter first.
So your message ends up being:
msg: >-
{{
(
show_bgp_sessions.data
| regex_findall('\\d+\\.\\d+\\.\\d+\\.\\d+\\s\\s.*')
| first
).split()
}}
Given the playbook:
- hosts: all
gather_facts: no
vars:
show_bgp_sessions:
data: |
hostname#show bgp vrf vrfname summary | i 1.1
BGP Route Distinguisher: 1.1.1.1:0
BGP router identifier 1.1.1.1, local AS number 2222
1.1.1.3 0 64512 349608 316062 896772 0 0 2w4d 1
tasks:
- debug:
msg: >-
{{
(
show_bgp_sessions.data
| regex_findall('\\d+\\.\\d+\\.\\d+\\.\\d+\\s\\s.*')
| first
).split()
}}
Gives the recap:
TASK [debug] ***************************************************************
ok: [localhost] => {
"msg": [
"1.1.1.3",
"0",
"64512",
"349608",
"316062",
"896772",
"0",
"0",
"2w4d",
"1"
]
}

Ansible List Variable and Select Filter to ignore matched items

I have a variable dir_lst_raw in an ansible playbook whose value is a list as shown below:
"dir_lst_raw": [
"/path1/dir1/user",
"/path2/dir2/admin",
"/path3/dir3/user.ansible_backup_2020-03-16",
"/path1/dir1/config.ansible_backup_2020-03-16",
"/path2/dir2/dir3/somefile"
]
I need to remove all the lines containing .ansible_backup_ and save to another variable as a list.
I've googled for regex and tried to not match the pattern with the select filter as below:
- set_fact:
dir_lst: "{{ dir_lst_flt_r | select('match','(^.ansible_backup_)+') | list }}"
but the new variable dir_lst turned out as an empty list. I am expecting dir_lst as below:
"dir_lst_raw": [
"/path1/dir1/user",
"/path2/dir2/admin",
"/path2/dir2/dir3/somefile"
]
Could somebody please suggest how can I get it done?
Q: "Remove all the lines containing .ansible_backup_"
A: The task below does the job
- set_fact:
dir_lst: "{{ dir_lst_raw|reject('match', my_regex)|list }}"
vars:
my_regex: '^(.*)\.ansible_backup_(.*)$'
- debug:
var: dir_lst
gives
dir_lst:
- /path1/dir1/user
- /path2/dir2/admin
- /path2/dir2/dir3/somefile

Azure Pipeline dynamic parameters to template file from YAML pipeline

I am currently working with Azure Devops Build Pipelines, and am trying to call a template file to do some tasks from my build yaml.
I am facing some difficulties to pass parameters to the template file. Let assume that this is my template file (simplified) which works fine :
parameters:
iterations: []
steps:
- ${{ each i in parameters.iterations }}:
- task: PowerShell#2
displayName: "Get key values ${{i}}"
name: getKeyValues_${{i}}
inputs:
targetType: 'inline'
script: |
$item = "${{i}}"
Write-Host "item : $($item)"
$keyVal = $item -split "_"
Write-Host $keyVal
Write-Host "key: $($keyVal[0]) | value: $($keyVal[1])"
echo "##vso[task.setvariable variable=key;isOutput=true]$($keyVal[0])"
echo "##vso[task.setvariable variable=value;isOutput=true]$($keyVal[1])"
So I want my iterations parameter contain something like this :
iterations: ["1_60", "2_40"]
Inside my Yaml pipeline I have the following code(also simplified) :
Not working scenario
- task: PowerShell#2
displayName: Calculate iterations for $(copies) copies
name: calculateIterations
inputs:
targetType: 'inline'
script: |
# Do some stuf here to get the arrow below from int value = 100
$iterations = ["1_60, "2_40"]
echo "##vso[task.setvariable variable=iterations;isOutput=true]$($iterations)"
- template: container-template.yml
parameters:
iterations: $(calculateIterations.iterations)
Working scenario
- task: PowerShell#2
displayName: Calculate iterations for $(copies) copies
name: calculateIterations
inputs:
targetType: 'inline'
script: |
# Do some stuf here to get the arrow below from int value = 100
$iterations = ["1_60, "2_40"]
echo "##vso[task.setvariable variable=iterations;isOutput=true]$($iterations)"
- template: container-template.yml
parameters:
iterations: ["1_60, "2_40"]
As you can see, the problem is that I am unable to use the output variable of my script to pass it as parameter to my template.
When I run the not working scenario I have the following error :
I have found this post, but no solutions yet...
As what 4c74356b41 said, this is the dilemma at present. In another word, the Not working scenario you mentioned does not support to achieve until now.
Now, we must let the template know the clear text at compile time. Because during this compile time, we have difficulty to do 2 or more things in one step at same time, especially contain compiling variable value, passing to corresponding template dynamic arguments and etc.
Expected a sequence or mapping. Actual value
'$(calculateIterations.iterations)'
More detailed, during compile time (after you click Run but before pipeline start truely):
1) Firstly we map the value that come from YAML pipeline, to make sure the - ${{ each i in parameters.iterations }} has clear value to start.
2) After it is done, then parse exact value on name: getKeyValues_${{i}} in script order.
In your scenario, it cannot even satisfy the first step since what you passed is a variable, and we do not has parse value process here. That's why you saw error said Expected a sequence or mapping. Actual value '$(calculateIterations.iterations)'.
Another expression of this error message is: we(template) are looking forward to exact value(s) to map our dynamic parameters, but what you give is a unrecognized content $(calculateIterations.iterations). Sorry, we cannot start to run.

How to Insert a new string into telegraf.conf's inputs.ping using ansible regexp

I'm trying to use ansible to update telegraf.conf's [[inputs.ping]].
telegraf.conf looks like the following:
[[inputs.ping]]
urls = ["tac-temp1","tac-temp2", "tac-temp3","tac-temp4"] #tac
count = 30
timeout = 15.0
[inputs.ping.tags]
name = "tac"
[[inputs.ping]]
urls = ["prod-temp1","prod-temp2", "prod-temp3","prod-temp4"] #prod
count = 30
timeout = 15.0
[inputs.ping.tags]
name = "prod"
[[inputs.ping]]
urls = ["test-temp1","test-temp2", "test-temp3","test-temp4"] #test
count = 30
timeout = 15.0
[inputs.ping.tags]
name = "test"
I'm trying to add ,"tac-temp10" after ,"tac-temp4" in line 2 shown above.
- hosts: Servers
become: yes
become_method: sudo
tasks:
- name: Loading telegraf.conf content for search
shell: cat /tmp/telegraf.conf
register: tele_lookup
- name: Adding Server to /tmp/telegraf.conf if does not exists
lineinfile:
path: /tmp/telegraf.conf
state: present
regexp: '^((.*)"] #tac$)'
line: ',"tac-temp10"'
backup: yes
when: tele_lookup.stdout.find('tac-temp10') != '0'
regexp: '^((.*)"] #tac$)' is replacing the whole line with ,"tac-temp10". Expected output:
[[inputs.ping]]
urls = ["tac-temp1","tac-temp2", "tac-temp3","tac-temp4","tac-temp10"] #tac
count = 30
timeout = 15.0
[inputs.ping.tags]
name = "tac"
Warning: Ugly regexp ahead. Beware of unpredictable understanding for next guys (including you after time passed by...) doing maintenance.
The following will add your server at the end of the list if it is not already present (anywhere in the list) with a single idempotent task.
- name: add our server if needed
lineinfile:
path: /tmp/test.conf
backup: yes
state: present
regexp: '^( *urls *= *\[)(("(?!tac-temp10)([a-zA-Z0-9_-]*)",? *)*)(\] #tac)$'
backrefs: yes
line: '\1\2, "tac-temp10"\5'
You need to use backreferences to put back on the line the already matched parts of the expression. I used backup: yes so I could easily come back to the original for my tests. Feel free to drop it.
As you can see (and as advised in my warning) this is pretty much impossible to understand for anyone having to quickly read the code. If you have to do anything more fancy/complicated, consider using a template and storing your server list in a variable somewhere.