Re: [ansible-project] json_query & regular expression

2020-04-11 Thread Vladimir Botka
On Sat, 11 Apr 2020 21:26:28 -0700 (PDT)
Kiran Kumar  wrote:

> In jason query how can i add regular expression ? eg if have vm1, vm2,vm3 
> below query can be adjusted ? eg   query: "[?guest_name == 'vm*' ]" , 
> seems does not work in below case 
> 
> >   tasks:
> >   - name: Gather all VMs information
> > vmware_vm_info:
> >   hostname: '{{ vcenter_hostname }}'
> >   username: '{{ vcenter_username }}'
> >   password: '{{ vcenter_password }}'
> >   validate_certs: no
> > register: vm_facts
> > delegate_to: localhost
> >   - debug:
> >   msg:  "{{ item.ip_address }}"
> > with_items:
> > - "{{ vm_facts.virtual_machines | json_query(query) }}"
> > vars:
> >   query: "[?guest_name == 'vm1' ]"  

Filter "selectattr" should do the job. For example

- debug:
msg: "{{ item.ip_address }}"
  loop: "{{ vm_facts|
selectattr('guest_name', 'match', '^vm1$')|
list }}"
- debug:
msg: "{{ item.ip_address }}"
  loop: "{{ vm_facts|
selectattr('guest_name', 'match', '^vm(.*)$')|
list }}"

I'm not aware of regex in JMESPath.
https://jmespath.readthedocs.io/en/latest/

HTH,

-vlado

-- 
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/20200412070147.05c65041%40gmail.com.


pgpGeHxUxSg7J.pgp
Description: OpenPGP digital signature


[ansible-project] json_query & regular expression

2020-04-11 Thread Kiran Kumar
In jason query how can i add regular expression ? eg if have vm1, vm2,vm3 
below query can be adjusted ? eg   query: "[?guest_name == 'vm*' ]" , 
seems does not work in below case 


https://jmespath.org/specification.html#filterexpressions  i tried few 
things but no luck 

Thanks


---
> - hosts: localhost
>   vars_files:
> - vcsim_vars.yml
>   tasks:
>   - name: Gather all VMs information
> vmware_vm_info:
>   hostname: '{{ vcenter_hostname }}'
>   username: '{{ vcenter_username }}'
>   password: '{{ vcenter_password }}'
>   validate_certs: no
> register: vm_facts
> delegate_to: localhost
>   - debug:
>   msg:  "{{ item.ip_address }}"
> with_items:
> - "{{ vm_facts.virtual_machines | json_query(query) }}"
> vars:
>   query: "[?guest_name == 'vm1' ]"


-- 
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/4e22d894-160a-4a1f-8a1f-0cb8fb5aa6ca%40googlegroups.com.


[ansible-project] Re: using vars_prompt in a vars file being addressed by include_vars

2020-04-11 Thread Dave Zarei
HI xxmlud,

yeah i couldn't find any documents saying this is possible. as a remedy, i 
used pause module in the main play.

Thanks.


On Friday, April 10, 2020 at 1:03:29 PM UTC-4, xxmlud gnu wrote:
>
> Hello,
>
> I think "vars_prompt" can only be used in the main playbook.
>
> BR,
>
>
> El jueves, 9 de abril de 2020, 20:45:28 (UTC+2), Dave Zarei escribió:
>>
>> HI,
>>
>> Got a quick question, I'm trying to use include_vars in a main play which 
>> addresses a vars file in which there is vars_prompt (i also have an 
>> include_tasks in the same main play which uses the variables being 
>> addressed by include_vars). when i run the main play there is no error, but 
>> it doesn't prompt me for the items i got under vars_prompt in the vars 
>> file. to make it short, how can i use vars_prompt in a vars file being 
>> addressed by include_vars?
>>
>>
>> Thanks
>>
>

-- 
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/026d64e3-e562-4c8f-ac0c-1cd2f3bb5962%40googlegroups.com.


Re: [ansible-project] Using OpenSSL module without files

2020-04-11 Thread 'Felix Fontein' via Ansible Project
Hi Dick,

