Re: [ansible-project] change of parsing of values? (in ansible.cfg)

2024-01-10 Thread Adrian Sevcenco

On 08.01.2024 21:26, Brian Coca wrote:

sorry, yes, that pr above broke it, this one should fix it
https://github.com/ansible/ansible/pull/82388

my brain just came back from vacation and reminded me 


Thanks a lot for info! I closed the community.general issue
with your information!

I'm not sure from the code of the fix: at this moment i made the things work
by removing quotes, after the fix will be apply, should i expect any kind of 
breakage
because of lack of quotes?

Thanks a lot!
Adrian

--
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/901b8a9a-4ac5-440e-846f-f3072037eeb5%40gmail.com.


Re: [ansible-project] Trying to replace single quote with regex_replace

2024-01-10 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
Even better! Brilliant!

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

On Jan 10, 2024, at 12:16 PM, Vladimir Botka  wrote:

"['/First Datacenter/vm/Prod-SRM']"
The problem is [' and ']. They can't be part pf the folder name.

FWIW, convert the string to a list

s: "['/First Datacenter/vm/Prod-SRM']"
l: "{{ s|from_yaml }}"

gives

l.0: /First Datacenter/vm/Prod-SRM

--
Vladimir Botka

--
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/20240110181644.79b47b90%40gmail.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/DFDE8949-FE3F-4DB7-AE58-41247AB0D056%40nist.gov.


Re: [ansible-project] Trying to replace single quote with regex_replace

2024-01-10 Thread Vladimir Botka
> "['/First Datacenter/vm/Prod-SRM']"
> The problem is [' and ']. They can't be part pf the folder name.

FWIW, convert the string to a list

s: "['/First Datacenter/vm/Prod-SRM']"
l: "{{ s|from_yaml }}"

gives

l.0: /First Datacenter/vm/Prod-SRM

--
Vladimir Botka

-- 
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/20240110181644.79b47b90%40gmail.com.


pgp3_W1RyRRlt.pgp
Description: OpenPGP digital signature


Re: [ansible-project] Trying to replace single quote with regex_replace

2024-01-10 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
In plain terms it is really this:

