Re: [ansible-project] how to parse variable in patterns by find module

2023-03-13 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
- name: look for backup files

  find:

paths: /tmp

recurse: false

file_type: 'file'

patterns: '^{{ item.filename }}\.[0-9]{6}.*$'

use_regex: true

  loop: ['backup']

  register: found


- name: get list of files

  set_fact:

files: "{{ found.results | json_query('[*].files[*][]') }}"


- name: show list of files

  debug: var=item.path

  loop: "{{ files }}"


Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

On Mar 13, 2023, at 1:11 PM, 'Rowe, Walter P. (Fed)' via Ansible Project 
 wrote:

You are not registering the product of the task.

find:
  paths: /tmp
  recurse: false
  file_type_ file
  patterns: '^{{ item.filename }}\.[0-9]{6}.*$'
  use_regex: yes
loop: {{ file }}
register: found

You then need to look at found.files (a list) to see what is found. This is 
documented in the ansible find module.

Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

On Mar 13, 2023, at 12:39 PM, Hiero-nymo  wrote:

Hi everyone,

I've tried to using a variable in find module by pattern by it doesn't seems to 
work. Here's below a example. I also looked at another solution with set_facts 
but I doesn't run too.
I want to list all the backup files in a directory. The files have a timestamp 
and it's filename will be defined by variable.
Does anyone have an idea how should I proceed? or in which way?

Thanks in advance for your help

Here's the variables:
---
file:
  - filename: backup
state: present
[...]

Here's the task:
---
[...]
find:
  paths: /tmp
  recurse: false
  file_type_ file
  patterns: '^{{ item.filename }}\.[0-9]{6}.*$'
  use_regex: yes
loop: {{ file }}

--
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/3419395b-36b0-4195-9278-de959fa763can%40googlegroups.com.


--
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/7E9B8E33-5171-4B7B-80D0-8AAEEA6A7E44%40nist.gov.

-- 
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/D7179F38-74CE-4A16-B296-60874B87A5AF%40nist.gov.


Re: [ansible-project] how to parse variable in patterns by find module

2023-03-13 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
You are not registering the product of the task.

find:
  paths: /tmp
  recurse: false
  file_type_ file
  patterns: '^{{ item.filename }}\.[0-9]{6}.*$'
  use_regex: yes
loop: {{ file }}
register: found

You then need to look at found.files (a list) to see what is found. This is 
documented in the ansible find module.

Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

On Mar 13, 2023, at 12:39 PM, Hiero-nymo  wrote:

Hi everyone,

I've tried to using a variable in find module by pattern by it doesn't seems to 
work. Here's below a example. I also looked at another solution with set_facts 
but I doesn't run too.
I want to list all the backup files in a directory. The files have a timestamp 
and it's filename will be defined by variable.
Does anyone have an idea how should I proceed? or in which way?

Thanks in advance for your help

Here's the variables:
---
file:
  - filename: backup
state: present
[...]

Here's the task:
---
[...]
find:
  paths: /tmp
  recurse: false
  file_type_ file
  patterns: '^{{ item.filename }}\.[0-9]{6}.*$'
  use_regex: yes
loop: {{ file }}

--
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/3419395b-36b0-4195-9278-de959fa763can%40googlegroups.com.

-- 
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/7E9B8E33-5171-4B7B-80D0-8AAEEA6A7E44%40nist.gov.


Re: [ansible-project] how to parse variable in patterns by find module

2023-03-13 Thread Stefan Hornburg (Racke)

On 13/03/2023 17:39, Hiero-nymo wrote:

Hi everyone,

I've tried to using a variable in find module by pattern by it doesn't seems to 
work. Here's below a example. I also looked at another solution with set_facts 
but I doesn't run too.
I want to list all the backup files in a directory. The files have a timestamp 
and it's filename will be defined by variable.
Does anyone have an idea how should I proceed? or in which way?

Thanks in advance for your help

Here's the variables:
---
file:
   - filename: backup
     state: present
[...]

Here's the task:
---
[...]
find:
   paths: /tmp
   recurse: false
   file_type_ file
   patterns: '^{{ item.filename }}\.[0-9]{6}.*$'
   use_regex: yes
loop: {{ file }}



Hello, you need to quote the argument for the loop:

  loop: '{{ file }}'

Regards
  Racke


--
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/3419395b-36b0-4195-9278-de959fa763can%40googlegroups.com
 
.


--
Automation expert - Ansible and friends
Linux administrator & Debian maintainer
Perl Dancer & conference hopper


--
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/c3f29330-5459-ea46-c912-eee5ed0c0eb3%40linuxia.de.


[ansible-project] how to parse variable in patterns by find module

2023-03-13 Thread Hiero-nymo
Hi everyone,

I've tried to using a variable in find module by pattern by it doesn't 
seems to work. Here's below a example. I also looked at another solution 
with set_facts but I doesn't run too.
I want to list all the backup files in a directory. The files have a 
timestamp and it's filename will be defined by variable.
Does anyone have an idea how should I proceed? or in which way?

Thanks in advance for your help

Here's the variables:
---
file:
  - filename: backup
state: present
[...]

Here's the task:
---
[...]
find:
  paths: /tmp
  recurse: false
  file_type_ file
  patterns: '^{{ item.filename }}\.[0-9]{6}.*$'
  use_regex: yes
loop: {{ file }}

-- 
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/3419395b-36b0-4195-9278-de959fa763can%40googlegroups.com.


Re: [ansible-project] 'dict object' has no attribute 'stdout'

2023-03-13 Thread Todd Lewis
D'oh! Test one thing and post something else. *Argh!*
How about this:

- name: Save output to file
  ansible.builtin.copy:
 content: |
   {{ output.stdout_lines[0:1] | join('\n') }}
 dest: "show-output/{{ inventory_hostname }}.ios"
  when output.stdout_lines is defined 

On Monday, March 13, 2023 at 11:36:25 AM UTC-4 Todd Lewis wrote:

> - name: Save output to file
>   ansible.builtin.copy:
> content: |-
>   {{ '\n'.join(output.stdout_lines[0:1]) }}
> dest: "show-output/{{ inventory_hostname }}.ios"
>   when output.stdout_lines is defined
>
>
>
> On 3/13/23 11:13 AM, Merlijn De Wandel wrote:
>
> Hi We have the following working config down below. However sometimes the 
> routers don't have the command "sh ip ospf nei" and we get the following 
> error: 
> FAILED! => {"msg": "The task includes an option with an undefined 
> variable. The error was: 'dict object' has no attribute 'stdout'\n\nThe 
> error appears to be in 
> '/etc/ansible/playbooks/ShowCommandsRunAndIpOspfNei.yaml': line 15, column 
> 7, but may\nbe elsewhere in the file depending on the exact syntax 
> problem.\n\nThe offending line appears to be:\n\n\n - name: Save output to 
> file\n ^ here\n"} 
> We would like to get the show run from all routers and sh ip ospf nei from 
> the routers who have it.
> --- - name: Show run and sh ip ospf nei hosts: Test gather_facts: false 
> tasks: - name: Show Commands ignore_errors: true ios_command: commands: - 
> sh run - sh ip ospf nei register: output - name: Save output to file copy: 
> content: |- {% if output.stdout_lines[1] is defined %} {{ output.stdout[0] 
> | replace('\\n', '\n') }} 
> {{ output.stdout[1] | replace('\\n', '\n') }} {% else %} {{ 
> output.stdout[0] | replace('\\n', '\n') }} {% endif %} dest: 
> "show-output/{{ inventory_hostname }}.ios"
>
> -- 
> 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-proje...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/c7df6afd-61c9-46e2-8b0f-519d9200c192n%40googlegroups.com
>  
> 
> .
>
>
> -- 
> Todd
>
>

-- 
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/d29b85d1-95e5-4ba2-a0ed-b48a74a139ccn%40googlegroups.com.


Re: [ansible-project] 'dict object' has no attribute 'stdout'

2023-03-13 Thread Todd Lewis

- name: Save output to file
  ansible.builtin.copy:
    content: |-
      {{ '\n'.join(output.stdout_lines[0:1]) }}
dest: "show-output/{{ inventory_hostname }}.ios"
  when output.stdout_lines is defined


On 3/13/23 11:13 AM, Merlijn De Wandel wrote:
Hi We have the following working config down below. However sometimes 
the routers don't have the command "sh ip ospf nei" and we get the 
following error:
FAILED! => {"msg": "The task includes an option with an undefined 
variable. The error was: 'dict object' has no attribute 
'stdout'\n\nThe error appears to be in 
'/etc/ansible/playbooks/ShowCommandsRunAndIpOspfNei.yaml': line 15, 
column 7, but may\nbe elsewhere in the file depending on the exact 
syntax problem.\n\nThe offending line appears to be:\n\n\n - name: 
Save output to file\n ^ here\n"}
We would like to get the show run from all routers and sh ip ospf nei 
from the routers who have it.
--- - name: Show run and sh ip ospf nei hosts: Test gather_facts: 
false tasks: - name: Show Commands ignore_errors: true ios_command: 
commands: - sh run - sh ip ospf nei register: output - name: Save 
output to file copy: content: |- {% if output.stdout_lines[1] is 
defined %} {{ output.stdout[0] | replace('\\n', '\n') }}
{{ output.stdout[1] | replace('\\n', '\n') }} {% else %} {{ 
output.stdout[0] | replace('\\n', '\n') }} {% endif %} dest: 
"show-output/{{ inventory_hostname }}.ios"

--
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/c7df6afd-61c9-46e2-8b0f-519d9200c192n%40googlegroups.com 
.


--
Todd

--
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/da48fc49-95e4-e272-e325-251ea3776e14%40gmail.com.


[ansible-project] 'dict object' has no attribute 'stdout'

2023-03-13 Thread Merlijn De Wandel
Hi We have the following working config down below. However sometimes the 
routers don't have the command "sh ip ospf nei" and we get the following 
error:
FAILED! => {"msg": "The task includes an option with an undefined variable. 
The error was: 'dict object' has no attribute 'stdout'\n\nThe error appears 
to be in '/etc/ansible/playbooks/ShowCommandsRunAndIpOspfNei.yaml': line 
15, column 7, but may\nbe elsewhere in the file depending on the exact 
syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Save 
output to file\n ^ here\n"}

We would like to get the show run from all routers and sh ip ospf nei from 
the routers who have it.
--- - name: Show run and sh ip ospf nei hosts: Test gather_facts: false 
tasks: - name: Show Commands ignore_errors: true ios_command: commands: - 
sh run - sh ip ospf nei register: output - name: Save output to file copy: 
content: |- {% if output.stdout_lines[1] is defined %} {{ output.stdout[0] 
| replace('\\n', '\n') }} 
{{ output.stdout[1] | replace('\\n', '\n') }} {% else %} {{ 
output.stdout[0] | replace('\\n', '\n') }} {% endif %} dest: 
"show-output/{{ inventory_hostname }}.ios"

-- 
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/c7df6afd-61c9-46e2-8b0f-519d9200c192n%40googlegroups.com.


Re: [ansible-project] Vmware.Collection: vmware_guest_snapshot setting expiration

2023-03-13 Thread Stefan Coussens
I don't know if you use tower but what I do is take a snapshot named
"snapshot by ansible" and  for the removal I use the absent parameter
(state: absent) and schedule the playbook to run at a certain time.



On Sun, Mar 12, 2023 at 11:00 PM kyle jones 
wrote:

> Hello,
>
> Does anyone have any documentation or know what parameters to use when
> using vmware_guest_snapshot to take snapshot, but adding an expiration
> period?
>
> I looked over the ansible docs a few times and I did not see it.
>
>
> --
> 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/ed094263-70fd-49c7-b140-7dfc408f3239n%40googlegroups.com
> 
> .
>

-- 
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/CAPMYB%3D2%3DKSf1YTTX3RwJUeni95zYbKdi0rd-SADHXiV27GsO_g%40mail.gmail.com.