> Our ansible deployments are using OpenSSL key materials that are
> stored as multiline values in yaml vars files.
> I'd like to use openssl_certificate_info but that seems to require a
> path parameter:
> https://docs.ansible.com/ansible/latest/modules/openssl_certificate_info_module.html
> 
> After inspection the majority of the openssl modules have this
> requirement.

that's indeed true.

> I can't think of a way to use the modules with variable based
> certificate materials, someone else maybe knows?

There isn't one.

> Also would this be a good feature request?

It is, and someone already requested this:
https://github.com/ansible/ansible/issues/63553

> For instance a new 'content' parameter which contains the key
> material.

That won't work that easily, unfortunately, as the modules are designed
to behave similarly to the `file` module. It would require a new set of
modules which are designed differently.

Fortunately, now that everything has been moved to collections
(https://github.com/ansible-collections/community.crypto/), this is
easier to do, since it is easier to move code to module_utils. My idea
would be to refactor the modules to move a lot of their core
functionality to module_utils, and then adding a new modules which can
work in-memory, re-use the core functionality from module_utils, and
thus do not require a large amount of code copy'n'paste. I have a
couple of other things I'll work on first, but this is something that
I'd like to do somewhen anyway.

Cheers,
Felix


-- 
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/20200411100748.64d509b2%40rovaniemi.


[ansible-project] Using OpenSSL module without files

2020-04-11 Thread Dick Visser
Hi

Our ansible deployments are using OpenSSL key materials that are stored as
multiline values in yaml vars files.
I'd like to use openssl_certificate_info but that seems to require a path
parameter:
https://docs.ansible.com/ansible/latest/modules/openssl_certificate_info_module.html

After inspection the majority of the openssl modules have this requirement.

I can't think of a way to use the modules with variable based certificate
materials, someone else maybe knows?

Also would this be a good feature request?
For instance a new 'content' parameter which contains the key material.


Thx


Dick

-- 
Sent from a mobile device - please excuse the brevity, spelling and
punctuation.

-- 
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/CAL8fbwOO6awv-Fz7%2BzzZyWkvJSSLFGNtdrTJD5dVkPRU4hr4-Q%40mail.gmail.com.


Re: [ansible-project] Append data to json file using ansible modules

2020-04-11 Thread Shyam U
Hi Vinod and dick,

Thank you, please look at the json file on the remote server. I'm trying to
replace the nas path using win_lineinfile, but the path that I'm providing
is updating at the end of the file.

Hi dick, please update how to do with from_json and to_json.

Json file:

[
{
 "Service_id" : "node1"
 "Source_path" : "192.168.1.1\\data\\nonprod"
 "Source_type" : "NAS"
 "Deztination_type": "Nas"
  }
]

Playbook:

Win_lineinfile:
   Path: D:\\dest\\config.json
   regexp : '^source_path'
   insertafter: '^service_id'
   line: '192.168.1.2\\data\\nonprod'
   state: present

Thankyou,
Shyam



On Sat, Apr 11, 2020, 3:41 AM Dick Visser  wrote:

> It depends on your data.
> Please post your json and tell what you want to manipulate exactly.
> Lineinfile sounds fragile. You might have better results with from_json,
> combine, and to_json.
>
>
> On Fri, 10 Apr 2020 at 21:02, syam rhel  wrote:
>
>> Hi All,
>>
>> Is it possible to update the data of json file using ansible modules.
>>
>> I tried on windows machine using win_lineinfile module but the required
>> file is not updating.
>>
>> The line is updating at the end of the file.
>>
>> Can any one suggest the solution for editing fields in json file.
>>
>> Thank you,
>>
>> --
>> 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/61a135e8-2c2a-4751-b21f-884c25debda3%40googlegroups.com
>> .
>>
> --
> Sent from a mobile device - please excuse the brevity, spelling and
> punctuation.
>
> --
> 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/CAL8fbwNu7%2BAkRyeCdw2B-x2C1zV0sg8muLuD1KA0urgw0NWyNQ%40mail.gmail.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/CAN0_vCY%2BfrtN6p5dzGFJwnactVujHBNs6ZYRDj4fKdX17sYJHg%40mail.gmail.com.