[[]']

The outside square brackets define a character set. The characters in between 
mean "any of these".

Since square brackets define a character set we have to escape the inside 
square brackets to be see as characters in the set.

[\[\]']

Since this is ansible we have to escape the backslashes.

[\\[\\]']

You could place any characters in that set. The regex matches *any* of them any 
number of times.

For example I could use [walter] and it would look for any of those characters.

You also can use ranges like [a-dv-z]. This all follows Python regex rules.

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

On Jan 10, 2024, at 11:03 AM, Dimitri Yioulos  wrote:

Walter, to further my knowledge, would you mind explaining further what this 
regex  \"([\\[\\]'])\",'  does? Is the regex specifi to regex_replace?

On Wednesday, January 10, 2024 at 10:33:53 AM UTC-5 Dimitri Yioulos wrote:
Walter, that worked, and thanks so much! I both appreciate the regex solution, 
and it simplification. I also probably be able to reuse this, with some 
modifications, depending on what I'm trying to accomplish. Double win. Thanks 
again!

On Wednesday, January 10, 2024 at 10:14:32 AM UTC-5 Rowe, Walter P. (Fed) wrote:
This works.

regex_replace(\"([\\[\\]'])\",'')

Escaping the double quotes that define the search regex gets around needing to 
escape the single quote. Also note that I collapsed your search into a single 
character set.

---
- name: test
  hosts: localhost
  become: false
  gather_facts: false
  vars:
mystr: "['/First Datacenter/vm/Prod-SRM']"
  tasks:
- debug: msg="{{ mystr | regex_replace(\"([\\[\\]'])\",'') }}"


% ansible-playbook -i localhost, foo.yml

PLAY [test] 


TASK [debug] 
***
ok: [localhost] => {
"msg": "/First Datacenter/vm/Prod-SRM"
}

PLAY RECAP 
*
localhost  : ok=1changed=0unreachable=0failed=0
skipped=0rescued=0ignored=0

The solution was found on this stack overflow page.

https://stackoverflow.com/questions/52495838/ansible-remove-the-single-quote-character-from-a-string

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

On Jan 10, 2024, at 9:27 AM, Rowe, Walter P. (Fed)  wrote:

Have you tried:

regex_replace('(\\[)|(\\])|(\\')', '')

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

On Jan 10, 2024, at 9:08 AM, Dimitri Yioulos  wrote:

Hello, all.

I'm working with VMware modules in removing snapshots across all vCenter 
folders. In order for this to work, I first have to get the folders in which 
the virtual machines live. Here's the playbook:

---

- hosts: all
  become: false
  gather_facts: false

  vars_prompt:

- name: "vcenter_username"
  prompt: "Enter your Vcenter username"
  private: no
- name: "vcenter_password"
  prompt: "Enter your VMware password"
  private: yes

  vars:
vcenter_hostname: vcenter1.mycompany.com
vcenter_datacenter: First Datacenter

  tasks:

- name: Find virtual machine's folder name
  vmware_guest_find:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
name: "{{ inventory_hostname }}"
validate_certs: False
  delegate_to: localhost
  ignore_errors: true
  register: vm_facts
  tags:
- folder

- name: Show folders
  ansible.builtin.debug:
msg: "{{ vm_facts.folders }}"
  tags:
- folder

- name: Remove all snapshots of a VM
  community.vmware.vmware_guest_snapshot:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter: "{{ vcenter_datacenter }}"
folder: "{{ vm_facts.folders | regex_replace('(\\[)|(\\])',  '') }}"
name: "{{ inventory_hostname }}"
state: remove_all
validate_certs: False
  delegate_to: localhost

Previous to my having employed regex_replace, this is the output I'd get, e.g., 
for a vm's folder:

"['/First Datacenter/vm/Prod-SRM']"

The problem with that is [' and ']. They can't be part pf the folder name. 
After employing regex-replace, the output is:

" '/Bedford Datacenter/vm/Bedford-Prod-SRM' "

Try as I may, I've not been able to find a way to also remove the single quotes 
(the double quotes can remain). I've tried appending to the regex_replace, but 
every piece of code i've used has failed.

regex_replace('(\\[)|(\\])'|(addlcodehere),  '') }}

Your kinf 

Re: [ansible-project] Trying to replace single quote with regex_replace

2024-01-10 Thread Dimitri Yioulos
Walter, to further my knowledge, would you mind explaining further what 
this regex  \"([\\[\\]'])\",'  does? Is the regex specifi to regex_replace?

On Wednesday, January 10, 2024 at 10:33:53 AM UTC-5 Dimitri Yioulos wrote:

> Walter, that worked, and thanks so much! I both appreciate the regex 
> solution, and it simplification. I also probably be able to reuse this, 
> with some modifications, depending on what I'm trying to accomplish. Double 
> win. Thanks again!
>
> On Wednesday, January 10, 2024 at 10:14:32 AM UTC-5 Rowe, Walter P. (Fed) 
> wrote:
>
>> This works. 
>>
>> regex_replace(\"([\\[\\]'])\",'')
>>
>> Escaping the double quotes that define the search regex gets around 
>> needing to escape the single quote. Also note that I collapsed your search 
>> into a single character set.
>>
>> ---
>>
>> - name: test
>>
>>   hosts: localhost
>>
>>   become: false
>>
>>   gather_facts: false
>>
>>   vars:
>>
>> mystr: "['/First Datacenter/vm/Prod-SRM']"
>>
>>   tasks:
>>
>> - debug: msg="{{ mystr | regex_replace(\"([\\[\\]'])\",'') }}"
>>
>>
>> *% ansible-playbook -i localhost, foo.yml*
>>
>>
>> PLAY [test] 
>> 
>>
>>
>> TASK [debug] 
>> ***
>>
>> ok: [localhost] => {
>>
>> "msg": "/First Datacenter/vm/Prod-SRM"
>>
>> }
>>
>>
>> PLAY RECAP 
>> *
>>
>> localhost  : ok=1changed=0unreachable=0
>> failed=0skipped=0rescued=0ignored=0   
>>
>> The solution was found on this stack overflow page.
>>
>>
>> https://stackoverflow.com/questions/52495838/ansible-remove-the-single-quote-character-from-a-string
>>
>> Walter
>> --
>> Walter Rowe, Division Chief
>> Infrastructure Services Division
>> Mobile: 202.355.4123 <(202)%20355-4123> 
>>
>> On Jan 10, 2024, at 9:27 AM, Rowe, Walter P. (Fed)  
>> wrote:
>>
>> Have you tried: 
>>
>> *regex_replace('(\\[)|(\\])**|(\\')**', '')*
>>
>> Walter
>> --
>> Walter Rowe, Division Chief
>> Infrastructure Services Division
>> Mobile: 202.355.4123 <(202)%20355-4123> 
>>
>> On Jan 10, 2024, at 9:08 AM, Dimitri Yioulos  wrote:
>>
>> Hello, all. 
>>
>> I'm working with VMware modules in removing snapshots across all vCenter 
>> folders. In order for this to work, I first have to get the folders in 
>> which the virtual machines live. Here's the playbook:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> *--- - hosts: all   become: false   gather_facts: false   vars_prompt:   
>>   - name: "vcenter_username"   prompt: "Enter your Vcenter username"   
>> private: no - name: "vcenter_password"   prompt: "Enter your 
>> VMware password"   private: yes   vars: vcenter_hostname: 
>> vcenter1.mycompany.com  
>> vcenter_datacenter: First Datacenter   tasks: - name: Find virtual 
>> machine's folder name   vmware_guest_find: hostname: "{{ 
>> vcenter_hostname }}" username: "{{ vcenter_username }}" 
>> password: "{{ vcenter_password }}" name: "{{ inventory_hostname }}" 
>> validate_certs: False   delegate_to: localhost   
>> ignore_errors: true   register: vm_facts   tags: *
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> *- folder - name: Show folders   ansible.builtin.debug:   
>>   msg: "{{ vm_facts.folders }}"   tags: - folder - 
>> name: Remove all snapshots of a VM   
>> community.vmware.vmware_guest_snapshot: hostname: "{{ 
>> vcenter_hostname }}" username: "{{ vcenter_username }}" 
>> password: "{{ vcenter_password }}" datacenter: "{{ 
>> vcenter_datacenter }}" folder: "{{ vm_facts.folders | 
>> regex_replace('(\\[)|(\\])',  '') }}" name: "{{ inventory_hostname 
>> }}" state: remove_all validate_certs: False   
>> delegate_to: localhost*
>>
>> Previous to my having employed regex_replace, this is the output I'd get, 
>> e.g., for a vm's folder:
>>
>> *"['/First Datacenter/vm/Prod-SRM']"*
>>
>> The problem with that is *['* and *']*. They can't be part pf the folder 
>> name. After employing regex-replace, the output is:
>>
>> *" '/Bedford Datacenter/vm/Bedford-Prod-SRM' "*
>>
>> Try as I may, I've not been able to find a way to also remove the single 
>> quotes (the double quotes can remain). I've tried appending to the 
>> regex_replace, but every piece of code i've used has failed.
>>
>> *regex_replace('(\\[)|(\\])'|(addlcodehere),  '') }}*
>>
>> Your kinf assistance requested.
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Ansible Project" group.
>> To unsubscribe from this group and 

Re: [ansible-project] Trying to replace single quote with regex_replace

2024-01-10 Thread Dimitri Yioulos
Walter, that worked, and thanks so much! I both appreciate the regex 
solution, and it simplification. I also probably be able to reuse this, 
with some modifications, depending on what I'm trying to accomplish. Double 
win. Thanks again!

On Wednesday, January 10, 2024 at 10:14:32 AM UTC-5 Rowe, Walter P. (Fed) 
wrote:

> This works. 
>
> regex_replace(\"([\\[\\]'])\",'')
>
> Escaping the double quotes that define the search regex gets around 
> needing to escape the single quote. Also note that I collapsed your search 
> into a single character set.
>
> ---
>
> - name: test
>
>   hosts: localhost
>
>   become: false
>
>   gather_facts: false
>
>   vars:
>
> mystr: "['/First Datacenter/vm/Prod-SRM']"
>
>   tasks:
>
> - debug: msg="{{ mystr | regex_replace(\"([\\[\\]'])\",'') }}"
>
>
> *% ansible-playbook -i localhost, foo.yml*
>
>
> PLAY [test] 
> 
>
>
> TASK [debug] 
> ***
>
> ok: [localhost] => {
>
> "msg": "/First Datacenter/vm/Prod-SRM"
>
> }
>
>
> PLAY RECAP 
> *
>
> localhost  : ok=1changed=0unreachable=0
> failed=0skipped=0rescued=0ignored=0   
>
> The solution was found on this stack overflow page.
>
>
> https://stackoverflow.com/questions/52495838/ansible-remove-the-single-quote-character-from-a-string
>
> Walter
> --
> Walter Rowe, Division Chief
> Infrastructure Services Division
> Mobile: 202.355.4123 <(202)%20355-4123> 
>
> On Jan 10, 2024, at 9:27 AM, Rowe, Walter P. (Fed)  
> wrote:
>
> Have you tried: 
>
> *regex_replace('(\\[)|(\\])**|(\\')**', '')*
>
> Walter
> --
> Walter Rowe, Division Chief
> Infrastructure Services Division
> Mobile: 202.355.4123 <(202)%20355-4123> 
>
> On Jan 10, 2024, at 9:08 AM, Dimitri Yioulos  wrote:
>
> Hello, all. 
>
> I'm working with VMware modules in removing snapshots across all vCenter 
> folders. In order for this to work, I first have to get the folders in 
> which the virtual machines live. Here's the playbook:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *--- - hosts: all   become: false   gather_facts: false   vars_prompt: 
> - name: "vcenter_username"   prompt: "Enter your Vcenter username" 
>   private: no - name: "vcenter_password"   prompt: "Enter your 
> VMware password"   private: yes   vars: vcenter_hostname: 
> vcenter1.mycompany.com  
> vcenter_datacenter: First Datacenter   tasks: - name: Find virtual 
> machine's folder name   vmware_guest_find: hostname: "{{ 
> vcenter_hostname }}" username: "{{ vcenter_username }}" 
> password: "{{ vcenter_password }}" name: "{{ inventory_hostname }}" 
> validate_certs: False   delegate_to: localhost   
> ignore_errors: true   register: vm_facts   tags: *
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *- folder - name: Show folders   ansible.builtin.debug:   
>   msg: "{{ vm_facts.folders }}"   tags: - folder - 
> name: Remove all snapshots of a VM   
> community.vmware.vmware_guest_snapshot: hostname: "{{ 
> vcenter_hostname }}" username: "{{ vcenter_username }}" 
> password: "{{ vcenter_password }}" datacenter: "{{ 
> vcenter_datacenter }}" folder: "{{ vm_facts.folders | 
> regex_replace('(\\[)|(\\])',  '') }}" name: "{{ inventory_hostname 
> }}" state: remove_all validate_certs: False   
> delegate_to: localhost*
>
> Previous to my having employed regex_replace, this is the output I'd get, 
> e.g., for a vm's folder:
>
> *"['/First Datacenter/vm/Prod-SRM']"*
>
> The problem with that is *['* and *']*. They can't be part pf the folder 
> name. After employing regex-replace, the output is:
>
> *" '/Bedford Datacenter/vm/Bedford-Prod-SRM' "*
>
> Try as I may, I've not been able to find a way to also remove the single 
> quotes (the double quotes can remain). I've tried appending to the 
> regex_replace, but every piece of code i've used has failed.
>
> *regex_replace('(\\[)|(\\])'|(addlcodehere),  '') }}*
>
> Your kinf assistance requested.
>
> -- 
> 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/34393455-5021-4342-89b4-de276d68ccd9n%40googlegroups.com
>  
> 
> .
>
>
>
>

