[ansible-project] Looping through data/vars file turns number into a string when creating a site in Cisco DNA Center

2023-08-17 Thread Paul Bauer
When using the task below with the yaml data that is shown below I end up 
getting an error indicating that my latitude number is not a number. If I 
just hard code a number in the latitude value the task works as expected. 
Any suggestions on how to get this to work?

Ansible task
# DNA Center Site Creation
- name: Create building
cisco.dnac.site_create:
dnac_host: "{{ ansible_host }}"
dnac_username: "{{ username }}"
dnac_password: "{{ password }}"
dnac_verify: false
dnac_port: 443
dnac_version: "2.3.3.0"
site:
building:
address: "{{ item.address }}"
country: "{{ item.country }}"
latitude: "{{ (item.latitude | float) }}"
longitude: "{{ (item.longitude | float) }}" 
name: "{{ item.name }}"
parentName: "{{ item.parent_name }}"
type: "{{ item.site_type }}"
loop: "{{ sites }}"
when: item.site_type == 'building'

YAML Data 
# vars file for dnac-create-site-hierarchy
sites:
# North America
- name: "US"
site_type: "area"
parent_name: "Global"
- name: "Big Campus"
site_type: "area"
parent_name: "Global/US"
- name: "Big_bldg"
site_type: "building"
address: " Big Dr."
country: "United States"
latitude: 44.2
longitude: -111.1
parent_name: "Global/US/Big Campus"

Error Message returned from the Cisco DNAC SDK which is required for the 
Cisco.DNAC Ansible Module

raise MalformedRequest(
dnacentersdk.exceptions.MalformedRequest: {'type': 'building', 'site': {
'building': {'address': ' Big Dr.', 'country': 'United States', 
'latitude': '44.2', 'longitude': '-111.1', 'name': 'Big_bldg', 
'parentName': 'Global/US/Big Campus'}}} is invalid. Reason: 
data.site.building.latitude 
must be number
failed: [dna-center-lab] (item={'name': 'Big_bldg', 'site_type': 'building', 
'address': ' Big Dr.', 'country': 'United States', 'latitude': 44.2, 
'longitude': -111.1, 'parent_name': 'Global/US/Big Campus'}) => {
"ansible_loop_var": "item",
"item": {
"address": " Big Dr.",
"country": "United States",
"latitude": 44.2,
"longitude": -111.1,
"name": "Big_bldg",
"parent_name": "Global/US/Big Campus",
"site_type": "building"
},
"msg": "An error occured when executing operation. The error was: {'type': 
'building', 'site': {'building': {'address': ' Big Dr.', 'country': 
'United States', 'latitude': '44.2', 'longitude': '-111.1', 'name': 
'Big_bldg', 'parentName': 'Global/US/Big Campus'}}} is invalid. Reason: 
data.site.building.latitude must be number"
}

Thank you,

Paul

-- 
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/84cec934-05e7-4ed8-a67a-44d35f83bb0cn%40googlegroups.com.


Re: [ansible-project] Shell module commands runs on Local Controller

2023-08-17 Thread Harry Clendening
Agreed.  This is essentially what I am doing now and it does work (pipe var 
to regex_search, etc.).  I was just hoping to get the (shell:) command to 
work in our environment, but with our setup, it does not appear to be 
possible.  I should also be to take the (bigip_command:) output, write the 
JSON to file, and then run AWK against the file.  I have not tried this 
yet.  I'll probably just stick with (regex_search) for now.  Thanks!
On Thursday, August 17, 2023 at 10:41:00 AM UTC-4 Rowe, Walter P. (Fed) 
wrote:

> If the F5 is returning structured data (ie. JSON), then set_fact tasks 
> with filters can help you get to what you need.
>
>
> Walter
> --
> Walter Rowe, Division Chief
> Infrastructure Services, OISM
> Mobile: 202.355.4123 <(202)%20355-4123>
>
> On Aug 17, 2023, at 10:32 AM, Harry Clendening  
> wrote:
>
> I can get the basic disk space command (df) to work when using a F5 module 
> (bigip_command:) (which does use provider:).  However, the F5 modules do 
> not support (AWK, GREP, SED, etc.) (which is a bummer), like (shell:) and 
> (command:) do.  I may end up having to use (bigip_command:) to grab the 
> disk space, and then use a separate Ansible (regex_search) task to filter 
> for what I want, which is what I have done in the past (albeit this is an 
> extra step).
>
>
>

-- 
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/38e660a0-eb7d-4035-bc4d-789902125004n%40googlegroups.com.


Re: [ansible-project] Loopless alternative?

2023-08-17 Thread Vladimir Botka
On Thu, 17 Aug 2023 13:11:25 -0400
Brian Coca  wrote:

> see map/select/reject filters .. they are actually loops and normally
> much simpler than using jinja command syntax ( {% %} ).

Unfortunately, some filters are not *map* friendly. For example, the
filter *product*

  list1|product(list2) .. works fine
  list1|zip(list2)|map('product') ... does not work


Details: Given the list

  l1:
- dir: /tmp/test/d1
  sub_dir: [a, b]
- dir: /tmp/test/d2
  sub_dir: [a, b, c]

the goal is to create the list of products

  l2:
  - /tmp/test/d1/a
  - /tmp/test/d1/b
  - /tmp/test/d2/a
  - /tmp/test/d2/b
  - /tmp/test/d2/c

The iteration (the filter *subelements* not used
to demonstrate the functionality of *product*)

- debug:
msg: "{{ [item.0]|product(item.1) }}"
  loop: "{{ dirs|zip(sdirs) }}"
  vars:
dirs: "{{ l1|map(attribute='dir') }}"
sdirs: "{{ l1|map(attribute='sub_dir') }}"

works as expected. Gives (abridged)

  msg:
  - - /tmp/test/d1
- a
  - - /tmp/test/d1
- b

  msg:
  - - /tmp/test/d2
- a
  - - /tmp/test/d2
- b
  - - /tmp/test/d2
- c

But, the filter *product* doesn't work with *map*

  dirs: "{{ l1|map(attribute='dir') }}"
  sdirs: "{{ l1|map(attribute='sub_dir') }}"
  l3: "{{ dirs|zip(sdirs)|map('product') }}"

gives

  l3:
  - - - /tmp/test/d1
- - - a
- b
  - - - /tmp/test/d2
- - - a
- b
- c

This leaves you with Jinja if you want to avoid the loops in tasks

  l3: |
{% filter from_yaml %}
{% for i in l1 %}
{% for s in i.sub_dir %}
- {{ i.dir }}/{{ s }}
{% endfor %}
{% endfor %}
{% endfilter %}

-- 
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/20230817202944.3f3512c8%40gmail.com.


pgpzQmp4GVXoP.pgp
Description: OpenPGP digital signature


Re: [ansible-project] Loopless alternative?

2023-08-17 Thread Brian Coca
see map/select/reject filters .. they are actually loops and normally
much simpler than using jinja command syntax ( {% %} ).

-- 
--
Brian Coca

-- 
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/CACVha7cCi7ZURZdzutxvi5vsCDsUyFrB757n3Q-fTcHFyQo0Tg%40mail.gmail.com.


Re: [ansible-project] Loopless alternative?

2023-08-17 Thread Vladimir Botka
On Thu, 17 Aug 2023 07:56:58 -0400
Todd Lewis  wrote:

>bn:
>- - basename
>  - dev_wss_db
>- - basename
>  - dev_wss_db_requests
>- - basename
>  - dev_bss_service_database
>- - basename
>  - dev_bss_frontend_db
>- - basename
>  - dev_mss_db
> 
> But I didn't find a way to map that using "community.general.dict" to create
> 
>bn:
>- basename: dev_wss_db
>- basename: dev_wss_db_requests
>- basename: dev_bss_service_database
>- basename: dev_bss_frontend_db
>- basename: dev_mss_db

You can always use brute-force Jinja as the last resort. For example,
given the list

  bn_list:
  - dev_wss_db
  - dev_wss_db_requests
  - dev_bss_service_database
  - dev_bss_frontend_db
  - dev_mss_db

the below Jinja creates the list of the hashes

  bn: |
{% filter from_yaml %}
{% for basename in bn_list %}
- basename: {{ basename }}
{% endfor %}
{% endfilter %}

As a side-note, this is equivalent to

  bn: "{{ all_objects|
  map(attribute='Key')|
  map('regex_replace', bn_regex, '{basename: \\1}')|
  map('from_yaml') }}"
 
> This for me is one of the more frustrating things about Jinja
> pipelines. I keep wishing "map" would take arbitrary
> expressions rather than the limited set it's stuck with.

This is very good point. It would be possible to write such a filter.
However, I'm not sure about the security implications.

-- 
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/20230817170740.038163cc%40gmail.com.


pgpOgqpg7TAic.pgp
Description: OpenPGP digital signature


[ansible-project] Ansible 2.15 Warning message

2023-08-17 Thread Dhirender Yadav
Hi Team,

Recently we have upgraded to ansible 2.15 and we are getting below WARNINGS.

*Please find the below for the ansible version and collection installed.*

~$ ansible-galaxy collection list -p /home/test/

[DEPRECATION WARNING]: DEFAULT_GATHER_SUBSET option, the module_defaults
keyword is a more generic version and can apply to all calls to the
M(ansible.builtin.gather_facts) or M(ansible.builtin.setup) actions, use
module_defaults

instead. This feature will be removed from ansible-core in version 2.18.
Deprecation warnings can be disabled by setting deprecation_warnings=False
in ansible.cfg.


# /home/test/ansible_collections

Collection Version

- ---

ansible.posix 1.5.4

ansible.utils 2.10.3

community.general 4.6.1

:~$

:~$ ansible --version

ansible-playbook [core 2.15.2]

config file = /home/test/ansible.cfg

configured module search path = ['/home/test/modules']

ansible python module location =
/usr/local/lib/python3.9/site-packages/ansible

ansible collection location = /home/test

executable location = /usr/local/bin/ansible-playbook

python version = 3.9.16 (main, Dec 21 2022, 10:57:18) [GCC 8.5.0 20210514
(Red Hat 8.5.0-17)] (/usr/bin/python3.9)

jinja version = 3.1.2

libyaml = False

*Ansible playbook used for the testing:*

*:~$ cat test.yml*

---

- name: Fail test

hosts: localhost

any_errors_fatal: true

vars:

CASSANDRA:

distribution: dse

pre_tasks:

- fail:

msg: "Cassandra distribution '{{ CASSANDRA.distribution|d(distribution) }}'
is not valid"

when:

- CASSANDRA.distribution|d(distribution) not in ('dse', 'apache_cassandra')

- '"test" not in ansible_run_tags'

tasks:

- debug: msg="{{ CASSANDRA.distribution }}"
--

*Ansible logs *

:~$ ansible-playbook test.yml -vv
ansible-playbook [core 2.15.2]
  config file = /home/test/ansible.cfg
  configured module search path = ['/home/test/modules']
  ansible python module location =
/usr/local/lib/python3.9/site-packages/ansible
  ansible collection location = /home/test
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.9.16 (main, Dec 21 2022, 10:57:18) [GCC 8.5.0 20210514
(Red Hat 8.5.0-17)] (/usr/bin/python3.9)
  jinja version = 3.1.2
  libyaml = False
Using /home/test/ansible.cfg as config file
[DEPRECATION WARNING]: DEFAULT_GATHER_SUBSET option, the module_defaults
keyword is a more generic version and can apply to all calls to the
M(ansible.builtin.gather_facts) or M(ansible.builtin.setup) actions, use
module_defaults
instead. This feature will be removed from ansible-core in version 2.18.
Deprecation warnings can be disabled by setting deprecation_warnings=False
in ansible.cfg.
[WARNING]: Skipping plugin
(/usr/local/lib/python3.9/site-packages/ansible/plugins/callback/selective.py),
cannot load: cannot import name 'codeCodes' from 'ansible.utils.color'
(/usr/local/lib/python3.9/site-
packages/ansible/utils/color.py)
Skipping callback 'dense', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
Skipping callback 'actionable', as we already have a stdout callback.
Skipping callback 'counter_enabled', as we already have a stdout callback.
Skipping callback 'debug', as we already have a stdout callback.
Skipping callback 'dense', as we already have a stdout callback.
Skipping callback 'full_skip', as we already have a stdout callback.
Skipping callback 'json', as we already have a stdout callback.
Skipping callback 'null', as we already have a stdout callback.
Skipping callback 'skippy', as we already have a stdout callback.
Skipping callback 'stderr', as we already have a stdout callback.
Skipping callback 'unixy', as we already have a stdout callback.
Skipping callback 'yaml', as we already have a stdout callback.

PLAYBOOK: test.yml
**
1 plays in test.yml

PLAY [Fail test]


TASK [Gathering Facts]
**
task path: /home/test/test.yml:2
ok: [localhost]

TASK [fail]
*
task path: /home/test/test.yml:9
redirecting (type: filter) ansible.builtin.ipaddr to
ansible.netcommon.ipaddr
*[WARNING]: An unexpected 

Re: [ansible-project] Shell module commands runs on Local Controller

2023-08-17 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
If the F5 is returning structured data (ie. JSON), then set_fact tasks with 
filters can help you get to what you need.

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

On Aug 17, 2023, at 10:32 AM, Harry Clendening  
wrote:

I can get the basic disk space command (df) to work when using a F5 module 
(bigip_command:) (which does use provider:).  However, the F5 modules do not 
support (AWK, GREP, SED, etc.) (which is a bummer), like (shell:) and 
(command:) do.  I may end up having to use (bigip_command:) to grab the disk 
space, and then use a separate Ansible (regex_search) task to filter for what I 
want, which is what I have done in the past (albeit this is an extra step).

-- 
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/FD30305E-7242-43EA-B6F9-E7D9930B3B6B%40nist.gov.


Re: [ansible-project] Shell module commands runs on Local Controller

2023-08-17 Thread Harry Clendening
I can get the basic disk space command (df) to work when using a F5 module 
(bigip_command:) (which does use provider:).  However, the F5 modules do 
not support (AWK, GREP, SED, etc.) (which is a bummer), like (shell:) and 
(command:) do.  I may end up having to use (bigip_command:) to grab the 
disk space, and then use a separate Ansible (regex_search) task to filter 
for what I want, which is what I have done in the past (albeit this is an 
extra step).
On Thursday, August 17, 2023 at 10:26:35 AM UTC-4 Harry Clendening wrote:

> Hello Brian.  Thank you for your reply.  Please all me to provide some 
> additional context based on your suggestion (I should have mentioned this 
> on my initial post):
>
> We are working with F5 BIG-IP devices and using REST API  (443) (
> https://clouddocs.f5.com/products/orchestration/ansible/devel/usage/playbook_tutorial.html)
>  
> for the remote device connection, and not SSH (22).  If I remove 
> (connection: local), Ansible try's to connect using SSH (22) (which is 
> blocked).  Since the (shell:) module does not appear to support the F5 
> (provider:) credentials/connection (please see example below), I'm not sure 
> how to get (shell:) to connect to a remote host.  I have tried adding 
> (delegate_to: server1) to the (shell:) command and it simply ignores it.
>
> vars:
>   provider:
> password: password
> server: 1.1.1.1
> user: admin_name
> validate_certs: no
> server_port: 443
>
>
> On Thursday, August 17, 2023 at 10:00:18 AM UTC-4 Brian Coca wrote:
>
>> That is becase 'connection: local' forces using the 'local' connection 
>> plugin, which means that instead of executing on the target it 'forks 
>> locally' to execute the module. 
>> Just remove it, 99% of the time you do not need to specify `connection`. 
>>
>> -- 
>> -- 
>> Brian Coca 
>>
>>

-- 
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/6e98371a-27e1-45ad-a91c-16a2e6f64107n%40googlegroups.com.


Re: [ansible-project] Shell module commands runs on Local Controller

2023-08-17 Thread Harry Clendening
Hello Brian.  Thank you for your reply.  Please all me to provide some 
additional context based on your suggestion (I should have mentioned this 
on my initial post):

We are working with F5 BIG-IP devices and using REST API  (443) (
https://clouddocs.f5.com/products/orchestration/ansible/devel/usage/playbook_tutorial.html)
 
for the remote device connection, and not SSH (22).  If I remove 
(connection: local), Ansible try's to connect using SSH (22) (which is 
blocked).  Since the (shell:) module does not appear to support the F5 
(provider:) credentials/connection (please see example below), I'm not sure 
how to get (shell:) to connect to a remote host.  I have tried adding 
(delegate_to: server1) to the (shell:) command and it simply ignores it.

vars:
  provider:
password: password
server: 1.1.1.1
user: admin_name
validate_certs: no
server_port: 443


On Thursday, August 17, 2023 at 10:00:18 AM UTC-4 Brian Coca wrote:

> That is becase 'connection: local' forces using the 'local' connection
> plugin, which means that instead of executing on the target it 'forks
> locally' to execute the module.
> Just remove it, 99% of the time you do not need to specify `connection`.
>
> -- 
> --
> Brian Coca
>
>

-- 
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/d0f9e2dc-5992-4714-bc05-b66fd56f1d68n%40googlegroups.com.


Re: [ansible-project] Shell module commands runs on Local Controller

2023-08-17 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
Just remove it, 99% of the time you do not need to specify `connection`.

.. and you still can delegate individual tasks to localhost when needed ..

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

On Aug 17, 2023, at 9:59 AM, Brian Coca  wrote:

That is becase 'connection: local' forces using the 'local' connection
plugin, which means that instead of executing on the target it 'forks
locally' to execute the module.
Just remove it, 99% of the time you do not need to specify `connection`.

--
--
Brian Coca

--
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://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2FCACVha7dZo6PgpVnymyO9trKRqU3YS6EoF9AoXxeR5-%252BDN9KGcQ%2540mail.gmail.com=05%7C01%7Cwalter.rowe%40nist.gov%7C9efc5d85b5954e48b10d08db9f2a4560%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638278776139822553%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C=5V8CbvQmY8TYnDQ6%2BMLHGSb3XVELxUivqYvCFm0p4qc%3D=0.

-- 
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/A37D9962-78E8-4B6A-A209-C3130AFE778E%40nist.gov.


Re: [ansible-project] Shell module commands runs on Local Controller

2023-08-17 Thread Brian Coca
That is becase 'connection: local' forces using the 'local' connection
plugin, which means that instead of executing on the target it 'forks
locally' to execute the module.
Just remove it, 99% of the time you do not need to specify `connection`.

-- 
--
Brian Coca

-- 
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/CACVha7dZo6PgpVnymyO9trKRqU3YS6EoF9AoXxeR5-%2BDN9KGcQ%40mail.gmail.com.


[ansible-project] Shell module commands runs on Local Controller

2023-08-17 Thread Harry Clendening
Good morning,

I am attempting to use the (shell:) command to obtain the disk space for a 
remote host.  Once I get the command working, I'll then use AWK to filter 
the output.

However, the below example playbook insists on running the (shell:) command 
on the local Ansible control machine, and not the remote host (server1).  
Thus, I end up with disk space (/var) for the Ansible machine, and NOT the 
remote host (server1).  Does anyone know how what I may be doing wrong?  
Other commands for example (bigip_command:) run on the remote host fine.

If I enter a directory (chdir:) that only exists on the remote host, 
Ansible throws an error like "Directory does not exist", which is true, as 
it is looking on the local machine.

Thank you!

- name: Test Playbook
  hosts: server1
  connection: local
  gather_facts: true
   

  - name: Display Disk Space

shell:

  cmd: df /var
  chdir: /var
register: disk_space_output

-- 
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/ce88ea03-b22d-4a5a-a21b-e475517a0676n%40googlegroups.com.


Re: [ansible-project] Loopless alternative?

2023-08-17 Thread Todd Lewis
Thanks, Vladimir. I had missed the point of "community.general.dict_kv". 
I had gotten as far as this:


- set_fact:
bn: |
 {{ query('ansible.builtin.nested', ['basename'], (all_objects
| map(attribute='Key')
| map('regex_replace', '^' ~ prefix ~ '\d{10}_(.*)\.pgdump', 
'\1'))) }}

which produces:

  bn:
  - - basename
- dev_wss_db
  - - basename
- dev_wss_db_requests
  - - basename
- dev_bss_service_database
  - - basename
- dev_bss_frontend_db
  - - basename
- dev_mss_db

But I didn't find a way to map that using "community.general.dict" to create

  bn:
  - basename: dev_wss_db
  - basename: dev_wss_db_requests
  - basename: dev_bss_service_database
  - basename: dev_bss_frontend_db
  - basename: dev_mss_db

This for me is one of the more frustrating things about Jinja pipelines. 
I keep wishing "map" would take arbitrary expressions rather than the 
limited set it's stuck with. So you end up with a fleet of one-off 
filters like "community.general.dict_kv" which does what 
"community.general.dict" would do if there were an obvious way to turn this:


  - - basename
- dev_wss_db
  - - basename
- dev_wss_db_requests
  - - basename
- dev_bss_service_database
  - - basename
- dev_bss_frontend_db
  - - basename
- dev_mss_db

into this:

  - - - basename
  - dev_wss_db
  - - - basename
  - dev_wss_db_requests
  - - - basename
  - dev_bss_service_database
  - - - basename
  - dev_bss_frontend_db
  - - - basename
  - dev_mss_db

i.e. a "deepen" counterpart to "flatten". But that magical incantation 
has so far eluded me.

--
Todd

On 8/16/23 6:46 PM, Vladimir Botka wrote:

Create the list of the hashes

   bn_regex: '^{{ prefix }}\d{10}_(.*)\.pgdump$'
   bn: "{{ all_objects|
   map(attribute='Key')|
   map('regex_replace', bn_regex, '\\1')|
   map('community.general.dict_kv', 'basename') }}"

gives

   bn:
   - basename: dev_wss_db
   - basename: dev_wss_db_requests
   - basename: dev_bss_service_database
   - basename: dev_bss_frontend_db
   - basename: dev_mss_db

zip the lists and combine the items

   backup_object: "{{ all_objects|zip(bn)|map('combine') }}"




--
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/d783a813-746b-c961-eca7-76ba6bccc6aa%40gmail.com.


[ansible-project] uri post to avoid duplicate

2023-08-17 Thread Veera
Hi ,

I have the below uri module to post the details inside the web api

- name: REST POST Example
  uri:
url: "{{ webapp_url }}/api/orgs"
method: POST
return_content: yes
body: "{ \"name\": \"{{ project_name }}\" }"
body_format: json
validate_certs: no
user: "{{ user }}"
password: "{{ password }}"
force_basic_auth: yes

while passing the variables as 
ansible-playbook myplay.yml  -e "project_name=first_project"  
n- number of times it works and overwrites the same first_project name.

Is there an option available to stop overwriting if the same project_name 
is  available with uri module? 
Or we have to use the GET method  to collect and compare the existing 
project_name , before writing using POST? or will  a conditional check can 
help ?


-- 
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/1e1f7f5f-ea12-4349-9375-a2e1a8e22ef4n%40googlegroups.com.