Re: [ansible-project] How to split string twice in ansible playbook hosts section.

2022-12-27 Thread Vladimir Botka
> On Tue, Dec 27, 2022 at 7:04 AM Know-Your-Tech  wrote:
> >
> > ansible-playbook -i /web/aes/admin/playbooks/updated.hosts
> > /web/aes/admin/playbooks/split.yml -e ENV=qa -e NODE=cluster -e
> > instance_name=APP1,APP2
> >
> > Playbook:
> >
> > ---
> > - hosts: "{{ [ENV] | product(instance_name.split(',')) | product([NODE]) |
> > product(['wladmin_mmsplit'])|map('flatten')|map('join', '_') }}"

Put the logic into the inventory plugin *constructed*. See
shell> ansible-doc -t inventory ansible.builtin.constructed

In the example below, I'll use another inventory plugin *generator*
which you don't need because you obviously have another source of the
inventory. When you try the code below in your environment use this
source instead of 02-generator.yml. See
shell> ansible-doc -t inventory ansible.builtin.generator

I've ignored the case of the parameters.

1) Create the inventory

shell> tree inventory/
inventory/
├── 01-hosts
├── 02-generator.yml
└── 03-constructed.yml

shell> cat inventory/01-hosts 
localhost

shell> cat inventory/02-generator.yml 
plugin: ansible.builtin.generator
hosts:
  name: "{{ env }}_{{ instance }}_{{ node }}_{{ ext }}"
layers:
  env:
- dev
- qa
- prod
  instance:
- app1
- app2
  node:
- cluster1
- cluster2
  ext:
- wladmin_mmsplit

shell> cat inventory/03-constructed.yml 
plugin: ansible.builtin.constructed
use_extra_vars: true
compose:
  layer_env: ENV.split(',')
  layer_node: NODE.split(',')
  layer_instance: instance_name.split(',')
groups:
  my_group: inventory_hostname.split('_').0 in layer_env and
inventory_hostname.split('_').1 in layer_instance and
inventory_hostname.split('_').2 in layer_node

2) Test inventory

shell> ansible-inventory -i inventory --list --yaml
all:
  children:
ungrouped:
  hosts:
dev_app1_cluster1_wladmin_mmsplit: {}
dev_app1_cluster2_wladmin_mmsplit: {}
dev_app2_cluster1_wladmin_mmsplit: {}
dev_app2_cluster2_wladmin_mmsplit: {}
localhost: {}
prod_app1_cluster1_wladmin_mmsplit: {}
prod_app1_cluster2_wladmin_mmsplit: {}
prod_app2_cluster1_wladmin_mmsplit: {}
prod_app2_cluster2_wladmin_mmsplit: {}
qa_app1_cluster1_wladmin_mmsplit: {}
qa_app1_cluster2_wladmin_mmsplit: {}
qa_app2_cluster1_wladmin_mmsplit: {}
qa_app2_cluster2_wladmin_mmsplit: {}

3) Test inventory group *my_group*

shell> ansible-inventory -i inventory --list --yaml -e ENV=qa -e NODE=cluster2 
-e instance_name=app1,app2
all:
  children:
my_group:
  hosts:
qa_app1_cluster2_wladmin_mmsplit:
  ENV: qa
  NODE: cluster2
  instance_name: app1,app2
  layer_env:
  - qa
  layer_instance:
  - app1
  - app2
  layer_node:
  - cluster2
qa_app2_cluster2_wladmin_mmsplit:
  ENV: qa
  NODE: cluster2
  instance_name: app1,app2
  layer_env:
  - qa
  layer_instance:
  - app1
  - app2
  layer_node:
  - cluster2
ungrouped:
  hosts:
dev_app1_cluster1_wladmin_mmsplit:
...

4) Use *my_group* in a playbook

shell> cat pb.yml 
- hosts: my_group
  tasks:
- debug:
var: ansible_play_hosts_all
  run_once: true

shell> ansible-playbook -i inventory -e ENV=qa -e NODE=cluster2 -e 
instance_name=app1,app2 pb.yml

PLAY [my_group]
*

TASK [debug]
*
ok: [qa_app1_cluster2_wladmin_mmsplit] =>
  ansible_play_hosts_all:
  - qa_app1_cluster2_wladmin_mmsplit
  - qa_app2_cluster2_wladmin_mmsplit
  ...

5) The items added to the inventory (02-generator.yml in this example)

  instance:
- app1
- app2
- app3-brazil

will be automatically available for selection

shell> ansible-playbook -i inventory -e ENV=qa -e NODE=cluster2 -e 
instance_name=app1,app3-brazil pb.yml

PLAY [my_group]
**

TASK [debug]
*
ok: [qa_app1_cluster2_wladmin_mmsplit] => ansible_play_hosts_all:
  - qa_app1_cluster2_wladmin_mmsplit
  - qa_app3-brazil_cluster2_wladmin_mmsplit
  ...

-- 
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/20221228041926.7c027306%40gmail.com.


pgpsNUXdPi3Vw.pgp
Description: OpenPGP digital signature


Re: [ansible-project] Ansible - combine output

2022-12-27 Thread Dick Visser
Hii

On Tue, 27 Dec 2022 at 18:41, ahar...@gmail.com  wrote:

> [ removed some unwanted data ]


I'm not sure what you intended to do here, but if you are under the
impression that you could somehow retract the credentials that you posted
to this (public) list earlier, that is impossible.
If they are real credentials then they should be considered compromised and
you should reset them.

Dick
-- 
Sent from Gmail Mobile

-- 
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/CAF8BbLZ1Jd%2Bd4bchS5z-6Ov_zVy7veJyJYRQsPe5WP2pWx8yYw%40mail.gmail.com.


[ansible-project] Add Ansible Template as RPC dependancy for Privilege Vault/Secret Server

2022-12-27 Thread Tim
We're running Delinea/Thycotic Privilege Vault in our environment.

We're trying to onboard all credentials into Privilege Vault as much as 
possible to leverage Auto-Change, where the password is rotated by 
Privilege Vault every X days.

Whereas using the Remote File and Application Pool Recycle dependencies 
works in many instances, there are other instances where we would like to 
trigger an Ansible Playbook after an RPC in Privilege Vault. Has anyone 
been able to add an Ansible Playbook as a dependency for a remote password 
change (RPC)?

If not, how are you triggering playbooks after an RPC?

-- 
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/ae373bf9-8823-4b66-9f86-a5db20fabd2an%40googlegroups.com.


Re: [ansible-project] How to split string twice in ansible playbook hosts section.

2022-12-27 Thread Vladimir Botka
On Tue, 27 Dec 2022 09:47:57 -0700
Richard Megginson  wrote:

> `split` is not an ansible filter

Wrong. The filter *split* is available since 2.11. See
https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_filters.html#manipulating-strings

-- 
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/20221227192459.2011e8f0%40gmail.com.


pgpiQOqAKtbmU.pgp
Description: OpenPGP digital signature


Re: [ansible-project] Ansible - combine output

2022-12-27 Thread ahar...@gmail.com
[ removed some unwanted data ]

On Sunday, October 30, 2022 at 9:13:48 PM UTC+5:30 Todd Lewis wrote:

> Since I don't have the hosts you do, I'm going to create a "proxy 
> variable" to stand in for your "hostvars". I think I'm giving it the same 
> structure that your hostvars has. See if this playbook helps explain the 
> manipulation.
>
> ---
> - name: Combining lists across hostvars
>   hosts: localhost
>   gather_facts: no
>   vars:
> hostvars_proxy:   # This is my proxy for your "hostvars" variable.
>  Cluster1:
>"list_snapmirror": [
>{
>"Host_Name": "Cluster1",
>"destination_path": "data",
>"lagTime": "NULL",
>"source_path": "data"
>},
>{
>"Host_Name": "Cluster1",
>"destination_path": "data",
>"lagTime": "P483DT17H7M38S",
>"source_path": "data"
>}
>]
>  Cluster2:
>"list_snapmirror": [
>{
>"Host_Name": "Cluster2",
>"destination_path": "data",
>"lagTime": "P215DT22H24M15S",
>"source_path": "data"
>},
>{
>"Host_Name": "Cluster2",
>"destination_path": "data",
>"lagTime": "NULL",
>"source_path": "data"
>},
>{
>"Host_Name": "Cluster2",
>"destination_path": "data",
>"lagTime": "PT8M39S",
>"source_path": "data"
>}
>]
>
>   tasks:
> - name: show me the data
>   debug:
> msg: "{{ hostvars_proxy }}"
>
> - name: show me dict2items
>   debug:
> msg: "{{ hostvars_proxy | dict2items }}"
>
> - name: show me dict2items | value
>   debug:
> msg: "{{ hostvars_proxy | dict2items | map(attribute='value') }}"
>
> - name: show me dict2items | value | list_snapmirror
>   debug:
> msg: "{{ hostvars_proxy | dict2items | map(attribute='value') | 
> map(attribute='list_snapmirror') }}"
>
> - name: show me dict2items | value | list_snapmirror | flatten
>   debug:
> msg: "{{ hostvars_proxy | dict2items | map(attribute='value') | 
> map(attribute='list_snapmirror') | flatten }}"
>
>
>
> On Saturday, October 29, 2022 at 10:54:52 PM UTC-4 ahar...@gmail.com 
> wrote:
>
>> Hi,
>>
>> I tried but there is still some issue. Please help what i am 
>> missing here. Thank you
>>
>> TASK [set_fact] 
>> *
>>
>>
>> *fatal: [localhost]: FAILED! => {"msg": 
>> "\"hostvars['inventory_hostname']\" is undefined"*
>>
>>
>> *Playbook:*
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> * hosts: all  collections: - netapp.ontap  gather_facts: no  
>> connection: local  vars:#ansible_python_interpreter: /usr/bin/python3  
>>   input:   hostname: "{{ inventory_hostname }}"*
>>
>
>> *  username:   password:*
>>
>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> *  https: true  validate_certs: false  use_rest: Always  
>> tasks:  - name: run ontap rest cli command
>> netapp.ontap.na_ontap_rest_cli:  <<: *input  command: 
>> 'snapmirror?fields=lag_time'  verb: 'GET'register: 
>> ontap_volume_info  - debug: var=ontap_volume_info.msg*
>>
>
>>
>>
>>
>>
>>
>> *- hosts: localhost  gather_facts: no  connection: local  tasks:  - 
>> set_fact:  list_snapmirror: "{{ list_snapmirror|default([]) + 
>> [{'source_path': item.source_path ,'destination_path': 
>> item.destination_path ,'lagTime': item.lag_time } ] }}"*
>>
> *#with_items: "{{ ontap_volume_info.msg.records }}"*
>>
>
>>
>>
>>
>>
>> *with_items: "{{ 
>> hostvars['inventory_hostname']['ontap_volume_info.msg.records'] }}"
>> when:  - hostvars['inventory_hostname']['ontap_volume_info'] is 
>> defined  - hostvars['inventory_hostname']['item.lag_time'] is defined  
>>   run_once: true*
>>
>
>>
>> *  - debug:  var=list_snapmirror*
>> ...
>>
>>
>>
>> On Sat, Oct 29, 2022 at 11:01 AM Aharonu  wrote:
>>
>>> Thank you for your response.
>>>
>>> Sure, I will try ans get back with an update
>>>
>>> On Sat, 29 Oct 2022, 11:12 rajthecomputerguy,  
>>> wrote:
>>>
>> Please try this, just explore hostvars in another play

 ---
 - hosts: all
   collections:
  - netapp.ontap
   gather_facts: no
   connection: local
   vars:
 #ansible_python_interpreter: /usr/bin/python3
 input: 
   hostname: "{{ inventory_hostname }}"
   username: 'aharonu'
   password: 'abcd1234'
   https: true
   validate_certs: false
   use_rest: Always
   tasks:
   - name: run ontap rest cli command
 

Re: [ansible-project] Ansible - combine output

2022-12-27 Thread ahar...@gmail.com

[ remove some unwanted data ]
On Sunday, October 30, 2022 at 9:13:48 PM UTC+5:30 Todd Lewis wrote:

> Since I don't have the hosts you do, I'm going to create a "proxy 
> variable" to stand in for your "hostvars". I think I'm giving it the same 
> structure that your hostvars has. See if this playbook helps explain the 
> manipulation.
>
> ---
> - name: Combining lists across hostvars
>   hosts: localhost
>   gather_facts: no
>   vars:
> hostvars_proxy:   # This is my proxy for your "hostvars" variable.
>  Cluster1:
>"list_snapmirror": [
>{
>"Host_Name": "Cluster1",
>"destination_path": "data",
>"lagTime": "NULL",
>"source_path": "data"
>},
>{
>"Host_Name": "Cluster1",
>"destination_path": "data",
>"lagTime": "P483DT17H7M38S",
>"source_path": "data"
>}
>]
>  Cluster2:
>"list_snapmirror": [
>{
>"Host_Name": "Cluster2",
>"destination_path": "data",
>"lagTime": "P215DT22H24M15S",
>"source_path": "data"
>},
>{
>"Host_Name": "Cluster2",
>"destination_path": "data",
>"lagTime": "NULL",
>"source_path": "data"
>},
>{
>"Host_Name": "Cluster2",
>"destination_path": "data",
>"lagTime": "PT8M39S",
>"source_path": "data"
>}
>]
>
>   tasks:
> - name: show me the data
>   debug:
> msg: "{{ hostvars_proxy }}"
>
> - name: show me dict2items
>   debug:
> msg: "{{ hostvars_proxy | dict2items }}"
>
> - name: show me dict2items | value
>   debug:
> msg: "{{ hostvars_proxy | dict2items | map(attribute='value') }}"
>
> - name: show me dict2items | value | list_snapmirror
>   debug:
> msg: "{{ hostvars_proxy | dict2items | map(attribute='value') | 
> map(attribute='list_snapmirror') }}"
>
> - name: show me dict2items | value | list_snapmirror | flatten
>   debug:
> msg: "{{ hostvars_proxy | dict2items | map(attribute='value') | 
> map(attribute='list_snapmirror') | flatten }}"
>
>
>
> On Saturday, October 29, 2022 at 10:54:52 PM UTC-4 ahar...@gmail.com 
> wrote:
>
>> Hi,
>>
>> I tried but there is still some issue. Please help what i am 
>> missing here. Thank you
>>
>> TASK [set_fact] 
>> *
>> task path: 
>>
>> *fatal: [localhost]: FAILED! => {"msg": 
>> "\"hostvars['inventory_hostname']\" is undefined"*
>>
>>
>> *Playbook:*
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> * hosts: all  collections: - netapp.ontap  gather_facts: no  
>> connection: local  vars:#ansible_python_interpreter: /usr/bin/python3  
>>   input:   hostname: "{{ inventory_hostname }}"*
>>
>
>> *  username:  password: *
>>
>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> *  https: true  validate_certs: false  use_rest: Always  
>> tasks:  - name: run ontap rest cli command
>> netapp.ontap.na_ontap_rest_cli:  <<: *input  command: 
>> 'snapmirror?fields=lag_time'  verb: 'GET'register: 
>> ontap_volume_info  - debug: var=ontap_volume_info.msg*
>>
>
>>
>>
>>
>>
>>
>> *- hosts: localhost  gather_facts: no  connection: local  tasks:  - 
>> set_fact:  list_snapmirror: "{{ list_snapmirror|default([]) + 
>> [{'source_path': item.source_path ,'destination_path': 
>> item.destination_path ,'lagTime': item.lag_time } ] }}"*
>>
> *#with_items: "{{ ontap_volume_info.msg.records }}"*
>>
>
>>
>>
>>
>>
>> *with_items: "{{ 
>> hostvars['inventory_hostname']['ontap_volume_info.msg.records'] }}"
>> when:  - hostvars['inventory_hostname']['ontap_volume_info'] is 
>> defined  - hostvars['inventory_hostname']['item.lag_time'] is defined  
>>   run_once: true*
>>
>
>>
>> *  - debug:  var=list_snapmirror*
>> ...
>>
>>
>>
>> On Sat, Oct 29, 2022 at 11:01 AM Aharonu  wrote:
>>
>>> Thank you for your response.
>>>
>>> Sure, I will try ans get back with an update
>>>
>>> On Sat, 29 Oct 2022, 11:12 rajthecomputerguy,  
>>> wrote:
>>>
>> Please try this, just explore hostvars in another play

 ---
 - hosts: all
   collections:
  - netapp.ontap
   gather_facts: no
   connection: local
   vars:
 #ansible_python_interpreter: /usr/bin/python3
 input: 
   hostname: "{{ inventory_hostname }}"
   username: 'aharonu'
   password: 'abcd1234'
   https: true
   validate_certs: false
   use_rest: Always
   tasks:
   - name: run ontap rest cli command
   

Re: [ansible-project] Ansible - combine output

2022-12-27 Thread ahar...@gmail.com
[ remove some unwanted data ]

On Sunday, October 30, 2022 at 9:13:48 PM UTC+5:30 Todd Lewis wrote:

> Since I don't have the hosts you do, I'm going to create a "proxy 
> variable" to stand in for your "hostvars". I think I'm giving it the same 
> structure that your hostvars has. See if this playbook helps explain the 
> manipulation.
>
> ---
> - name: Combining lists across hostvars
>   hosts: localhost
>   gather_facts: no
>   vars:
> hostvars_proxy:   # This is my proxy for your "hostvars" variable.
>  Cluster1:
>"list_snapmirror": [
>{
>"Host_Name": "Cluster1",
>"destination_path": "data",
>"lagTime": "NULL",
>"source_path": "data"
>},
>{
>"Host_Name": "Cluster1",
>"destination_path": "data",
>"lagTime": "P483DT17H7M38S",
>"source_path": "data"
>}
>]
>  Cluster2:
>"list_snapmirror": [
>{
>"Host_Name": "Cluster2",
>"destination_path": "data",
>"lagTime": "P215DT22H24M15S",
>"source_path": "data"
>},
>{
>"Host_Name": "Cluster2",
>"destination_path": "data",
>"lagTime": "NULL",
>"source_path": "data"
>},
>{
>"Host_Name": "Cluster2",
>"destination_path": "data",
>"lagTime": "PT8M39S",
>"source_path": "data"
>}
>]
>
>   tasks:
> - name: show me the data
>   debug:
> msg: "{{ hostvars_proxy }}"
>
> - name: show me dict2items
>   debug:
> msg: "{{ hostvars_proxy | dict2items }}"
>
> - name: show me dict2items | value
>   debug:
> msg: "{{ hostvars_proxy | dict2items | map(attribute='value') }}"
>
> - name: show me dict2items | value | list_snapmirror
>   debug:
> msg: "{{ hostvars_proxy | dict2items | map(attribute='value') | 
> map(attribute='list_snapmirror') }}"
>
> - name: show me dict2items | value | list_snapmirror | flatten
>   debug:
> msg: "{{ hostvars_proxy | dict2items | map(attribute='value') | 
> map(attribute='list_snapmirror') | flatten }}"
>
>
>
> On Saturday, October 29, 2022 at 10:54:52 PM UTC-4 ahar...@gmail.com 
> wrote:
>
>> Hi,
>>
>> I tried but there is still some issue. Please help what i am 
>> missing here. Thank you
>>
>> TASK [set_fact] 
>> 
>>
>> *fatal: [localhost]: FAILED! => {"msg": 
>> "\"hostvars['inventory_hostname']\" is undefined"*
>>
>>
>> *Playbook:*
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> * hosts: all  collections: - netapp.ontap  gather_facts: no  
>> connection: local  vars:#ansible_python_interpreter: /usr/bin/python3  
>>   input:   hostname: "{{ inventory_hostname }}"*
>>
>
>> *  username: xx  password: xxx*
>>
>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> *  https: true  validate_certs: false  use_rest: Always  
>> tasks:  - name: run ontap rest cli command
>> netapp.ontap.na_ontap_rest_cli:  <<: *input  command: 
>> 'snapmirror?fields=lag_time'  verb: 'GET'register: 
>> ontap_volume_info  - debug: var=ontap_volume_info.msg*
>>
>
>>
>>
>>
>>
>>
>> *- hosts: localhost  gather_facts: no  connection: local  tasks:  - 
>> set_fact:  list_snapmirror: "{{ list_snapmirror|default([]) + 
>> [{'source_path': item.source_path ,'destination_path': 
>> item.destination_path ,'lagTime': item.lag_time } ] }}"*
>>
> *#with_items: "{{ ontap_volume_info.msg.records }}"*
>>
>
>>
>>
>>
>>
>> *with_items: "{{ 
>> hostvars['inventory_hostname']['ontap_volume_info.msg.records'] }}"
>> when:  - hostvars['inventory_hostname']['ontap_volume_info'] is 
>> defined  - hostvars['inventory_hostname']['item.lag_time'] is defined  
>>   run_once: true*
>>
>
>>
>> *  - debug:  var=list_snapmirror*
>> ...
>>
>>
>>
>> On Sat, Oct 29, 2022 at 11:01 AM Aharonu  wrote:
>>
>>> Thank you for your response.
>>>
>>> Sure, I will try ans get back with an update
>>>
>>> On Sat, 29 Oct 2022, 11:12 rajthecomputerguy,  
>>> wrote:
>>>
>> Please try this, just explore hostvars in another play

 ---
 - hosts: all
   collections:
  - netapp.ontap
   gather_facts: no
   connection: local
   vars:
 #ansible_python_interpreter: /usr/bin/python3
 input: 
   hostname: "{{ inventory_hostname }}"
   username: 'aharonu'
   password: 'abcd1234'
   https: true
   validate_certs: false
   use_rest: Always
   tasks:
   - name: run ontap rest cli command
 

Re: [ansible-project] How to split string twice in ansible playbook hosts section.

2022-12-27 Thread Know-Your-Tech
Thanks, Richard, but I was looking for a specific solution which seems to 
be tricky.

On Tuesday, December 27, 2022 at 10:18:27 PM UTC+5:30 Richard Megginson 
wrote:

> `split` is not an ansible filter - you cannot use it like `| 
> split(something)` - you have to use as a string method which is why 
> `instance_name.split(',')` works
>
> On Tue, Dec 27, 2022 at 7:04 AM Know-Your-Tech  wrote:
>
>> Below is how i call my ansible-playbook and pass application names as 
>> parameters APP1 & APP2
>>
>> ansible-playbook -i /web/aes/admin/playbooks/updated.hosts 
>> /web/aes/admin/playbooks/split.yml -e ENV=qa -e NODE=cluster -e 
>> instance_name=APP1,APP2
>>
>> Playbook:
>>
>> ---
>> - hosts: "{{ [ENV] | product(instance_name.split(',')) | product([NODE]) 
>> | product(['wladmin_mmsplit'])|map('flatten')|map('join', '_') }}"
>>   user: wladmin
>>   gather_facts: no
>>
>> I get the desired Output as below:
>>
>> PLAY [['qa_APP1_cluster_wladmin_mmsplit', 
>> 'qa_APP2_cluster_wladmin_mmsplit']]
>>
>> The problem occurs when i pass the application names as 
>> APP1-brazil & APP2-Chile
>>
>> and wish the same output as before.
>>
>> ansible-playbook -i /web/aes/admin/playbooks/updated.hosts 
>> /web/aes/admin/playbooks/split.yml -e ENV=qa -e NODE=cluster -e 
>> instance_name=APP1-brazil,APP2-Chile
>>
>> I tried the below but i get error:
>>
>> - hosts: "{{ [ENV] | product(instance_name.split(',') | split('-')[0]) | 
>> product([NODE]) | product(['wladmin_mmsplit'])|map('flatten')|map('join', 
>> '_') }}"
>>
>> Error in output:
>>
>> ERROR! template error while templating string: expected token ',', got 
>> '['. String: {{ [ENV] | product(instance_name.split(',') | split('-')[0]) | 
>> product([NODE]) | product(['wladmin_mmsplit'])|map('flatten')|map('join', 
>> '_') }}
>>
>> Can you please suggest how can i address this requirement? 
>>  
>>
>> -- 
>> 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/da1f5460-e7c8-4e84-814a-ed3b2e3a9828n%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/5ab85cf8-d627-4092-afc6-a7bd7d883a0dn%40googlegroups.com.


Re: [ansible-project] How to split string twice in ansible playbook hosts section.

2022-12-27 Thread Richard Megginson
`split` is not an ansible filter - you cannot use it like `|
split(something)` - you have to use as a string method which is why
`instance_name.split(',')` works

On Tue, Dec 27, 2022 at 7:04 AM Know-Your-Tech  wrote:

> Below is how i call my ansible-playbook and pass application names as
> parameters APP1 & APP2
>
> ansible-playbook -i /web/aes/admin/playbooks/updated.hosts
> /web/aes/admin/playbooks/split.yml -e ENV=qa -e NODE=cluster -e
> instance_name=APP1,APP2
>
> Playbook:
>
> ---
> - hosts: "{{ [ENV] | product(instance_name.split(',')) | product([NODE]) |
> product(['wladmin_mmsplit'])|map('flatten')|map('join', '_') }}"
>   user: wladmin
>   gather_facts: no
>
> I get the desired Output as below:
>
> PLAY [['qa_APP1_cluster_wladmin_mmsplit',
> 'qa_APP2_cluster_wladmin_mmsplit']]
>
> The problem occurs when i pass the application names as
> APP1-brazil & APP2-Chile
>
> and wish the same output as before.
>
> ansible-playbook -i /web/aes/admin/playbooks/updated.hosts
> /web/aes/admin/playbooks/split.yml -e ENV=qa -e NODE=cluster -e
> instance_name=APP1-brazil,APP2-Chile
>
> I tried the below but i get error:
>
> - hosts: "{{ [ENV] | product(instance_name.split(',') | split('-')[0]) |
> product([NODE]) | product(['wladmin_mmsplit'])|map('flatten')|map('join',
> '_') }}"
>
> Error in output:
>
> ERROR! template error while templating string: expected token ',', got
> '['. String: {{ [ENV] | product(instance_name.split(',') | split('-')[0]) |
> product([NODE]) | product(['wladmin_mmsplit'])|map('flatten')|map('join',
> '_') }}
>
> Can you please suggest how can i address this requirement?
>
>
> --
> 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/da1f5460-e7c8-4e84-814a-ed3b2e3a9828n%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/CALF5A-JaEOy%2BNgwvLySNmtTX7kXjcyZk5UbP0aQzhVY%3De1OLXA%40mail.gmail.com.


[ansible-project] How to split string twice in ansible playbook hosts section.

2022-12-27 Thread Know-Your-Tech
Below is how i call my ansible-playbook and pass application names as 
parameters APP1 & APP2

ansible-playbook -i /web/aes/admin/playbooks/updated.hosts 
/web/aes/admin/playbooks/split.yml -e ENV=qa -e NODE=cluster -e 
instance_name=APP1,APP2

Playbook:

---
- hosts: "{{ [ENV] | product(instance_name.split(',')) | product([NODE]) | 
product(['wladmin_mmsplit'])|map('flatten')|map('join', '_') }}"
  user: wladmin
  gather_facts: no

I get the desired Output as below:

PLAY [['qa_APP1_cluster_wladmin_mmsplit', 
'qa_APP2_cluster_wladmin_mmsplit']]

The problem occurs when i pass the application names as 
APP1-brazil & APP2-Chile

and wish the same output as before.

ansible-playbook -i /web/aes/admin/playbooks/updated.hosts 
/web/aes/admin/playbooks/split.yml -e ENV=qa -e NODE=cluster -e 
instance_name=APP1-brazil,APP2-Chile

I tried the below but i get error:

- hosts: "{{ [ENV] | product(instance_name.split(',') | split('-')[0]) | 
product([NODE]) | product(['wladmin_mmsplit'])|map('flatten')|map('join', 
'_') }}"

Error in output:

ERROR! template error while templating string: expected token ',', got '['. 
String: {{ [ENV] | product(instance_name.split(',') | split('-')[0]) | 
product([NODE]) | product(['wladmin_mmsplit'])|map('flatten')|map('join', 
'_') }}

Can you please suggest how can i address this requirement? 
 

-- 
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/da1f5460-e7c8-4e84-814a-ed3b2e3a9828n%40googlegroups.com.