-- 
You received 

Re: [ansible-project] Trying to replace single quote with regex_replace

2024-01-10 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
This works.


regex_replace(\"([\\[\\]'])\",'')

Escaping the double quotes that define the search regex gets around needing to 
escape the single quote. Also note that I collapsed your search into a single 
character set.


---

- name: test

  hosts: localhost

  become: false

  gather_facts: false

  vars:

mystr: "['/First Datacenter/vm/Prod-SRM']"

  tasks:

- debug: msg="{{ mystr | regex_replace(\"([\\[\\]'])\",'') }}"



% ansible-playbook -i localhost, foo.yml


PLAY [test] 



TASK [debug] 
***

ok: [localhost] => {

"msg": "/First Datacenter/vm/Prod-SRM"

}


PLAY RECAP 
*

localhost  : ok=1changed=0unreachable=0failed=0
skipped=0rescued=0ignored=0

The solution was found on this stack overflow page.

https://stackoverflow.com/questions/52495838/ansible-remove-the-single-quote-character-from-a-string

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

On Jan 10, 2024, at 9:27 AM, Rowe, Walter P. (Fed)  wrote:

Have you tried:

regex_replace('(\\[)|(\\])|(\\')', '')

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

On Jan 10, 2024, at 9:08 AM, Dimitri Yioulos  wrote:

Hello, all.

I'm working with VMware modules in removing snapshots across all vCenter 
folders. In order for this to work, I first have to get the folders in which 
the virtual machines live. Here's the playbook:

---

- hosts: all
  become: false
  gather_facts: false

  vars_prompt:

- name: "vcenter_username"
  prompt: "Enter your Vcenter username"
  private: no
- name: "vcenter_password"
  prompt: "Enter your VMware password"
  private: yes

  vars:
vcenter_hostname: vcenter1.mycompany.com
vcenter_datacenter: First Datacenter

  tasks:

- name: Find virtual machine's folder name
  vmware_guest_find:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
name: "{{ inventory_hostname }}"
validate_certs: False
  delegate_to: localhost
  ignore_errors: true
  register: vm_facts
  tags:
- folder

- name: Show folders
  ansible.builtin.debug:
msg: "{{ vm_facts.folders }}"
  tags:
- folder

- name: Remove all snapshots of a VM
  community.vmware.vmware_guest_snapshot:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter: "{{ vcenter_datacenter }}"
folder: "{{ vm_facts.folders | regex_replace('(\\[)|(\\])',  '') }}"
name: "{{ inventory_hostname }}"
state: remove_all
validate_certs: False
  delegate_to: localhost

Previous to my having employed regex_replace, this is the output I'd get, e.g., 
for a vm's folder:

"['/First Datacenter/vm/Prod-SRM']"

The problem with that is [' and ']. They can't be part pf the folder name. 
After employing regex-replace, the output is:

" '/Bedford Datacenter/vm/Bedford-Prod-SRM' "

Try as I may, I've not been able to find a way to also remove the single quotes 
(the double quotes can remain). I've tried appending to the regex_replace, but 
every piece of code i've used has failed.

regex_replace('(\\[)|(\\])'|(addlcodehere),  '') }}

Your kinf assistance requested.

--
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/34393455-5021-4342-89b4-de276d68ccd9n%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/D4C8E154-6B7D-4D2A-9EEF-7E0ECE8CBC17%40nist.gov.


Re: [ansible-project] Trying to replace single quote with regex_replace

2024-01-10 Thread Dimitri Yioulos
Hi, Walter.

Yes, and it fails:



*fatal: [api-dev-01 -> localhost]: FAILED! => {"msg": "template error 
while templating string: expected token 'end of print statement', got 
'string'. String: {{ vm_facts.folders | 
regex_replace('([)|(])|(')',  '') }}. expected token 'end of 
print statement', got 'string'"}*

On Wednesday, January 10, 2024 at 9:27:25 AM UTC-5 Rowe, Walter P. (Fed) 
wrote:

> Have you tried: 
>
> *regex_replace('(\\[)|(\\])**|(\\')**', '')*
>
> Walter
> --
> Walter Rowe, Division Chief
> Infrastructure Services Division
> Mobile: 202.355.4123 <(202)%20355-4123> 
>
> On Jan 10, 2024, at 9:08 AM, Dimitri Yioulos  wrote:
>
> Hello, all. 
>
> I'm working with VMware modules in removing snapshots across all vCenter 
> folders. In order for this to work, I first have to get the folders in 
> which the virtual machines live. Here's the playbook:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *--- - hosts: all   become: false   gather_facts: false   vars_prompt: 
> - name: "vcenter_username"   prompt: "Enter your Vcenter username" 
>   private: no - name: "vcenter_password"   prompt: "Enter your 
> VMware password"   private: yes   vars: vcenter_hostname: 
> vcenter1.mycompany.com  
> vcenter_datacenter: First Datacenter   tasks: - name: Find virtual 
> machine's folder name   vmware_guest_find: hostname: "{{ 
> vcenter_hostname }}" username: "{{ vcenter_username }}" 
> password: "{{ vcenter_password }}" name: "{{ inventory_hostname }}" 
> validate_certs: False   delegate_to: localhost   
> ignore_errors: true   register: vm_facts   tags: *
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *- folder - name: Show folders   ansible.builtin.debug:   
>   msg: "{{ vm_facts.folders }}"   tags: - folder - 
> name: Remove all snapshots of a VM   
> community.vmware.vmware_guest_snapshot: hostname: "{{ 
> vcenter_hostname }}" username: "{{ vcenter_username }}" 
> password: "{{ vcenter_password }}" datacenter: "{{ 
> vcenter_datacenter }}" folder: "{{ vm_facts.folders | 
> regex_replace('(\\[)|(\\])',  '') }}" name: "{{ inventory_hostname 
> }}" state: remove_all validate_certs: False   
> delegate_to: localhost*
>
> Previous to my having employed regex_replace, this is the output I'd get, 
> e.g., for a vm's folder:
>
> *"['/First Datacenter/vm/Prod-SRM']"*
>
> The problem with that is *['* and *']*. They can't be part pf the folder 
> name. After employing regex-replace, the output is:
>
> *" '/Bedford Datacenter/vm/Bedford-Prod-SRM' "*
>
> Try as I may, I've not been able to find a way to also remove the single 
> quotes (the double quotes can remain). I've tried appending to the 
> regex_replace, but every piece of code i've used has failed.
>
> *regex_replace('(\\[)|(\\])'|(addlcodehere),  '') }}*
>
> Your kinf assistance requested.
>
> -- 
> 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/34393455-5021-4342-89b4-de276d68ccd9n%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/29d9f7b7-60bf-45c9-86b0-afedfb237830n%40googlegroups.com.


Re: [ansible-project] Trying to replace single quote with regex_replace

2024-01-10 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
Have you tried:

regex_replace('(\\[)|(\\])|(\\')', '')

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

On Jan 10, 2024, at 9:08 AM, Dimitri Yioulos  wrote:

Hello, all.

I'm working with VMware modules in removing snapshots across all vCenter 
folders. In order for this to work, I first have to get the folders in which 
the virtual machines live. Here's the playbook:

---

- hosts: all
  become: false
  gather_facts: false

  vars_prompt:

- name: "vcenter_username"
  prompt: "Enter your Vcenter username"
  private: no
- name: "vcenter_password"
  prompt: "Enter your VMware password"
  private: yes

  vars:
vcenter_hostname: vcenter1.mycompany.com
vcenter_datacenter: First Datacenter

  tasks:

- name: Find virtual machine's folder name
  vmware_guest_find:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
name: "{{ inventory_hostname }}"
validate_certs: False
  delegate_to: localhost
  ignore_errors: true
  register: vm_facts
  tags:
- folder

- name: Show folders
  ansible.builtin.debug:
msg: "{{ vm_facts.folders }}"
  tags:
- folder

- name: Remove all snapshots of a VM
  community.vmware.vmware_guest_snapshot:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter: "{{ vcenter_datacenter }}"
folder: "{{ vm_facts.folders | regex_replace('(\\[)|(\\])',  '') }}"
name: "{{ inventory_hostname }}"
state: remove_all
validate_certs: False
  delegate_to: localhost

Previous to my having employed regex_replace, this is the output I'd get, e.g., 
for a vm's folder:

"['/First Datacenter/vm/Prod-SRM']"

The problem with that is [' and ']. They can't be part pf the folder name. 
After employing regex-replace, the output is:

" '/Bedford Datacenter/vm/Bedford-Prod-SRM' "

Try as I may, I've not been able to find a way to also remove the single quotes 
(the double quotes can remain). I've tried appending to the regex_replace, but 
every piece of code i've used has failed.

regex_replace('(\\[)|(\\])'|(addlcodehere),  '') }}

Your kinf assistance requested.

--
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/34393455-5021-4342-89b4-de276d68ccd9n%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/6D8F3276-7A70-4ABC-A47D-B177ACB4E34C%40nist.gov.


[ansible-project] Trying to replace single quote with regex_replace

2024-01-10 Thread Dimitri Yioulos
Hello, all.

I'm working with VMware modules in removing snapshots across all vCenter 
folders. In order for this to work, I first have to get the folders in 
which the virtual machines live. Here's the playbook:

































* hosts: all  become: false  gather_facts: false  vars_prompt:- 
name: "vcenter_username"  prompt: "Enter your Vcenter username"  
private: no- name: "vcenter_password"  prompt: "Enter your VMware 
password"  private: yes  vars:vcenter_hostname: 
vcenter1.mycompany.comvcenter_datacenter: First Datacenter  tasks:- 
name: Find virtual machine's folder name  vmware_guest_find:
hostname: "{{ vcenter_hostname }}"username: "{{ vcenter_username 
}}"password: "{{ vcenter_password }}"name: "{{ 
inventory_hostname }}"validate_certs: False  delegate_to: 
localhost  ignore_errors: true  register: vm_facts  tags:*


















*- folder- name: Show folders  ansible.builtin.debug:  
  msg: "{{ vm_facts.folders }}"  tags:- folder- name: 
Remove all snapshots of a VM  community.vmware.vmware_guest_snapshot:  
  hostname: "{{ vcenter_hostname }}"username: "{{ 
vcenter_username }}"password: "{{ vcenter_password }}"
datacenter: "{{ vcenter_datacenter }}"folder: "{{ vm_facts.folders 
| regex_replace('(\\[)|(\\])',  '') }}"name: "{{ inventory_hostname 
}}"state: remove_allvalidate_certs: False  delegate_to: 
localhost*

Previous to my having employed regex_replace, this is the output I'd get, 
e.g., for a vm's folder:

*"['/First Datacenter/vm/Prod-SRM']"*

The problem with that is *['* and *']*. They can't be part pf the folder 
name. After employing regex-replace, the output is:

*" '/Bedford Datacenter/vm/Bedford-Prod-SRM' "*

Try as I may, I've not been able to find a way to also remove the single 
quotes (the double quotes can remain). I've tried appending to the 
regex_replace, but every piece of code i've used has failed.

*regex_replace('(\\[)|(\\])'|(addlcodehere),  '') }}*

Your kinf assistance requested.

-- 
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/34393455-5021-4342-89b4-de276d68ccd9n%40googlegroups.com.


[ansible-project] ansible.builtin.user :: input password appears not to have been hashed

2024-01-10 Thread Adrian Sevcenco

Hi! I'm trying to sync users from a "frontend" type server
to compute nodes and for this i build a var yml with the information
including the hash of the passwords (provided by spwd module attribute sp_pwdp)
sp_pwdp is described here as Encrypted password, see 
https://docs.python.org/3.6/library/spwd.html#module-spwd

as such i used it in ansible.builtin.user in the 'password' attribute but i get:
[WARNING]: The input password appears not to have been hashed. The 'password' argument must be encrypted for this module 
to work properly.


from a --check run the issue seems to be from nfsnobody user that have the 
bellow information
but the problem seems to come from 'hash': '!!'

Any idea what can i do to fix this? or being a warning i can just ignore it?

Thanks a lot!!
Adrian

ok: [issaf-0-0] => (item={'name': 'nfsnobody', 'uid': 65534, 'gid': 65534, 'shell': '/sbin/nologin', 'home': 
'/var/lib/nfs', 'groups': [], 'hash': '!!'}) => {

"ansible_loop_var": "user_def",
"append": false,
"changed": false,
"comment": "Anonymous NFS User",
"group": 65534,
"groups": "",
"home": "/var/lib/nfs",
"invocation": {
"module_args": {
"append": false,
"authorization": null,
"comment": null,
"create_home": false,
"expires": null,
"force": false,
"generate_ssh_key": null,
"group": null,
"groups": [],
"hidden": null,
"home": "/var/lib/nfs",
"local": null,
"login_class": null,
"move_home": false,
"name": "nfsnobody",
"non_unique": false,
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"password_expire_max": null,
"password_expire_min": null,
"password_lock": null,
"profile": null,
"remove": false,
"role": null,
"seuser": null,
"shell": "/sbin/nologin",
"skeleton": null,
"ssh_key_bits": 0,
"ssh_key_comment": "ansible-generated on issaf-0-0.issaf",
"ssh_key_file": null,
"ssh_key_passphrase": null,
"ssh_key_type": "rsa",
"state": "present",
"system": false,
"uid": 65534,
"update_password": "always"
}
},
"move_home": false,
"name": "nfsnobody",
"password": "NOT_LOGGING_PASSWORD",
"shell": "/sbin/nologin",
"state": "present",
"uid": 65534,
"user_def": {
"gid": 65534,
"groups": [],
"hash": "!!",
"home": "/var/lib/nfs",
"name": "nfsnobody",
"shell": "/sbin/nologin",
"uid": 65534
},
"warnings": [
"The input password appears not to have been hashed. The 'password' argument must be encrypted for this module 
to work properly."

]
}

--
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/effa28df-f579-4bbc-9f23-326fa89574e3%40gmail.com.


Re: [ansible-project] ERROR! Unexpected Exception, this is probably a bug: module 'argcomplete' has no attribute 'autocomplete'

2024-01-10 Thread Dick Visser
On Wed, 10 Jan 2024 at 10:52, Arunkumar Paramasivam 
wrote:

> I installed ansible using homebrew and was working until recent update


What was updated? Homebrew? or ansible? or both? or?
Also, homebrew isn't listed as an installation method on
https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html
.
I would recommend picking an installation method from there.



> What am I missing? Any help would be appreciated. Thanks you
>
> I tried adding ansible_python_interpreter="/usr/bin/python3", but no luck.
>
> my python version in system
> ╰─➤  python -m pip -V
> pip 23.3.2 from
> /Users/aparamasivam/Library/Python/3.11/lib/python/site-packages/pip
> (python 3.11)
>
> ─➤  ansible -v
> ERROR! Unexpected Exception, this is probably a bug: module 'argcomplete'
> has no attribute 'autocomplete'
> the full traceback was:
>
> Traceback (most recent call last):
>   File
> "/opt/homebrew/Cellar/ansible/9.1.0/libexec/lib/python3.12/site-packages/ansible/cli/__init__.py",
> line 659, in cli_executor
> exit_code = cli.run()
> ^
>   File
> "/opt/homebrew/Cellar/ansible/9.1.0/libexec/lib/python3.12/site-packages/ansible/cli/adhoc.py",
> line 104, in run
> super(AdHocCLI, self).run()
>   File
> "/opt/homebrew/Cellar/ansible/9.1.0/libexec/lib/python3.12/site-packages/ansible/cli/__init__.py",
> line 156, in run
> self.parse()
>   File
> "/opt/homebrew/Cellar/ansible/9.1.0/libexec/lib/python3.12/site-packages/ansible/cli/__init__.py",
> line 462, in parse
> argcomplete.autocomplete(self.parser)
> 
> AttributeError: module 'argcomplete' has no attribute 'autocomplete'
>
> --
> 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/7190f30e-c7ba-493b-a041-14bc43f5f07fn%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/CAF8BbLYNTDP6SKHZO-3%2BpMu7YeBadHSj0PWWGtOk3CFk1XJBVQ%40mail.gmail.com.


[ansible-project] ERROR! Unexpected Exception, this is probably a bug: module 'argcomplete' has no attribute 'autocomplete'

2024-01-10 Thread Arunkumar Paramasivam
I installed ansible using homebrew and was working until recent update
What am I missing? Any help would be appreciated. Thanks you

I tried adding ansible_python_interpreter="/usr/bin/python3", but no luck.

my python version in system
╰─➤  python -m pip -V
pip 23.3.2 from 
/Users/aparamasivam/Library/Python/3.11/lib/python/site-packages/pip 
(python 3.11)

─➤  ansible -v
ERROR! Unexpected Exception, this is probably a bug: module 'argcomplete' 
has no attribute 'autocomplete'
the full traceback was:

Traceback (most recent call last):
  File 
"/opt/homebrew/Cellar/ansible/9.1.0/libexec/lib/python3.12/site-packages/ansible/cli/__init__.py",
 
line 659, in cli_executor
exit_code = cli.run()
^
  File 
"/opt/homebrew/Cellar/ansible/9.1.0/libexec/lib/python3.12/site-packages/ansible/cli/adhoc.py",
 
line 104, in run
super(AdHocCLI, self).run()
  File 
"/opt/homebrew/Cellar/ansible/9.1.0/libexec/lib/python3.12/site-packages/ansible/cli/__init__.py",
 
line 156, in run
self.parse()
  File 
"/opt/homebrew/Cellar/ansible/9.1.0/libexec/lib/python3.12/site-packages/ansible/cli/__init__.py",
 
line 462, in parse
argcomplete.autocomplete(self.parser)

AttributeError: module 'argcomplete' has no attribute 'autocomplete'

-- 
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/7190f30e-c7ba-493b-a041-14bc43f5f07fn%40googlegroups.com.


[ansible-project] ERROR! Unexpected Exception, this is probably a bug: module 'argcomplete' has no attribute 'autocomplete'

2024-01-10 Thread Arunkumar Paramasivam
I installed ansible using homebrew and was working fine for a while and 
recently started failing with this error message. any help to resolve this 
woule be appreciated, thank you.

╰─➤  ansible -v
ERROR! Unexpected Exception, this is probably a bug: module 'argcomplete' 
has no attribute 'autocomplete'
the full traceback was:

Traceback (most recent call last):
  File 
"/opt/homebrew/Cellar/ansible/9.1.0/libexec/lib/python3.12/site-packages/ansible/cli/__init__.py",
 
line 659, in cli_executor
exit_code = cli.run()
^
  File 
"/opt/homebrew/Cellar/ansible/9.1.0/libexec/lib/python3.12/site-packages/ansible/cli/adhoc.py",
 
line 104, in run
super(AdHocCLI, self).run()
  File 
"/opt/homebrew/Cellar/ansible/9.1.0/libexec/lib/python3.12/site-packages/ansible/cli/__init__.py",
 
line 156, in run
self.parse()
  File 
"/opt/homebrew/Cellar/ansible/9.1.0/libexec/lib/python3.12/site-packages/ansible/cli/__init__.py",
 
line 462, in parse
argcomplete.autocomplete(self.parser)

AttributeError: module 'argcomplete' has no attribute 'autocomplete'

-- 
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/3c267f95-6b1a-4bec-afe9-4d09fc7b2b8an%40googlegroups.com.