[ansible-project] Re: Looping through a dictionary to create links

2019-07-28 Thread Aaron Hicks
Well, I have a solution but it's very 
https://www.goodreads.com/quotes/7053458-but-i-am-very-poorly-today-very-stupid

I've had to restructure the inventory:

all:
  vars:
filesystems:
  - path: /sharedfs1
links:
  - src: /sharedfs1/filesets/home
dest: /home
  - src: /sharedfs1/filesets/foo
dest: /opt/foo
  - src: /sharedfs1/filesets/baa
dest: /opt/baa
  - src: /sharedfs1/filesets/lmod
dest: /opt/lmod
  - src: /sharedfs1/filesets/baz
dest: /quack/baz
  - path: /sharedfs2
links:
  - src: /sharedfs2/filesets/nobackup
dest: /quack/nobackup
  - path: /sharefds3
  - path: /sharedfs4
  children:
hostlist:
  hosts:
host1:
host2:

And then the playbook looks like, which does a bit more should/shouldn't 
testing than initially asked for

---
- name: Create links to filesets from GPFS filesystems
  hosts: all
  vars:
ansible_become_user: root
ansible_become_method: sudo
  tasks:
- name: Check which Spectrum Scale filesystems are mounted
  stat:
path: "{{ item.path }}"
  register: fsstat
  loop: "{{ filesystems }}"

# It should be possible to remove this debug and use the filter directly
- name: Which filesystem mount exists?
  debug:
msg: "src: {{ item.0.1.src }} dest:{{ item.0.1.dest }}"
  register: linkslist
  when:
- item.1.stat.exists
- item.1.stat.path == item.0.0.path
  loop: "{{ filesystems|subelements('links', 
skip_missing=True)|product(fsstat.results)|list }}"

- name: Stat filesystem link destinations
  stat:
path: "{{ item.item.0.1.dest }}"
  become: true
  register: linksstat
  when:
- item is not skipped
  loop: "{{ linkslist.results }}"

- name: Remove link destintations (if not a link)
  file:
   path: "{{ item.stat.path }}"
   state: absent
  become: true
  when:
- item is not skipped
- item.stat.isdir is defined
- item.stat.isdir
  loop: "{{ linksstat.results }}"

- name: Check link destination parent directories
  file:
path: "{{ item.item.0.1.dest | dirname }}"
state: directory
  become: true
  when:
- item is not skipped
- item.item.0.1.dest | dirname is not match("/")
  loop: "{{ linkslist.results }}"

- name: Create Scale filesystem links
  file:
src: "{{ item.item.0.1.src }}"
dest: "{{ item.item.0.1.dest }}"
state: link
  become: true
  when:
- item is not skipped
  loop: "{{ linkslist.results }}"



On Friday, July 26, 2019 at 3:44:27 PM UTC+12, Aaron Hicks wrote:
>
> The Python equivalent I'm trying to make is:
>
> for sharedfs in filesystems:
> if os.path.exists(sharedfs):
> for link in filesystems[sharedfs]:
> os.symlink(link['source']. link['target'])
>
>
> On Friday, July 26, 2019 at 3:37:07 PM UTC+12, Aaron Hicks wrote:
>>
>> Hello the list,
>>
>> I have  a bunch of machines with some shared file systems. Some of the 
>> file systems are not mounted on all the machines. For the filesystems that 
>> are mounted, I'd like to check/create a bunch of symbolic links to those 
>> filesystems from various places in the filesystem. Some filesystems do not 
>> have links (yet) but we may do some other things with them later.
>>
>> So given a YAML inventory file:
>>
>> all:
>>   vars:
>> filesystems:
>>   /sharedfs1:
>> - source: /sharedfs1/filesets/home
>>   target: /home
>> - source: /sharedfs1/filesets/foo
>>   target: /opt/foo
>> - source: /sharedfs1/filesets/baa
>>   target: /opt/baa
>> - source: /sharedfs1/filesets/lmod
>>   target: /opt/lmod
>> - source: /scale_wlg_persistent/filesets/baz
>>   target: /quack/baz
>>  /sharedfs2:
>> - source: /sharedfs2/filesets/scratch
>>   target: /quack/scratch
>>   /sharedfs3:
>>   /sharedfs4:
>>   children:
>> hostlist:
>>   hosts:
>> host1:
>> host2:
>>
>> And the following play, which checks the mount point exists
>>
>> ---
>> - name: Create links to filesets from shared filesystems
>>   hosts: all
>>   tasks:
>> - name: Check filesystems are mounted
>>   stat:
>> path: "{{ item.key }}"
>>   register: fsstat
>

Re: [ansible-project] Send playbook output to Logstash/Elasticsearch

2019-07-25 Thread Aaron Hicks
Late to the game, but this is the best ranked answer so far: Is there a 
callback that logs _directly_ to ElasticSearch without logstash?

On Saturday, January 28, 2017 at 9:06:10 AM UTC+13, Ievgen Khmelenko wrote:
>
> Try to use the new version 
> https://github.com/ujenmr/ansible-logstash-callback
>
> On Thursday, January 26, 2017 at 11:13:53 PM UTC+2, Ievgen Khmelenko wrote:
>>
>> Hi,
>>
>> I'm author of the module, I can fix it. I will return with result...
>>
>> Ievgen
>>
>> On Wednesday, January 18, 2017 at 1:20:20 PM UTC+2, dubravko sever wrote:
>>>
>>> Hi,
>>>
>>> Using given callback I'm able to log events from ansible to 
>>> logstash/elastic search. But can't search ansible_result field because it 
>>> represent field as string, for instance:
>>> "{"changed":"false", "msg":"some message"}".
>>>
>>>
>>> In ELK I'm trying to get format like this one
>>>
>>>  "ansible_result":{
>>>
>>>
>>>
>>>
>>>
>>> Any ideas how to resolve this issue?
>>>
>>> Dubravko
>>>
>>>
>>>
>>> On Saturday, December 17, 2016 at 8:22:30 PM UTC+1, dubravko sever wrote:

 Hi,

 Exactly I've been looking for, if it collects json results from ansible 
 (will test it)

 Thanks
 Dubravko

 On Saturday, December 17, 2016 at 7:15:05 PM UTC+1, Gabriel Rosca wrote:
>
> What about the callback module :) 
>
>
> https://github.com/ujenmr/ansible-logstash-callback/blob/master/README.md
>
> Regards,
> Gabriel
>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/e2b9b513-e896-40eb-b0a3-a29bda19d67e%40googlegroups.com.


[ansible-project] Re: Looping through a dictionary to create links

2019-07-25 Thread Aaron Hicks
The Python equivalent I'm trying to make is:

for sharedfs in filesystems:
if os.path.exists(sharedfs):
for link in filesystems[sharedfs]:
os.symlink(link['source']. link['target'])


On Friday, July 26, 2019 at 3:37:07 PM UTC+12, Aaron Hicks wrote:
>
> Hello the list,
>
> I have  a bunch of machines with some shared file systems. Some of the 
> file systems are not mounted on all the machines. For the filesystems that 
> are mounted, I'd like to check/create a bunch of symbolic links to those 
> filesystems from various places in the filesystem. Some filesystems do not 
> have links (yet) but we may do some other things with them later.
>
> So given a YAML inventory file:
>
> all:
>   vars:
> filesystems:
>   /sharedfs1:
> - source: /sharedfs1/filesets/home
>   target: /home
> - source: /sharedfs1/filesets/foo
>   target: /opt/foo
> - source: /sharedfs1/filesets/baa
>   target: /opt/baa
> - source: /sharedfs1/filesets/lmod
>   target: /opt/lmod
> - source: /scale_wlg_persistent/filesets/baz
>   target: /quack/baz
>  /sharedfs2:
> - source: /sharedfs2/filesets/scratch
>   target: /quack/scratch
>   /sharedfs3:
>   /sharedfs4:
>   children:
> hostlist:
>   hosts:
> host1:
> host2:
>
> And the following play, which checks the mount point exists
>
> ---
> - name: Create links to filesets from shared filesystems
>   hosts: all
>   tasks:
> - name: Check filesystems are mounted
>   stat:
> path: "{{ item.key }}"
>   register: fsstat
>   loop: "{{ filesystems|dict2items }}"
>
> - name: Which filesystem mount exists?
>   debug:
> var: fsstat.stat.path
>   when: item.0.stat.path == item.1.key
>   loop: "{{ fsstat.results|product(filesystems|dict2items)|list }}"
>
> Now what I want to do for each filesystem mount that exists, I'd like to 
> create a link from source to target for each list of link hashes associated 
> with each filesystem. Doing this in Python is almost trivial, but a massive 
> pain in Ansible/Jinja2
>
> Regards,
>
> Aaron
>
>
>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/aa117a6e-c9cb-4030-884d-63c640ffb439%40googlegroups.com.


[ansible-project] Looping through a dictionary to create links

2019-07-25 Thread Aaron Hicks
Hello the list,

I have  a bunch of machines with some shared file systems. Some of the file 
systems are not mounted on all the machines. For the filesystems that are 
mounted, I'd like to check/create a bunch of symbolic links to those 
filesystems from various places in the filesystem. Some filesystems do not 
have links (yet) but we may do some other things with them later.

So given a YAML inventory file:

all:
  vars:
filesystems:
  /sharedfs1:
- source: /sharedfs1/filesets/home
  target: /home
- source: /sharedfs1/filesets/foo
  target: /opt/foo
- source: /sharedfs1/filesets/baa
  target: /opt/baa
- source: /sharedfs1/filesets/lmod
  target: /opt/lmod
- source: /scale_wlg_persistent/filesets/baz
  target: /quack/baz
 /sharedfs2:
- source: /sharedfs2/filesets/scratch
  target: /quack/scratch
  /sharedfs3:
  /sharedfs4:
  children:
hostlist:
  hosts:
host1:
host2:

And the following play, which checks the mount point exists

---
- name: Create links to filesets from shared filesystems
  hosts: all
  tasks:
- name: Check filesystems are mounted
  stat:
path: "{{ item.key }}"
  register: fsstat
  loop: "{{ filesystems|dict2items }}"

- name: Which filesystem mount exists?
  debug:
var: fsstat.stat.path
  when: item.0.stat.path == item.1.key
  loop: "{{ fsstat.results|product(filesystems|dict2items)|list }}"

Now what I want to do for each filesystem mount that exists, I'd like to 
create a link from source to target for each list of link hashes associated 
with each filesystem. Doing this in Python is almost trivial, but a massive 
pain in Ansible/Jinja2

Regards,

Aaron



-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/f4f54a75-30c8-4b0d-9ede-79400db6ac96%40googlegroups.com.