Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
post hole digger
Mar 21, 2011

I'm not sure this is the right place to ask this but I'm working with ansible and trying to learn a little about facts, and I'm wondering why this:

code:
ansible myserver -m setup -a "filter=ansible_default_ipv4.alias"
myserver.com | SUCCESS => {
    "ansible_facts": {},
    "changed": false
}
doesn't work, but making a playbook with this info:

- debug: msg="{{ ansible_default_ipv4.alias }}"

does work, eg:

code:
TASK [debug] **************************************************************
ok: [myserver.com] => {
    "msg": "eth0"
}
I'm sure there's a simple explanation for this... but what is it?

Adbot
ADBOT LOVES YOU

post hole digger
Mar 21, 2011

Yep. I've noticed that running that type of filter, looking for a "nested" (not sure if thats the right word) fact within a fact doesn't seem to work as an ad-hoc command for anything I've tried.

eg this works fine:

code:
$ ansible myserver -m setup -a "filter=ansible_default_ipv4"
myserver.com | SUCCESS => {
    "ansible_facts": {
        "ansible_default_ipv4": {
            "address": "172.31.XX.XXX",
            "alias": "eth0",
            "broadcast": "172.31.31.255",
            "gateway": "172.31.16.1",
            "interface": "eth0",
            "macaddress": "06:d1:6f:e5:a9:a0",
            "mtu": 9001,
            "netmask": "255.255.240.0",
            "network": "172.31.16.0",
            "type": "ether"
        }
    },
    "changed": false
}
but i cant successfully zero in on anything within 'ansible_default_ipv4' when running an ad-hoc command. is the syntax different when working with ad-hoc? a difference in how debug and setup modules process fact filtering?

post hole digger fucked around with this message at 00:11 on Oct 21, 2017

post hole digger
Mar 21, 2011

There it is... thank you. I looked at the module page but I glossed right over that :tipshat:

post hole digger
Mar 21, 2011

Is Spacewalk still relevant as a package management system? we run a pretty... dated... software mangement and distribution system for cent7 and I'm seeing how to best replace it. Our main goal is to have all of our systems running the same versions of software. We don't do any fancy containerization yet and use cobbler for provisioning. Is building an internal repo still something people do? I've also seen Foreman but it seems... sprawling and we'd really only need the package/repo management part of it for now. Is there a newer open space project based on Satellite? Pulp also looks interesting. I guess I'm just looking for ideas or suggestions as to what other people are doing for this.

post hole digger
Mar 21, 2011

can anyone recommend a podcast app for fedora? ive tried vocal and its a buggy pos

post hole digger
Mar 21, 2011

For how long has Centos had security errata in yum (ie yum --security update)? I thought that was a RHEL only thing and was surprised to see it work the other day.

post hole digger
Mar 21, 2011

anthonypants posted:

CentOS (and Fedora) are kind of upstream of RHEL, so I'm gonna say almost exactly as long as RHEL

I'm pretty sure that's not the case, there have been a bunch of projects designed to provide security errata for centos.

https://petersouter.xyz/the-story-of-errata-for-centos/

post hole digger
Mar 21, 2011

I'm not sure if this is the right thread for this (hopefully it is) but I am trying to write a sed one liner to find a string which is wrapped in curly braces, and then once its found that string, expand the selection to the leading and trailing curly braces, and then delete everything.

An example of the file I'm working with looks like this:

code:
{
  package => 'package',
  version => '1.0.0',
  commands => [
    ['jslib', '.'],
    ['thing1','thing2'],
    ['other','thing']
  ]
},
{
  package => 'winston',
  version => '1.2.3',
  commands => [
    ['jslib', '.']
  ]
},
{
  package => 'other-thing',
  version => '4.2.0',
  commands => [
    ['thing', '.'],
    ['thing', '.'],
    ['thing', '.']
  ]
},
{
  package => 'wrench',
  version => '1.0.0',
  commands => [
    ['jslib', '.'],
    ['thing','bin']
  ]
},
And what I'm trying to do is to find 'winston' (or any of the other ones) and then delete its top and bottom braces (plus the trailing comma), so this:

code:
{
  package => 'winston',
  version => '1.2.3',
  commands => [
    ['jslib', '.']
  ]
},
I thought sed would be the easiest way to do this but I am not having very much luck. I was hoping that something like something like this would work:
code:
sed -i -r "/\{\n\s\spackage\s\=\>\s\'winston\'\,(.|\n)+?\}\,/d" ~/test.txt
No errors with this, but no changes to the file either.

Can anyone help me write a sed command that makes sense for this or guide me in a better direction? I'm also using double quotes in the line above because I will eventually want to pass a variable to the command.

I've checked with a couple PCRE regex validators online and my regex seems correct, so I thought that sed -r would be sufficient to parse it, but it seems like I might be miles off trying to just use sed, even running
code:
cat ~/test.txt | sed -r "/\s\spackage\s\=\>\s\'winston\'/d"
won't remove the single line containing package => 'winston',

post hole digger fucked around with this message at 01:39 on Nov 2, 2018

post hole digger
Mar 21, 2011

Ryaath posted:

Allow me to introduce you to our Lord and savior, jq

Thanks, I'll check this out.

Methanar posted:

Is there any particular reason you're treating this as a regular string and not the structured data that it is?

Can you tell us what you're actually trying to do

No, no reason at all. When I started working on this, I did briefly look at jq, but I don't have a ton of experience with JSON and I wasn't sure if something like that would work because of the => symbols. I also wasn't sure if that data actually was in JSON format because of the => symbols. Also, there are some strings at the beginning of this file, and I thought that might affect how the file was read. So I thought sed would be easiest, and then started having the issues which led me to post. Basically just didn't know any better.

As for what I am doing, I am just trying to automate a workflow for myself. I am working on something that requires me to run a few bash commands, then I need to edit this file to delete a reference to the package (the part from my original post), and then run a few more commands that read that file once the string (data object?) has been removed.

Docjowles posted:

Use jq, or a json parsing lib in your favorite language that isn’t Bash. You can do this super easily in Python or Ruby or whatever.

Or tell us why this has to be bash.

It doesn't have to be in bash. I was actually looking at Ruby potentially being easier to work with, I have a little experience with that and it looks like its just a couple of lines of Ruby. The only reason I was doing it in bash is this is one step out of a dozen or so, and the other steps are just bash commands. I started writing a shell script that was just the bash commands I needed to run, then I realized I forgot this step, and went back and tried to work it in with sed, which seemed like the most sensible tool to use at the time.

post hole digger fucked around with this message at 06:40 on Nov 2, 2018

Adbot
ADBOT LOVES YOU

post hole digger
Mar 21, 2011

Since the file I have to work with is not quite standard JSON and contains a few oddities (commented out blocks, => symbols, variables defined at the top of the file), I didn't want to spend too much more time trying to get jq to play nice with it, and I've gone the hacky ruby route. Here is what I ended up with if anyone cares. After I added some parenthesis around the regex, it works for my needs.

code:

  pkg = "winston"

  re = /(\{\n\s\spackage\s\=\>\s\'#{pkg}\'\,(.|\n)+?\}\,)/m

  config_txt = File.read("test.txt")

  replace = config_txt.gsub(re, "")

  File.open("test.txt", "w") {|file| file.puts replace}

Thanks for your help folks.

post hole digger fucked around with this message at 19:34 on Nov 2, 2018

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply