I am writing a playbook to replace a string in three files. That string can be written either in lowercase or uppercase. Here is my code :
---
- name: "Modif string"
hosts: myhosts
tasks:
- name: "Replace line"
replace:
path: ~/Documents/{{ item }}
regexp: 'test'
replace: 'new'
with_items:
- 'file'
- 'file1'
- 'file2'
How can I make it work so the string 'test' is amended either it is written in lowercase or uppercase? Also what if there is randomly letter uppercase or lowercase in that string?
Thank you all.
Try as below
- name: "Replace line"
replace:
path: ~/Documents/{{ item }}
regexp: '(?i)test'
replace: 'new'
I finally wrote that script. Works like a charm.
- name: "Other test"
hosts: raspi
vars:
text_to_replace:
- {regexp: '(?i)(test)', line: 'new'}
- {regexp: '10', line: '20'}
my_files:
- {file: 'file'}
- {file: 'file1'}
- {file: 'file2'}
tasks:
- name: "Replace"
replace:
path: ~/test/{{item.1.file}}
regexp: "{{item.0.regexp}}"
replace: "{{item.0.line}}"
with_nested:
- "{{text_to_replace}}"
- "{{my_files}}"
Related
I am trying to create a schema which includes key - value arrays, but the properties are themselves separately defined. For example, lets say I would like to describe a file with following properties:
id
fileName
fileType
where fileType is an object with id and a specific set of acceptable key-value combination, for example
0, Word
1, Excel
2, PDF
... etc
I am a bit confused on how to describe this with OpenApi 3 as from the documentation I can't seem to find a way to describe arrays with specific key - value combinations.
Right now I am using an enum like below
components:
schemas:
fileType:
type: string
description: file type
enum:
- Word
- Excel
- PDF
but that is inadequate.
Thanks
You can use something like this:
Your fileType Schema
components:
schemas:
fileType:
type: object
description: file type
properties:
1:
type: string
example: "Word"
2:
type: string
example: "Excel"
3:
type: string
example: "PDF"
Here is your requestBudy
requestBody:
description: File
content:
'*/*':
schema:
properties:
id:
type: string
fileName:
type: string
fileType:
$ref: '#/components/schemas/fileType'
Looks like
Hope this help.
I am working on a project where we receive a flat file but the first and last lines have information that does not fit the fixed width pattern. Is there a way to dataweave all of this information correctly and if possible put the header and footer into variables and just have the contents in the payload.
Example File
HDMTFSBEUP00000220170209130400 MT HD07
DT01870977 FSFSS F3749261 CR00469002017020820170225 0000
DT01870978 FSFSS F3749262 CR00062002017020820170125 0000
TRMTFSBEUP00000220170209130400 000000020000002000000000000043330000000000000 0000
I know for CSV you can skip a line but dont see it with fixed width and also the header and footer will both start with the first 2 letters every time so maybe they can be filtered by dataweave?
Please refer to the DataWeave Flatfile Schemas documentation. There are several examples for processing several different types of data.
In this case, I tried to simplify your example data, and apply a custom schema as follow:
Example data:
HDMTFSBEUP00000220170209130400
DT01870977
DT01870978
TRMTFSBEUP00000220170209130400
Schema/Flat File Definition:
form: FLATFILE
structures:
- id: 'test'
name: test
tagStart: 0
tagLength: 2
data:
- { idRef: 'header' }
- { idRef: 'data', count: '>1' }
- { idRef: 'footer' }
segments:
- id: 'header'
name: header
tag: 'HD'
values:
- { name: 'header', type: String, length: 39 }
- id: 'data'
name: data
tag: 'DT'
values:
- { name: 'code', type: String, length: 17 }
- id: 'footer'
name: footer
tag: 'TR'
values:
- { name: 'footer', type: String, length: 30 }
The schema will validate the example data and identify based on the tag, the first 2 letters. The output will be grouped accordingly.
{
"header": {},
"data": [{}, {}],
"footer": {}
}
Since the expected result is only the data, then just select it: payload.data.
Use range selector to skip header and footer.
payload[1..-2] map {
field1: $[0..15],
field2: $[16..31]
...,
...
}
[1..-2] will select from 2nd line till the second last line in the payload.
$[0..15] will select from 1st column index to 16th index. $[16..31] select from 17th column index to 32nd index.
I was facing the same issue and the answer #sulthony h wrote needs a little tweak. I used these lines instead and it worked for me.
data:
- { idRef: 'header', count: 1 }
- { idRef: 'data', count: '>1' }
- { idRef: 'footer', count: 1 }
"count" was missing from header and footer, and that was throwing an exception. Hope this helps.
I am trying to make a kit pvp server and my players are not being able to use signs at all!
groups:
Initiate:
options:
default: 'true'
prefix: '&0[&3Initiate&0]&f'
permissions:
- modifyworld.*
- essentials.eco
- essentials.pay
- essentials.pay.multiple
- essentials.afk
- essentials.afk.auto
- essentials.mail
- essentials.mail.send
- essentials.msg
- essentials.rules
- essentials.seen
- essentials.seen.banreason
- essentials.suicide
- essentials.spawn
- essentials.keepxp
- essentials.warp
- essentials.warp.list
- essentials.warp.afireandice
- essentials.warp.forestlyr
- essentials.warp.mainplains
- essentials.warp.spawn
- essentials.signs.use.balance
- essentials.signs.use.buy
- essentials.signs.use.disposal
- essentials.signs.use.free
- essentials.signs.use.heal
- essentials.signs.use.info
- essentials.signs.use.mail
- essentials.signs.use.repair
- essentials.signs.use.sell
- essentials.signs.use.warp
- kingkits.command.previewkit
- kingkits.sign.list.use
- kingkits.sign.kit.use
- kingkits.compass
- kingkits.quicksoup
schema-version: 1
users:
9bb304e6-2ff2-4acc-b073-d899993e157d:
group: []
options:
name: CraigSwords
7225aabb-6ae9-4081-add2-00dbdd6d114c:
group: []
options:
name: SocialSavior
b4c5a860-8e01-4306-99c7-3457e935eed3:
group: []
options:
name: mewtwolvex
7f1e5c73-3fac-4b5e-b7ed-6661740470a7:
group: []
options:
name: Slick10000
Your Initiate group permissions appear to be correct. Even though this group is configured to be the default group, it is not assigned to your players since you have explicit group definitions for all (i.e. group: []). Removing the empty group definitions from your players will cause PEX to assign them to your default Initiate group.
I am trying to shrink several chunks of similar code which looks like:
- ... multiple things is going here
register: list_register
- name: Generating list
set_fact: my_list="{{ list_register.results | map(attribute='ansible_facts.list_item') | list }}"
# the same code repeats...
The only difference between them is list name instead of my_list.
In fact, I want to do this:
set_fact:
"{{ some var }}" : "{{ some value }}"
I came across this post but didn't find any answer here.
Is it possible to do so or is there any workaround?
take a look at this sample playbook:
---
- hosts: localhost
vars:
iter:
- key: abc
val: xyz
- key: efg
val: uvw
tasks:
- set_fact: {"{{ item.key }}":"{{ item.val }}"}
with_items: "{{iter}}"
- debug: msg="key={{item.key}}, hostvar={{hostvars['localhost'][item.key]}}"
with_items: "{{iter}}"
The above does not work for me. What finally works is
- set_fact:
example_dict: "{'{{ some var }}':'{{ some other var }}'}"
Which is in the end obvious. You construct a string (the outer double quotes) which is then interpreted as a hash. In hashes key and value must be single quotes (the inner single quotes around the variable replacements). And finally you just place your variable replacements as in any other string.
Stefan
As of 2018, using ansible v2.7.1, the syntax you suggest in your post works perfectly well.
At least in my case, I have this in role "a" :
- name: Set fact
set_fact:
"{{ variable_name }}": "{{ variable_value }}"
And that in role "b" :
- debug:
msg: "variable_name = {{ variable_name }}"
And execution goes :
TASK [role a : Set fact] *******************************************************
ok: [host_name] => {
"ansible_facts": {
"variable_name": "actual value"
},
"changed": false
}
...
TASK [role b : debug] **********************************************************
ok: [host_name] => {}
MSG:
variable_name = actual value
- set_fact: '{{ some_var }}={{ some_value }}'
It creates a string of inline module parameter expression by concatenating value of some_var (fact name), separator = and value of some_value (fact value).
- set_fact:
var1={"{{variable_name}}":"{{ some value }}"}
This will create a variable "var1" with your dynamic variable key and value.
Example: I used this for creating dynamic tags in AWS Autoscaling group for creating kubernetes tags for the instances like this:
- name: Dynamic clustertag
set_fact:
clustertag={"kubernetes.io/cluster/{{ clustername }}":"owned"}
- name: Create the auto scale group
ec2_asg:
.
.
.
tags:
- "{{ clustertag }}"
Beware of a change in 2.9 – the behaviour changed rendering all the answers invalid. https://github.com/ansible/ansible/issues/64169
Ok so my problem is that my minecraft server will not read this so it comes up with no permissions at all. I have typed this from scratch following all of the guide-lines. I have tried altering the big and the small and testing each time and can come up with anything thank, Pokpok300 ~Ben
groups:
Player:
default: 'true'
options:
rank: '1000'
prefix: '&0[&2Player&0]'
Permissions:
-essentials.kit
-essentials.balance
-essentials.balancetop
-essentials.pay
-essentials.afk
-essentials.afkauto
-essentials.customtext
-essentials.help
-essentials.helpop
-essentials.mail*
-essentials.me
-essentials.msg*
-essentials.rules
-essentials.spawn
-essentials.delhome
-essentials.home
-essentials.sethome
-essentials.tpaccept
-essentials.tpahere
-essentials.tpdeny
-essentials.warp
-essentials.warp.list
Member:
inheritance:
- Player
options:
rank: '900'
prefix: '&0[&3Member&0]'
Permissions:
-essentials.ignore
-essentials.suicide
Member+:
inheritance:
- Member
options:
prefix: '&0[&3Member+0]'
rank: '500'
Permissions:
-essentials.recipe
-essentials.enderchest
Trial-Mod:
inheritance:
- Member+
options:
prefix: '&0[&7Trial-Mod&0]'
rank: '400'
Permissions:
-essentials.tree*
-essentials.workbench*
-essentials.realname
-essentials.whois*
-essentials.jails
-essentials.kick
-essentials.mute*
-essentials.tempban*
-essentials.togglejail*
-essentials.weather
-essentials.jump
Mod:
inheritance:
- Trial-Mod
options:
prefix: '&0[&7Mod&0]'
rank: '300'
Permissions:
-essentials.fly*
-essentials.time*
-essentials.helpop*
-essentials.spawner*
-essentials.invsee*
-essentials.vanish*
-essentials.back
-essentials.sethome.multiple.3
-essentials.tpaall
-essentials.world*
Trial-Admin:
inheritance:
- Mod
options:
prefix: '&0[&1Trial-Admin&0]'
rank: '200'
Permissions:
-essentials.gamemode*
-essentials.give*
-essentials.god*
-essentials.heal*
-essentials.repair*
-essentials.unlimited*
-essentials.ignore*
-essentials.ban*
-essentials.banip*
-essentials.clearinventory*
-essentials.enderchest*
-essentials.fireball
-essentials.kickall*
-essentials.kill*
-essentials.remove*
-essentials.unban*
-essentials.unbanip*
-essentials.top*
Admin:
inheritance:
- Trial-Admin
options:
prefix: '&0[&1Admin&0]'
rank: '100'
Permissions:
-essentials.exp*
-essentials.feed*
-essentials.more*
-essentials.speed*
-essentials.powertool*
-essentials.powertooltoggle*
-essentials.backup*
-essentials.broadcast
-essentials.deljail
-essentials.setjail
-essentials.setspawn
-essentials.delwarp
-essentials.sethome*
-essentials.tpall*
-essentials.tphere*
-essentials.tpo*
-essentials.tpohere*
-essentials.tppos*
-essentials.tptoggle*
Co-Owner:
inheritance:
- Admin
options:
prefix: '&0[&6Co-Owner&0]'
rank: '50'
Permissions:
Owner:
inheritance:
- Co-Owner
options:
prefix: '&0[&9Owner&0]'
rank: '1'
Permissions:
-essentials.nuke*
Dontator:
inheritance:
- Member+
options:
prefix: '&0[&2Dontator&0]'
Permissions:
-essentials.workbench*
-essentials.recipe
Dontator+:
inheritance:
- Dontator
options:
prefix: '&0[&2Dontator+&0]'
Permissions:
-essentials.nick
-essentials.nick.color
Dontator++:
inheritance:
- Dontator++
options:
prefix: '&0[&2Dontator++&0]'
Permissions:
-essentials.nick
-essentials.nick.color
-essentials.nick.magic
-essentials.nick.format
CustomDontator:
options:
prefix: '&0[&2Dontator+++&0]'
Permissions:
I see you are new at this... So I fixed everything up!
groups:
Player:
default: 'true'
options:
rank: '1000'
prefix: '&0[&2Player&0]'
permissions:
- essentials.kit
- essentials.balance
- essentials.balancetop
- essentials.pay
- essentials.afk
- essentials.afk.auto
- essentials.customtext
- essentials.help
- essentials.helpop
- essentials.mail.*
- essentials.me
- essentials.msg.*
- essentials.rules
- essentials.spawn
- essentials.delhome
- essentials.home
- essentials.sethome
- essentials.tpaccept
- essentials.tpahere
- essentials.tpdeny
- essentials.warp
- essentials.warp.list
Member:
inheritance:
- Player
options:
rank: '900'
prefix: '&0[&3Member&0]'
permissions:
- essentials.ignore
- essentials.suicide
Member+:
inheritance:
- Member
options:
prefix: '&0[&3Member+0]'
rank: '500'
Permissions:
- essentials.recipe
- essentials.enderchest
Trial-Mod:
inheritance:
- Member+
options:
prefix: '&0[&7Trial-Mod&0]'
rank: '400'
permissions:
- essentials.tree
- essentials.workbench
- essentials.realname
- essentials.whois
- essentials.jail
- essentials.kick
- essentials.mute
- essentials.tempban
- essentials.togglejail
- essentials.weather
- essentials.jump
Mod:
inheritance:
- Trial-Mod
options:
prefix: '&0[&7Mod&0]'
rank: '300'
permissions:
- essentials.fly
- essentials.time
- essentials.helpop
- essentials.spawner
- essentials.invsee
- essentials.vanish
- essentials.back
- essentials.sethome.multiple.3
- essentials.tpaall
- essentials.world
Trial-Admin:
inheritance:
- Mod
options:
prefix: '&0[&1Trial-Admin&0]'
rank: '200'
permissions:
- essentials.gamemode
- essentials.give
- essentials.god
- essentials.heal
- essentials.repair
- essentials.unlimited
- essentials.ignore
- essentials.ban
- essentials.banip
- essentials.clearinventory
- essentials.enderchest
- essentials.fireball
- essentials.kickall
- essentials.kill
- essentials.remove
- essentials.pardon
- essentials.pardonip
- essentials.top
Admin:
inheritance:
- Trial-Admin
options:
prefix: '&0[&1Admin&0]'
rank: '100'
permissions:
- essentials.exp
- essentials.feed
- essentials.more
- essentials.speed
- essentials.powertool
- essentials.powertooltoggle
- essentials.backup
- essentials.broadcast
- essentials.deljail
- essentials.setjail
- essentials.setspawn
- essentials.delwarp
- essentials.sethome
- essentials.tpall
- essentials.tpa
- essentials.tpahere
- essentials.tppos
- essentials.tptoggle
Co-Owner:
inheritance:
- Admin
options:
prefix: '&0[&6Co-Owner&0]'
rank: '50'
permissions:
Owner:
inheritance:
- Co-Owner
options:
prefix: '&0[&9Owner&0]'
rank: '1'
Permissions:
- essentials.nuke
Dontator:
inheritance:
- Member+
options:
prefix: '&0[&2Dontator&0]'
default: false
Permissions:
- essentials.workbench
- essentials.recipe
Dontator+:
inheritance:
- Dontator
options:
prefix: '&0[&2Dontator+&0]'
default: false
permissions:
- essentials.nick
- essentials.nick.color
Dontator++:
inheritance:
- Dontator++
options:
prefix: '&0[&2Dontator++&0]'
default: false
permissions:
- essentials.nick
- essentials.nick.color
- essentials.nick.magic
- essentials.nick.format
CustomDontator:
options:
prefix: '&0[&2Dontator+++&0]'
default: false
Permissions: