Re: [ansible-project] Apply action for each regexp match found on same line

2018-11-13 Thread John Harmon
In case anybody else is looking to do the same thing, here is my BASH 
solution:

- name: Sanitize Virtual Interface(s)
  shell: |
file="/var/ftp/vm.cfg"
total=$( grep ^vif "$file" | grep -o mac | wc -l )
for i in `seq 1 $total`; do
  my_random=$(xxd -l 1 -p /dev/urandom )
  my_random2=$(xxd -l 1 -p /dev/urandom )
  sed -ri 
"s|mac=00:21:f6:((\w{2}(:)?){3})|mac=00:21:f6:aa:${my_random}:${my_random2}|${i}"
 
$file
done


-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/8a24e671-0f09-403b-92ca-0a118b7f4b11%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Apply action for each regexp match found on same line

2018-11-12 Thread Thad Guidry
OK, sounds good, yes a script should do the trick.  You can even write it
in Python and later contribute a nice Ansible module :) :)

Here's inspiration:
https://docs.ansible.com/ansible/latest/modules/list_of_cloud_modules.html#vmware
https://docs.ansible.com/ansible/latest/modules/list_of_cloud_modules.html#misc

https://docs.ansible.com/ansible/latest/modules/ovirt_mac_pool_module.html?highlight=mac
https://docs.ansible.com/ansible/latest/modules/vmware_guest_module.html?highlight=mac

You can click "Edit on Github" in top right corner to get right to the
existing code for those modules.

Thad
+ThadGuidry 


On Mon, Nov 12, 2018 at 10:30 AM John Harmon 
wrote:

>
> On Saturday, November 10, 2018 at 9:48:17 AM UTC-7, Thad Guidry wrote:
>>
>> John,
>>
>> What problem are you actually trying to solve ?  Generating random
>> numbers especially around MAC certainly can get you in trouble.  Are you
>> trying to generate a Pool and apply something 1 time from that Pool ?
>>
>> Explain the use case, and we could help a lot more.
>>
>> -Thad
>>
>>
>  Thad,
> We clone systems in Oracle VM.  There are a handful of steps to clean up
> the vm.cfg from the clone, which has details about the VM.  If you don't
> change the MAC address (for instance), when you bring up the clone it will
> pull the NIC from the live system (one of those wonderful Oracle VM
> features).  I am just trying to take a repetitive process and clean it up
> without direct human intervention.  That will prevent human error (in case
> we miss something) and make it easier.  I have all steps done except this
> one.  If there is just one nic it works fine too, but when testing it out I
> happened to clone a system with 2 nics and I discovered the issue.  I have
> some systems with 3 nics.  I think I will have to script it as Kai said.
>
> I know that messing with NIC MAC addresses can get you in trouble, but
> right now we are just doing the same thing manually.  The clones don't
> usually last that long, and when done they are usually purged.  I don't
> believe any of our current VMs have AA in the fourth octet (and if they did
> I could change it to something else), and then the last 2 octets are
> randomized  chances of hitting an existing MAC are about nil.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-project+unsubscr...@googlegroups.com.
> To post to this group, send email to ansible-project@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/556fe7eb-a3bb-4b1d-8610-d20976131ad0%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAChbWaOrG6qCR%3DXyK7Lw1EO1TvyuB_U5v6xCdf38biTOKB9tKw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Apply action for each regexp match found on same line

2018-11-12 Thread John Harmon

On Saturday, November 10, 2018 at 9:48:17 AM UTC-7, Thad Guidry wrote:
>
> John,
>
> What problem are you actually trying to solve ?  Generating random numbers 
> especially around MAC certainly can get you in trouble.  Are you trying to 
> generate a Pool and apply something 1 time from that Pool ?
>
> Explain the use case, and we could help a lot more.
>
> -Thad
>
>
 Thad,
We clone systems in Oracle VM.  There are a handful of steps to clean up 
the vm.cfg from the clone, which has details about the VM.  If you don't 
change the MAC address (for instance), when you bring up the clone it will 
pull the NIC from the live system (one of those wonderful Oracle VM 
features).  I am just trying to take a repetitive process and clean it up 
without direct human intervention.  That will prevent human error (in case 
we miss something) and make it easier.  I have all steps done except this 
one.  If there is just one nic it works fine too, but when testing it out I 
happened to clone a system with 2 nics and I discovered the issue.  I have 
some systems with 3 nics.  I think I will have to script it as Kai said.

I know that messing with NIC MAC addresses can get you in trouble, but 
right now we are just doing the same thing manually.  The clones don't 
usually last that long, and when done they are usually purged.  I don't 
believe any of our current VMs have AA in the fourth octet (and if they did 
I could change it to something else), and then the last 2 octets are 
randomized  chances of hitting an existing MAC are about nil.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/556fe7eb-a3bb-4b1d-8610-d20976131ad0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Apply action for each regexp match found on same line

2018-11-12 Thread John Harmon


On Saturday, November 10, 2018 at 2:07:52 AM UTC-7, Kai Stian Olstad wrote:
>
> On Wednesday, 7 November 2018 17:36:43 CET John Harmon wrote: 
> > Desired (As shown above, keep first three octets of mac, change 4th to 
> AA, 
> > and the last two are random numbers between 10-99): 
> > vif = ['mac=00:21:f6:AA:21:56,bridge=101498d8ff', 
> > 'mac=00:21:f6:AA:17:27,bridge=1017dc5841'] 
> > 
> > Actual (notice that they are both the same--which is what I don't want) 
> > vif = ['mac=00:21:f6:AA:58:16,bridge=101498d8ff', 
> > 'mac=00:21:f6:AA:58:16,bridge=1017dc5841'] 
> > 
> > As I think about it I don't know of a way to do this within a single 
> task.   
> > Possibly in 2 tasks or more, but that number of vifs will vary from time 
> to 
> > time.  It may be anywhere from 1-5 possibly. 
>
> This isn't easy with Ansible modules so that's probably why you haven't 
> gotten an answer. 
> I probably wont give you one either. 
>
> To get different values you need multiple runs over the file. 
> When you run the fist one it will change all the lines, the same will 
> happened on the second run but with different value but same value on each 
> line. 
> To do this you would need a way to know which line you already changed and 
> then avoid them. 
>
> The best thing in this circumstances is to let Ansible create the file 
> with the template module. 
> Or use some external script like perl, awk, sed or python. 
>
>
> -- 
> Kai Stian Olstad 
>
>
>
Thanks Kai.  I was thinking along those lines.  A template isn't applicable 
in this scenario.  I will just have to go with an outside script. 

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/b7140a69-5ce6-4c1e-8a25-7d0d1d3dc154%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Apply action for each regexp match found on same line

2018-11-10 Thread Thad Guidry
John,

What problem are you actually trying to solve ?  Generating random numbers
especially around MAC certainly can get you in trouble.  Are you trying to
generate a Pool and apply something 1 time from that Pool ?

Explain the use case, and we could help a lot more.

-Thad

On Sat, Nov 10, 2018 at 3:07 AM Kai Stian Olstad <
ansible-project+l...@olstad.com> wrote:

> On Wednesday, 7 November 2018 17:36:43 CET John Harmon wrote:
> > Desired (As shown above, keep first three octets of mac, change 4th to
> AA,
> > and the last two are random numbers between 10-99):
> > vif = ['mac=00:21:f6:AA:21:56,bridge=101498d8ff',
> > 'mac=00:21:f6:AA:17:27,bridge=1017dc5841']
> >
> > Actual (notice that they are both the same--which is what I don't want)
> > vif = ['mac=00:21:f6:AA:58:16,bridge=101498d8ff',
> > 'mac=00:21:f6:AA:58:16,bridge=1017dc5841']
> >
> > As I think about it I don't know of a way to do this within a single
> task.
> > Possibly in 2 tasks or more, but that number of vifs will vary from time
> to
> > time.  It may be anywhere from 1-5 possibly.
>
> This isn't easy with Ansible modules so that's probably why you haven't
> gotten an answer.
> I probably wont give you one either.
>
> To get different values you need multiple runs over the file.
> When you run the fist one it will change all the lines, the same will
> happened on the second run but with different value but same value on each
> line.
> To do this you would need a way to know which line you already changed and
> then avoid them.
>
> The best thing in this circumstances is to let Ansible create the file
> with the template module.
> Or use some external script like perl, awk, sed or python.
>
>
> --
> Kai Stian Olstad
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-project+unsubscr...@googlegroups.com.
> To post to this group, send email to ansible-project@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/118624768.r0sT80IGcL%40x1
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAChbWaNYXAYRRvBm-PXfMq2u5dC7y34gUNmL35s5V69xPN6Wtg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Apply action for each regexp match found on same line

2018-11-10 Thread Kai Stian Olstad
On Wednesday, 7 November 2018 17:36:43 CET John Harmon wrote:
> Desired (As shown above, keep first three octets of mac, change 4th to AA, 
> and the last two are random numbers between 10-99):
> vif = ['mac=00:21:f6:AA:21:56,bridge=101498d8ff', 
> 'mac=00:21:f6:AA:17:27,bridge=1017dc5841']
> 
> Actual (notice that they are both the same--which is what I don't want)
> vif = ['mac=00:21:f6:AA:58:16,bridge=101498d8ff', 
> 'mac=00:21:f6:AA:58:16,bridge=1017dc5841']
> 
> As I think about it I don't know of a way to do this within a single task.  
> Possibly in 2 tasks or more, but that number of vifs will vary from time to 
> time.  It may be anywhere from 1-5 possibly.

This isn't easy with Ansible modules so that's probably why you haven't gotten 
an answer.
I probably wont give you one either.

To get different values you need multiple runs over the file.
When you run the fist one it will change all the lines, the same will happened 
on the second run but with different value but same value on each line.
To do this you would need a way to know which line you already changed and then 
avoid them.

The best thing in this circumstances is to let Ansible create the file with the 
template module.
Or use some external script like perl, awk, sed or python.


-- 
Kai Stian Olstad


-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/118624768.r0sT80IGcL%40x1.
For more options, visit https://groups.google.com/d/optout.