[ansible-project] from a list from list of dictionaries

2020-07-02 Thread Sivaraman P
Hi all,
please help to form a list,

I have a register variable as below,

[
{
"application": 
{
name: "abc"
}
},
{
"service":
{
"name": "def"
}
},
{
"service":
{
"name": "ghi"
}
},
}
{
"application": 
{
name: "jkl"
}
},
{
"service":
{
"name": "mno"
}
},
}
]

I need to form a list from this list of dictionaries,

The list i need should be like
[
"name": "abc"
"service": "def"
"service":"ghi"
]
[
"application": "jkl"
"service":"mno"
]
starting from the first application to the services until the second 
application should come under one list. and starting from second application to 
the services until 3rd should come under 2nd list.

Note: one application contain atleast ome service and more than 2 services also 
that will be based on register variable. and here the total number of 
application is two that can also be differ based on register variable.

Is there any way to do this.

-- 
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/b8d95b29-2308-41de-bb03-f2366d3492aco%40googlegroups.com.


Re: [ansible-project] Ansible not accepting When condition

2020-07-02 Thread Vladimir Botka
On Thu, 2 Jul 2020 20:05:17 +0530
"T. JENISHA"  wrote:

> Is there any syntax highlighter recommended for Ansible

There is "YAML mode" available in Emacs (not perfect unfortunately)
https://www.emacswiki.org/emacs/YamlMode

"HighlightIndentation" is useful too
https://www.emacswiki.org/emacs/HighlightIndentation

-- 
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/20200702174509.162df97a%40gmail.com.


pgp9GkFzWb3DY.pgp
Description: OpenPGP digital signature


Re: [ansible-project] Ansible not accepting When condition

2020-07-02 Thread Dick Visser
https://docs.ansible.com/ansible/latest/community/other_tools_and_programs.html


On Thu, 2 Jul 2020 at 16:35, T. JENISHA  wrote:

> Thankyou I fixed it. Is there any syntax highlighter recommended for
> Ansible
>
>
> Best Regards
> Jenisha T
> Whatsapp: +91 07598087866
>
>
>
>
>
> On Thu, 2 Jul 2020 at 19:27, Srinivas Naram 
> wrote:
>
>> when is indented too much. Put it at the level where module name is
>> mentioned.
>>
>> ---
>> - name: using multiple conditions
>>   gather_facts: yes
>>   hosts: localhost
>>   connection: local
>>   tasks:
>> - package:
>> name: httpd
>> state: installed
>>   when:
>> - ansible_distribution == "RedHat"
>> - ansible_memfree_mb > 1512
>>
>> On Thu, Jul 2, 2020 at 7:21 PM Jenisha T  wrote:
>>
>>> Hi everyone,
>>> Below is my playbook
>>>
>>> ---
>>> - name: using multiple conditions
>>>   gather_facts: yes
>>>   hosts: localhost
>>>   connection: local
>>>   tasks:
>>> - package:
>>> name: httpd
>>> state: installed
>>> when:
>>>   - ansible_distribution == "RedHat"
>>>   - ansible_memfree_mb > 1512
>>>
>>> When I run this playbook I get below error
>>>
>>> https://pastebin.com/embed_iframe/BVRZKc5K;
>>> style="border:none;width:100%">
>>>
>>>
>>>
>>> --
>>> 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/47b62adb-87ae-451c-b077-3cfeff5be26en%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/CAG-N3P5vRTJsf%2BveHerV5NrxX8%3D0FD0%3DQAFg%2BwAw4pzQbDvuiw%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/CAAGhZYjXRJHmQd9FX61OKz%3DLRqry9xXGSHXCKm61WgvomTn9cg%40mail.gmail.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/CAL8fbwPexgbJGLJ%3DQhm3bzP6gmEYCJPdTMbwnSiJ8NpCNumHgQ%40mail.gmail.com.


Re: [ansible-project] Nxos_config module issue

2020-07-02 Thread Dick Visser
"through ansible" isn't a playbook/task.
Provide the playbook and the invocation of it.



On Thu, 2 Jul 2020 at 16:05, rajthecomputerguy 
wrote:

> Hi Team
>>>
>>> nxos_config module where Ansible cannot able to return below highlighted
>>> information from device rather it returns the config as changed.
>>>
>>> Is this a bug? please help
>>>
>>> Manual:
>>>
>>> lab.device.local(config)# logging server x.x.x.x 6
>>> Can't configure more than 8 IP Servers
>>>
>>> Through Ansible:
>>>
>>> changed: [lab.device.local] => {
>>> "changed": true,
>>> "commands": [
>>> "logging server x.x.x.x 6",
>>> "logging server x.x.x.x 6"
>>> ],
>>> "invocation": {
>>> "module_args": {
>>> "after": null,
>>> "auth_pass": null,
>>> "authorize": null,
>>> "backup": false,
>>> "before": null,
>>> "defaults": false,
>>> "diff_against": null,
>>> "diff_ignore_lines": null,
>>> "force": false,
>>> "host": null,
>>> "intended_config": null,
>>> "lines": [
>>> "logging server x.x.x.x 6",
>>> "logging server x.x.x.x 6"
>>> ],
>>> "match": "line",
>>> "parents": null,
>>> "password": null,
>>> "port": null,
>>> "provider": null,
>>> "replace": "line",
>>> "replace_src": null,
>>> "running_config": null,
>>> "save": false,
>>> "save_when": "never",
>>> "src": null,
>>> "ssh_keyfile": null,
>>> "timeout": null,
>>> "transport": null,
>>> "use_ssl": null,
>>> "username": null,
>>> "validate_certs": null
>>> }
>>> },
>>> "updates": [
>>> "logging server x.x.x.x 6",
>>> "logging server x.x.x.x 6"
>>> ]
>>> }
>>>
>> --
> 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/1e5a4b39-e427-4160-a2e4-81a7ba29a415o%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/CAL8fbwM5dnv07Sb_kTswuH_JrTgsSf7psFmukr4Ekb9cRK1jmg%40mail.gmail.com.


Re: [ansible-project] Ansible not accepting When condition

2020-07-02 Thread T. JENISHA
Thankyou I fixed it. Is there any syntax highlighter recommended for Ansible


Best Regards
Jenisha T
Whatsapp: +91 07598087866





On Thu, 2 Jul 2020 at 19:27, Srinivas Naram 
wrote:

> when is indented too much. Put it at the level where module name is
> mentioned.
>
> ---
> - name: using multiple conditions
>   gather_facts: yes
>   hosts: localhost
>   connection: local
>   tasks:
> - package:
> name: httpd
> state: installed
>   when:
> - ansible_distribution == "RedHat"
> - ansible_memfree_mb > 1512
>
> On Thu, Jul 2, 2020 at 7:21 PM Jenisha T  wrote:
>
>> Hi everyone,
>> Below is my playbook
>>
>> ---
>> - name: using multiple conditions
>>   gather_facts: yes
>>   hosts: localhost
>>   connection: local
>>   tasks:
>> - package:
>> name: httpd
>> state: installed
>> when:
>>   - ansible_distribution == "RedHat"
>>   - ansible_memfree_mb > 1512
>>
>> When I run this playbook I get below error
>>
>> https://pastebin.com/embed_iframe/BVRZKc5K;
>> style="border:none;width:100%">
>>
>>
>>
>> --
>> 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/47b62adb-87ae-451c-b077-3cfeff5be26en%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/CAG-N3P5vRTJsf%2BveHerV5NrxX8%3D0FD0%3DQAFg%2BwAw4pzQbDvuiw%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/CAAGhZYjXRJHmQd9FX61OKz%3DLRqry9xXGSHXCKm61WgvomTn9cg%40mail.gmail.com.


[ansible-project] Nxos_config module issue

2020-07-02 Thread rajthecomputerguy

>
> Hi Team
>>
>> nxos_config module where Ansible cannot able to return below highlighted 
>> information from device rather it returns the config as changed. 
>>
>> Is this a bug? please help
>>
>> Manual:
>>
>> lab.device.local(config)# logging server x.x.x.x 6
>> Can't configure more than 8 IP Servers
>>
>> Through Ansible:
>>
>> changed: [lab.device.local] => {
>> "changed": true, 
>> "commands": [
>> "logging server x.x.x.x 6", 
>> "logging server x.x.x.x 6"
>> ], 
>> "invocation": {
>> "module_args": {
>> "after": null, 
>> "auth_pass": null, 
>> "authorize": null, 
>> "backup": false, 
>> "before": null, 
>> "defaults": false, 
>> "diff_against": null, 
>> "diff_ignore_lines": null, 
>> "force": false, 
>> "host": null, 
>> "intended_config": null, 
>> "lines": [
>> "logging server x.x.x.x 6", 
>> "logging server x.x.x.x 6"
>> ], 
>> "match": "line", 
>> "parents": null, 
>> "password": null, 
>> "port": null, 
>> "provider": null, 
>> "replace": "line", 
>> "replace_src": null, 
>> "running_config": null, 
>> "save": false, 
>> "save_when": "never", 
>> "src": null, 
>> "ssh_keyfile": null, 
>> "timeout": null, 
>> "transport": null, 
>> "use_ssl": null, 
>> "username": null, 
>> "validate_certs": null
>> }
>> }, 
>> "updates": [
>> "logging server x.x.x.x 6", 
>> "logging server x.x.x.x 6"
>> ]
>> }
>>
>

-- 
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/1e5a4b39-e427-4160-a2e4-81a7ba29a415o%40googlegroups.com.


Re: [ansible-project] Ansible not accepting When condition

2020-07-02 Thread Srinivas Naram
when is indented too much. Put it at the level where module name is
mentioned.

---
- name: using multiple conditions
  gather_facts: yes
  hosts: localhost
  connection: local
  tasks:
- package:
name: httpd
state: installed
  when:
- ansible_distribution == "RedHat"
- ansible_memfree_mb > 1512

On Thu, Jul 2, 2020 at 7:21 PM Jenisha T  wrote:

> Hi everyone,
> Below is my playbook
>
> ---
> - name: using multiple conditions
>   gather_facts: yes
>   hosts: localhost
>   connection: local
>   tasks:
> - package:
> name: httpd
> state: installed
> when:
>   - ansible_distribution == "RedHat"
>   - ansible_memfree_mb > 1512
>
> When I run this playbook I get below error
>
> https://pastebin.com/embed_iframe/BVRZKc5K;
> style="border:none;width:100%">
>
>
>
> --
> 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/47b62adb-87ae-451c-b077-3cfeff5be26en%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/CAG-N3P5vRTJsf%2BveHerV5NrxX8%3D0FD0%3DQAFg%2BwAw4pzQbDvuiw%40mail.gmail.com.


Re: [ansible-project] Regular Expression in ANSIBLE

2020-07-02 Thread Stefan Schmid
What may work is using Ansible Modul script.
It returns e.g. as stdout only the requested string.

-- 
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/a016b71f-31f7-46b2-9264-f1b67451e362o%40googlegroups.com.


[ansible-project] Debug and Print only failed telnet hosts

2020-07-02 Thread Know-Your-Tech
Below is my playbook that does telnet from my localhost to destination 
hosts.

   - wait_for:

   host: "{{ item }}"

   port: 22

   state: started # Port should be open

   delay: 0   # No wait before first check (sec)

   timeout: 2 # Stop checking after timeout (sec)

 ignore_errors: yes

 register: netstatoutput

 delegate_to: localhost

 with_items: "{{ groups['all_hosts'] }}"

I get a lot of unnecessary stuff dumped in the logs when i debug like below:

   - debug:

   msg: "{{ netstatoutput }}"



I just need all the failed telnet  IPs  printed in the debug and nothing 
else like below:

  "msg": "Timeout when waiting for 10.9.72.162:22 
"
  "msg": "Timeout when waiting for 10.9.72.166:22 
"
  "msg": "Timeout when waiting for 10.9.42.162:22 
"



Can you please suggest how can I?

-- 
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/238f9d4d-5a8c-48c1-bccf-e440e8a969bao%40googlegroups.com.


[ansible-project] Ansible not accepting When condition

2020-07-02 Thread Jenisha T
Hi everyone,
Below is my playbook

---
- name: using multiple conditions
  gather_facts: yes
  hosts: localhost
  connection: local
  tasks:
- package:
name: httpd
state: installed
when:
  - ansible_distribution == "RedHat"
  - ansible_memfree_mb > 1512

When I run this playbook I get below error

https://pastebin.com/embed_iframe/BVRZKc5K; 
style="border:none;width:100%">



-- 
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/47b62adb-87ae-451c-b077-3cfeff5be26en%40googlegroups.com.


Re: [ansible-project] Regular Expression in ANSIBLE

2020-07-02 Thread T. JENISHA
It's solved. I was asking about regex.  But I couldn't see your solution.


Thankyou!

Best Regards
Jenisha T
Whatsapp: +91 07598087866





On Thu, 2 Jul 2020 at 15:10, Srinivas Naram 
wrote:

> Not sure how you are initiating your playbooks. Here is what I did.
>
> I initiated my playbooks from a shell script and parsed the output in the
> script.
>
> On Thu, Jul 2, 2020 at 2:03 PM Jenisha T  wrote:
>
>>
>> It's present in a remote server where the playbook is executed. I m
>> facing the problem with extraction. Text present in register.
>>
>> On Thursday, 2 July 2020 at 12:41:37 UTC+5:30 sriniva...@gmail.com wrote:
>>
>>> Hello - is this log file located in the server where Ansible is
>>> installed or remote server ?
>>>
>>> On Thu, Jul 2, 2020 at 5:25 AM Jenisha T  wrote:
>>>
 Hi
 I have output from log file as below. I need to extract the string
 shown in bold.

  Communication Diagnostic Report

 ---


 User Name : username

 Directory : /path/to/dir

 Platform Architecture : Linux

 Version : x.0.00.x

 Host Name : abcdef1234

 Logical Name : *abcdef1234*

 Listen to Network Interface : *ANY


 processes status

 ==

 Listener : *Running as root *


 How to extract the value of Logical Name : *abcdef1234 *

 from the multiline string.


 --
 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/cbdb83e6-d7b4-42ec-8d23-408736d0aeb2n%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/59adf33c-d9c4-4d74-83fc-2e07d2d8e5adn%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/CAG-N3P4Khqov%2B3OvwLLig6-s8sEiiGsS23KuhKMS%2BoHB7668hw%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/CAAGhZYgboeMGTtqwvPYqrWXT_RDXvsePLUXOWDB5MQxuwxeOrw%40mail.gmail.com.


Re: [ansible-project] Run Command On Each Host

2020-07-02 Thread 'Jitender J' via Ansible Project
Dont want ansible to print command as below  only need output , is it 
possible ?


changed: [zsn-ams2-clr-1b2]

cmd: spaceorg=`echo "25528960,28115152,28863788"|sed 's/,/ /g'`

bin/smmgr -s nameid=smid2name >> /sc/build/smid2namePostOUTPUT-32145.txt

for i in ${spaceorg[@]}; do echo $i && grep -w $i 
/sc/build/smid2namePostOUTPUT-32145.txt | wc -l; done

On Wednesday, July 1, 2020 at 6:42:06 PM UTC+5:30 brae...@gmail.com wrote:

> On 7/1/20 12:13 PM, 'Jitender J' via Ansible Project wrote:
> > 
> > Hi how can i access array in shell module trying to access as below but 
> not getting any output
> > 
> > 
> >   tasks:
> > 
> > - name:  verify that it shows the new cluster ID for this company in 
> active list and old cluster in inactive list
> >   shell:
> > spaceorg=`echo "{{ commaorg }}"|sed 's/,/ /g'`|for i in 
> ${spaceorg[@]} ; do echo $i ; /sc/bin/smmgr -s cid=$i -s
> > getsminfo=company_ssn 2>/dev/null|grep $i|grep -v Changing ; done
> >   args:
> > executable: /bin/bash
> > 
>
> Do yourself a favour and use a shell script on the target host.
>
> You can either create it with copy or template module.
>
> Your task above is hard to read and escaping all the special characters is 
> a difficult and superfluous venture.
>
> Regards
> Racke
>
> > 
> > 
> > 
> > On Tuesday, June 30, 2020 at 7:51:10 PM UTC+5:30 lorenze...@gmail.com 
> wrote:
> > 
> > Hello,
> > 
> > try this for printing command output. I don't know if you can hide the
> > other parts of output:
> > 
> > https://stackoverflow.com/a/24834231
> > 
> > On Tue, Jun 30, 2020 at 4:18 PM 'Jitender J' via Ansible Project
> >  wrote:
> > >
> > > Thanks for the update, i''ll try using multiple shell tasks, also can 
> you please let me know how to make ansible
> > not to print commands only print output of command
> > >
> > >
> > > On Tue, Jun 30, 2020 at 7:44 PM Luca 'remix_tj' Lorenzetto <
> lorenze...@gmail.com> wrote:
> > >>
> > >> Hello,
> > >>
> > >> ansible by default runs a task on all hosts and then waits for result
> > >> from everyone before going to the next step. If your task has a loop,
> > >> there's no way to run the loop synchronously between all nodes,
> > >> because is a single task with multiple options.
> > >>
> > >> You can split the commands in several shell tasks, instead one with a 
> loop.
> > >>
> > >> Luca
> > >>
> > >> On Tue, Jun 30, 2020 at 4:04 PM 'Jitender J' via Ansible Project
> > >>  wrote:
> > >> >
> > >> > Hi Team,
> > >> >
> > >> > I want to run multiple commands in shell module, but i want to run 
> 1st command on each hosts than move to next
> > command on each host than third and so on, so that i can get output of 
> same command together from all host at single
> > place, tried with loop (with_item)
> > >> > but no luck, need help
> > >> >
> > >> > Thanks
> > >> > jitender
> > >> >
> > >> > --
> > >> > 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/efe49a15-80e6-4d37-aab6-44793d1d4c58n%40googlegroups.com
> .
> > >>
> > >>
> > >>
> > >> --
> > >> "E' assurdo impiegare gli uomini di intelligenza eccellente per fare
> > >> calcoli che potrebbero essere affidati a chiunque se si usassero delle
> > >> macchine"
> > >> Gottfried Wilhelm von Leibnitz, Filosofo e Matematico (1646-1716)
> > >>
> > >> "Internet è la più grande biblioteca del mondo.
> > >> Ma il problema è che i libri sono tutti sparsi sul pavimento"
> > >> John Allen Paulos, Matematico (1945-vivente)
> > >>
> > >> Luca 'remix_tj' Lorenzetto, http://www.remixtj.net , <
> lorenze...@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-proje...@googlegroups.com.
> > >> To view this discussion on the web visit
> > 
> https://groups.google.com/d/msgid/ansible-project/CAKuX69pb9XuqTd%2Bieoit-GVQOF0BGvPjFVrioRvawut6Uc%3DDrw%40mail.gmail.com
> .
> > 
> > >
> > >
> > >
> > > --
> > > Regards,
> > > Jitender
> > >
> > > --
> > > 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/CAMO4JZtPxnaoGxJ6NTTr-EuLpQV9jwWt7ME75t-0Z%3DcjXq%2BKkA%40mail.gmail.com
> .
> > 
> > 
> > 
> > 
> > -- 
> > "E' assurdo impiegare gli uomini di intelligenza eccellente per fare
> > calcoli che potrebbero essere affidati a chiunque se si usassero delle
> > macchine"
> > Gottfried Wilhelm von Leibnitz, 

Re: [ansible-project] Trouble with quoting variables

2020-07-02 Thread Dick Visser
What does the correct version of the command line look like?

The docs seem to indicate a slightly different data structure, where
only IpRanges is added as a json list:
https://docs.aws.amazon.com/cli/latest/reference/ec2/authorize-security-group-ingress.html

I would try defining the data structure as a variable in your playbook
(as YAML, which is easier to read/write), and then combine to_json and
quote.


On Thu, 2 Jul 2020 at 14:05, Ed Greenberg  wrote:
>
> I have a shell command with json on it. I need some assistance, please, in 
> quoting it properly.
>
> This is an attempt to execute an aws command-line command.  I realize that 
> there are a massive number of aws aws modules, but unfortunately, my bota is 
> broken, so I can't use anything that relies on python making api calls.  
> Upcoming is a project to move to python 3 in the hopes of fixing pythons 
> ability to do api work.  So I'm stuck with command line.
>
> My playbook says:
>
> - name: add to Github Enterprise Security Group
>   shell: aws ec2 authorize-security-group-ingress --group-name 
> GithubHappy --ip-permissions '[{"IpProtocol": "tcp","FromPort":22,"ToPort": 
> 22,"IpRanges": [{"CidrIp": 
> "{{external}}/32","Description":"{{servername}}"}]}]'
>
>
> and my error reads:
> RROR! We were unable to read either as JSON nor YAML, these are the errors we 
> got from each:
> JSON: No JSON object could be decoded
>
> Syntax Error while loading YAML.
>   mapping values are not allowed in this context
>
> The error appears to be in '/usr/local/ansible/playbooks/newserver.yml': line 
> 28, column 112, but may
> be elsewhere in the file depending on the exact syntax problem.
>
> The offending line appears to be:
>
> - name: add to Github Enterprise Security Group
>   shell: aws ec2 authorize-security-group-ingress --group-name 
> GithubHappy --ip-permissions "'[{"IpProtocol": "tcp","FromPort":22,"ToPort": 
> 22,"IpRanges": [{"CidrIp": 
> "{{external}}/32","Description":"{{servername}}"}]}]'"
>   
>  ^ here
> We could be wrong, but this one looks like it might be an issue with
> missing quotes. Always quote template expression brackets when they
> start a value. For instance:
>
> with_items:
>   - {{ foo }}
>
> Should be written as:
>
> with_items:
>   - "{{ foo }}"
>
>
> I've tried quoting the entire thing with both single quotes and then with  
> double quotes, escaping the embedded quotes with backslashes. I've tried 
> putting quotes in jinja curlies. such as {{ '"' }} .  Just about every 
> permutation I can think of.
>
> Is this even possible?  Should I put the aws command in a shell script and 
> run that?   Inquiring minds want to know :)
> Thanks.
>
> Ed Greenberg
>
> --
> 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/78a51375-524b-4b83-9188-0fadbb22597bo%40googlegroups.com.



-- 
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

-- 
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/CAL8fbwOZ%3DfttbC_pk%3D6L3A4-O-7ZczH00BsFWdSz8H8dBo81wQ%40mail.gmail.com.


[ansible-project] Mapping Multiple attributes from Ansible query

2020-07-02 Thread Albert Short
Hi all,

I need to try to map multiple attributes from an ACI vrf query output.

---

- name: Test Play
  hosts: mgtapic
  gather_facts: no


  tasks:

- name: Query all VRFs
  aci_vrf:
host: "{{ ansible_host }}"
username: "{{ ansible_user }}"
password: "{{ ansible_password }}"
validate_certs: no
###
state: query
  delegate_to: localhost
  register: vrf_query

- debug:
msg:
  - "{{ vrf_query }}"
  - "{{ vrf_query.current[:] | 
map(attribute='fvCtx.attributes.name') | list }}"
  - "{{ vrf_query.current[:] | map(attribute='fvCtx.attributes.dn') 
| list }}"

I can get the single requested output for ,  & ,

[root@localhost ]# ansible-playbook aci_test.yml

PLAY [Test Play] 
***

TASK [Query all VRFs] 
**
Thursday 02 July 2020  13:08:42 +0100 (0:00:00.026)   0:00:00.026 
*
ok: [mgtapic01 -> localhost]

TASK [debug] 
***
Thursday 02 July 2020  13:08:43 +0100 (0:00:00.694)   0:00:00.721 
*
ok: [mgtapic01] =>
  msg:
  - changed: false
current:
- fvCtx:
attributes:
  annotation: ''
  bdEnforcedEnable: 'no'
  childAction: ''
  descr: ''
  dn: uni/tn-mgmt/ctx-oob
  extMngdBy: ''
  ipDataPlaneLearning: enabled
  knwMcastAct: permit
  lcOwn: local
  modTs: '2020-06-29T08:53:32.087+00:00'
  monPolDn: uni/tn-common/monepg-default
  name: oob
  nameAlias: ''
  ownerKey: ''
  ownerTag: ''
  pcEnfDir: ingress
  pcEnfDirUpdated: 'yes'
  pcEnfPref: enforced
  pcTag: '32770'
  scope: '2981888'
  seg: '2981888'
  status: ''
  uid: '0'
- fvCtx:
attributes:
  annotation: ''
  bdEnforcedEnable: 'no'
  childAction: ''
  descr: ''
  dn: uni/tn-mgmt/ctx-inb
  extMngdBy: ''
  ipDataPlaneLearning: enabled
  knwMcastAct: permit
  lcOwn: local
  modTs: '2020-06-29T08:53:32.087+00:00'
  monPolDn: uni/tn-common/monepg-default
  name: inb
  nameAlias: ''
  ownerKey: ''
  ownerTag: ''
  pcEnfDir: ingress
  pcEnfDirUpdated: 'yes'
  pcEnfPref: enforced
  pcTag: '32770'
  scope: '2686976'
  seg: '2686976'
  status: ''
  uid: '0'
- fvCtx:
attributes:
  annotation: ''
  bdEnforcedEnable: 'no'
  childAction: ''
  descr: ''
  dn: uni/tn-common/ctx-default
  extMngdBy: ''
  ipDataPlaneLearning: enabled
  knwMcastAct: permit
  lcOwn: local
  modTs: '2020-06-29T08:53:31.783+00:00'
  monPolDn: uni/tn-common/monepg-default
  name: default
  nameAlias: ''
  ownerKey: ''
  ownerTag: ''
  pcEnfDir: ingress
  pcEnfDirUpdated: 'yes'
  pcEnfPref: enforced
  pcTag: '49153'
  scope: '2883584'
  seg: '2883584'
  status: ''
  uid: '0'
- fvCtx:
attributes:
  annotation: ''
  bdEnforcedEnable: 'no'
  childAction: ''
  descr: ''
  dn: uni/tn-infra/ctx-overlay-1
  extMngdBy: ''
  ipDataPlaneLearning: enabled
  knwMcastAct: permit
  lcOwn: local
  modTs: '2020-06-29T08:53:30.437+00:00'
  monPolDn: uni/tn-common/monepg-default
  name: overlay-1
  nameAlias: ''
  ownerKey: ''
  ownerTag: ''
  pcEnfDir: ingress
  pcEnfDirUpdated: 'yes'
  pcEnfPref: enforced
  pcTag: '49153'
  scope: '16777199'
  seg: '16777199'
  status: ''
  uid: '0'
- fvCtx:
attributes:
  annotation: ''
  bdEnforcedEnable: 'no'
  childAction: ''
  descr: ''
  dn: uni/tn-common/ctx-copy
  extMngdBy: ''
  ipDataPlaneLearning: enabled
  knwMcastAct: permit
  lcOwn: local
  modTs: '2020-06-29T08:53:31.783+00:00'
  monPolDn: uni/tn-common/monepg-default
  name: copy
  nameAlias: ''
  ownerKey: ''
  ownerTag: ''
  pcEnfDir: ingress

[ansible-project] Trouble with quoting variables

2020-07-02 Thread Ed Greenberg
I have a shell command with json on it. I need some assistance, please, in 
quoting it properly.  

This is an attempt to execute an aws command-line command.  I realize that 
there are a massive number of aws aws modules, but unfortunately, my *bota* 
is broken, so I can't use anything that relies on python making api calls.  
Upcoming is a project to move to python 3 in the hopes of fixing pythons 
ability to do api work.  So I'm stuck with command line.

My playbook says:

- name: add to Github Enterprise Security Group
  shell: aws ec2 authorize-security-group-ingress --group-name 
GithubHappy --ip-permissions '[{"IpProtocol": "tcp","FromPort":22,"ToPort": 
22,"IpRanges": [{"CidrIp": 
"{{external}}/32","Description":"{{servername}}"}]}]'


and my error reads:
RROR! We were unable to read either as JSON nor YAML, these are the errors 
we got from each:
JSON: No JSON object could be decoded

Syntax Error while loading YAML.
  mapping values are not allowed in this context

The error appears to be in '/usr/local/ansible/playbooks/newserver.yml': 
line 28, column 112, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- name: add to Github Enterprise Security Group
  shell: aws ec2 authorize-security-group-ingress --group-name 
GithubHappy --ip-permissions "'[{"IpProtocol": 
"tcp","FromPort":22,"ToPort": 22,"IpRanges": [{"CidrIp": 
"{{external}}/32","Description":"{{servername}}"}]}]'"

   ^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:

with_items:
  - {{ foo }}

Should be written as:

with_items:
  - "{{ foo }}"


I've tried quoting the entire thing with both single quotes and then with  
double quotes, escaping the embedded quotes with backslashes. I've tried 
putting quotes in jinja curlies. such as {{ '"' }} .  Just about every 
permutation I can think of. 

Is this even possible?  Should I put the aws command in a shell script and 
run that?   Inquiring minds want to know :)
Thanks.

Ed Greenberg

-- 
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/78a51375-524b-4b83-9188-0fadbb22597bo%40googlegroups.com.


Re: [ansible-project] How to extract information from string

2020-07-02 Thread T. JENISHA
Thankyou Vladimir. Its working now


Best Regards
Jenisha T
Whatsapp: +91 07598087866





On Thu, 2 Jul 2020 at 14:54, Vladimir Botka  wrote:

> On Thu, 2 Jul 2020 13:59:13 +0530
> "T. JENISHA"  wrote:
>
> > - name: Ex grep
> >   gather_facts: yes
> >   hosts: localhost
> >   connection: local
> >   tasks:
> >
> > - name: Run ag_diag_comm
> >   command: cat "ag_diag.txt"
> >   register: ag_diag
> >
> > - set_fact:
> >   . my_agent: "{{ my_agent|default({})|
> >   .  combine({my_key: my_val}) }}"
> >   . loop: "{{ my_data.splitlines()|
> >   .select('match', my_regex)|
> >   .list }}"
> >   . vars:
> >   .   my_regex: '^(.*?):(.*)$'
> >   .   my_key: "{{ item|
> >   .regex_replace(my_regex, '\\1')|
> >   .trim|
> >   .regex_replace(' ', '_') }}"
> >   .   my_val: "{{ item|
> >   .regex_replace(my_regex, '\\2')|
> >   .trim }}"
> > - debug:
> > var: my_agent
> > - debug:
> > var: my_agent.Logical_Agent_Name
> >
> > fatal: [localhost]: FAILED! => {"msg": "The task includes an option with
> an
>
> > > Fix it. The code below works as expected. Mind the indentation.
> > >
> > > - set_fact:
> > >   . my_agent: "{{ my_agent|default({})|
> > >   .   combine({my_key: my_val}) }}"
> > >   loop: "{{ my_data.splitlines()|
> > >   . select('match', my_regex)|
> > >   . list }}"
> > >   vars:
> > >   . my_regex: '^(.*?):(.*)$'
> > >   . my_key: "{{ item|
> > >   . regex_replace(my_regex, '\\1')|
> > >   . trim|
> > >   . regex_replace(' ', '_') }}"
> > >   . my_val: "{{ item|
> > >   . regex_replace(my_regex, '\\2')|
> > >   . trim }}"
> > > - debug:
> > > var: my_agent
> > > - debug:
> > > var: my_agent.Logical_Agent_Name
>
> Fix the indentation. I've put the dots '.' into the code to make the
> comparison easier. In addition to this, use your registered data in the
> loop
>
>loop: "{{ ag_diag.stdout_lines|
>
> For your convenience the code is also here
> https://gist.github.com/vbotka/1e68ef07627dc37b252553b6d838ed20
>
> --
> 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/CAAGhZYgms5X_vChFry3eLbNZnnodrhVcyawB5GdLutqHbLrgKQ%40mail.gmail.com.


[ansible-project] action plugin: modify task_vars?

2020-07-02 Thread Gregory Christy
Hello everybody,

I have a custom module and would like to set the ansible_python_interpreter 
variable 
from within a corresponding action plugin.
This is what I do in the action plugin:

task_vars_modified = task_vars.copy()
task_vars_modified['ansible_python_interpreter'] = ''
result = merge_hash(result, self._execute_module(module_args=module_args, 
task_vars=task_vars_modified))

Unfortunately this has no effect. Using the playbook debugger I can verify 
that ansible_python_interpreter is not set for the module.
I am sure that the action plugin is called.
What am I doing wrong?
Is it possible at all to modify task_vars? I cannot find an example for 
this approach.

Background:
My custom module makes use of some python modules. I do not want to install 
these modules globally so I'm using a virtual environment.
Obviously now the ansible module needs to use the python binary within the 
virtual environment.
I would like to encapsulate this so that the user does not have to remember 
to set ansible_python_interpreter each time he uses the module.

Thanks and Regards,
Carsten

-- 
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/12ecebdd-cabd-49ea-8eb4-725cd3b086fbo%40googlegroups.com.


Re: [ansible-project] Reboot servers strategy.

2020-07-02 Thread Moritz Kobel
Hi,

on our setup we reboot our servers groupwise.
With serial: 1 is ensured only one server is rebooted a time.
The reboot is only performed if /var/run/reboot-required exists. This
might be Debian specific. This 'when' condition could give you an idea
how to handle server specific facts.

--8<
- hosts:
- sensu_servers
- build_servers
- db_servers
- lamp_servers
- app_servers
- mail_servers
- web_servers
  become: true
  serial: 1
  tasks:
- name: check if reboot-required exists
  stat:
path: /var/run/reboot-required
  register: reboot_required
- name: reboot
  reboot:
  when: reboot_required.stat.exists
--8<

Check out the reboot module for further parameters like
'post_reboot_delay' or 'test_command':
https://docs.ansible.com/ansible/latest/modules/reboot_module.html

I hope this helps.


-- Moritz

Am Mittwoch den 01. Juli 2020 schrieb Rafael Tomelin:

> Hi,
> 
> I get all servers from Azure and created inventory in memory by ansible.
> After get server and created inventory, connect in all servers collection
> facts and execute update of servers.  This moment I need to create a
> process to reboot my servers by custom facts.
> 
> 
> On Tue, Jun 30, 2020 at 4:53 PM John Petro  wrote:
> 
> > Are you using ansible to apply updates and reboot now?  If so, what does
> > your current process look like?
> >
> > --john
> >
> > On Mon, Jun 29, 2020 at 3:26 PM Rafael Tomelin 
> > wrote:
> >
> >>
> >> Hi Guys,
> >> I have periodic updates on all RedHat servers at the same time, I need to
> >> create a strategy to restart my clusters because I can't stop my
> >> application and services.
> >>
> >> How to create the reboot strategy server-per-server in clusters?
> >>
> >>
> >> --
> >> Atenciosamente,
> >>
> >> Rafael Tomelin
> >> Tel.: 51-984104084
> >> Skype: rafael.tomelin
> >>
> >> LPI ID: LPI000191271
> >> Red Hat Certified Engineer
> >> Puppet Professional 2017 Certification
> >>
> >> --
> >> 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/CAGEUqbAwBVcpuWsULocMZ2ts4-298wqjmkkEvhRhRSDaFdnHPQ%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/CAPAjob-WzDS9BXVnGCvhS%3DXS%2B179f7mf-nJEbMQA-5-4_kZtmA%40mail.gmail.com
> > 
> > .
> >
> 
> 
> -- 
> Atenciosamente,
> 
> Rafael Tomelin
> Tel.: 51-984104084
> Skype: rafael.tomelin
> 
> LPI ID: LPI000191271
> Red Hat Certified Engineer
> Puppet Professional 2017 Certification
> 
> -- 
> 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/CAGEUqbCehhAhS6c-H40Dx5bPLfX5mJEF9Zkc%2BdocnpKnpYB8SQ%40mail.gmail.com.

-- 
   <\ __@  __@
 \ __   _-\<, -\<,_
http://www.tandemblog.ch 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/20200702111940.GA3727695%40moturau.office.itds.ch.


[ansible-project] Re: Add Additional Ip Addresses to an interface.

2020-07-02 Thread Paul Robinson

Managed to resolve this myself with the following playbook

cat network-ip-config.yml
---
- hosts: all
  remote_user: root

  tasks:
  - name: Create IP Address list
set_fact:
  addr_var1: "{{ guest_custom_ip + '/24' }}"
  addr_var2: "{{ virtual_alias_ip.split(', ')[0] + '/24' }}"
  addr_var3: "{{ virtual_alias_ip.split(', ')[1] + '/24' }}"
  addr_var4: "{{ virtual_alias_ip.split(', ')[2] + '/24' }}"

  - debug:
  var: addr_var1

  - debug:
  var: addr_var2

  - debug:
  var: addr_var3

  - debug:
  var: addr_var4


  - name: Pass variables to role
include_role:
  name: linux-system-roles.network
vars:
  network_provider: nm
  network_connections:
  - name: ens192
type: ethernet
interface_name: ens192
autoconnect: yes
ip:
  address:
  - "{{ addr_var1 }}"
  - "{{ addr_var2 }}"
  - "{{ addr_var3 }}"
  - "{{ addr_var4 }}"
  auto6: no
  dns:
  - X.X.X.X
  - 1.1.1.1
  dns_search:
  - example.co.uk

  - name: Unconditionally reboot the machine with all defaults
reboot:


On Tuesday, June 30, 2020 at 11:57:43 AM UTC+1 Paul Robinson wrote:

> Firstly just to say I'm new to ansible and learning as I go along.
>
> I have configure a playbook that clones 3 virtual machines using the 
> following inventory file which has a few custom variables added for my needs
>
> ansible-playbook -i vms-to-deploy deploy_sap_vm.yml
>
> vms-to-deploy
> [netweaver]
> prcsapnwd01 deploy_vsphere_datastore='datastore2' 
> guest_custom_ip='10.0.14.20' sap_sid='NWD' 
> virtual_alias_ip='10.0.14.21,10.0.14.22,10.0.14.23'
> prcsapnwq01 deploy_vsphere_datastore='datastore2' 
> guest_custom_ip='10.0.14.30' sap_sid='NWQ' 
> virtual_alias_ip='10.0.14.31,10.0.14.32,10.0.14.33'
> prcsapnwp01 deploy_vsphere_datastore='datastore2' 
> guest_custom_ip='10.0.14.40' sap_sid='NWP' 
> virtual_alias_ip='10.0.14.41,10.0.14.32,10.0.14.43'
>
> I have successfully managed to clone the vm's using vmware_guest role 
> which then customizes the virtual machines and assigns the guest_custom_ip 
> to be the ip of the physical interface eth0
>
> The next task I want to perform is to add additional ip addresses to that 
> adapter eth0 so for example in the case of host prcsapnwd01 eth0 has
>
> eth0:
> 10.0.14.20 (Phsyical Host)
> 10.0.14.21 (Virtual Alias IP)
> 10.0.14.22 (Virtual Alias IP)
> 10.0.14.23 (Virtual Alias IP)
>
> The linux-system-roles.network looks like it can do the job for me.
>
> I am just not sure how i go about reading the additional ip addresses from 
> my inventory file and passing them to the task variables.
>
> Any help would be appreciated. 
>

-- 
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/30dff693-7a2f-41ec-9736-f142884fbfdfn%40googlegroups.com.


Re: [ansible-project] How to structure variables to distinguish different environments

2020-07-02 Thread Srinivas Naram
There could be some distinction between both the environments. Can you use
gather_facts and get the differentiating value ?

if you are able to get it using gather_facts, you can use set_facts

Example

set_facts:
   nfs_server: xyx
when: ansible_distribution= 'CentOS'

set_fact:
   nfs_server: abc
when: ansible_distribution ='Ubuntu'

On Thu, Jul 2, 2020 at 12:26 AM Xinhuan Zheng 
wrote:

> Hello,
>
> I want to define a variable for playbook in *group_vars/server_genre*
> file. However, I don't know if Ansible can support something like
> server_genre@environment syntax notation. Here is the detail:
>
> *In inventory/environment*:
> ---
> [server_genre]
> myserver1.example.com
>
> *In group_vars/server_genre:*
> ---
> nfs_server: mynfsserver1.example.com
>
> *In server_genre.yml playbook:*
> ---
> - name: Playbook for server_genre
>   hosts: server_genre
>   gather_facts: yes
>
>   tasks:
>
>   - name: Install Nfs client
> package:
>   name: nfs-utils
>   state: present
>   - name: mount nfs
> mount:
>   path: /mymount
>   src: "{{ nfs_server }}"
>   fstype: nfs
>   opts: ro
>   state: mounted
>
> In a different environment, the variable {{ nfs_server }} will have
> different value, however, I can't separate the different values using one
> single group_var/server_genre file, unless Ansible supports something like
> group_vars/server_genre@enviornment.
>
> How do I accomplish the variable value distinction in my case?
>
> Thanks,
>
> - Xinhuan
>
>
> --
> 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/96edc459-2fec-4626-b7ac-2dae6d330505o%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/CAG-N3P5BygF3JiJAa6LXsMJ4798w6kH5OtVYJtRg5U-7uHnQog%40mail.gmail.com.


Re: [ansible-project] Regular Expression in ANSIBLE

2020-07-02 Thread Srinivas Naram
Not sure how you are initiating your playbooks. Here is what I did.

I initiated my playbooks from a shell script and parsed the output in the
script.

On Thu, Jul 2, 2020 at 2:03 PM Jenisha T  wrote:

>
> It's present in a remote server where the playbook is executed. I m facing
> the problem with extraction. Text present in register.
>
> On Thursday, 2 July 2020 at 12:41:37 UTC+5:30 sriniva...@gmail.com wrote:
>
>> Hello - is this log file located in the server where Ansible is installed
>> or remote server ?
>>
>> On Thu, Jul 2, 2020 at 5:25 AM Jenisha T  wrote:
>>
>>> Hi
>>> I have output from log file as below. I need to extract the string shown
>>> in bold.
>>>
>>>  Communication Diagnostic Report
>>>
>>> ---
>>>
>>>
>>> User Name : username
>>>
>>> Directory : /path/to/dir
>>>
>>> Platform Architecture : Linux
>>>
>>> Version : x.0.00.x
>>>
>>> Host Name : abcdef1234
>>>
>>> Logical Name : *abcdef1234*
>>>
>>> Listen to Network Interface : *ANY
>>>
>>>
>>> processes status
>>>
>>> ==
>>>
>>> Listener : *Running as root *
>>>
>>>
>>> How to extract the value of Logical Name : *abcdef1234 *
>>>
>>> from the multiline string.
>>>
>>>
>>> --
>>> 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/cbdb83e6-d7b4-42ec-8d23-408736d0aeb2n%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/59adf33c-d9c4-4d74-83fc-2e07d2d8e5adn%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/CAG-N3P4Khqov%2B3OvwLLig6-s8sEiiGsS23KuhKMS%2BoHB7668hw%40mail.gmail.com.


Re: [ansible-project] How to extract information from string

2020-07-02 Thread Vladimir Botka
On Thu, 2 Jul 2020 13:59:13 +0530
"T. JENISHA"  wrote:

> - name: Ex grep
>   gather_facts: yes
>   hosts: localhost
>   connection: local
>   tasks:
> 
> - name: Run ag_diag_comm
>   command: cat "ag_diag.txt"
>   register: ag_diag
> 
> - set_fact:
>   . my_agent: "{{ my_agent|default({})|
>   .  combine({my_key: my_val}) }}"
>   . loop: "{{ my_data.splitlines()|
>   .select('match', my_regex)|
>   .list }}"
>   . vars:
>   .   my_regex: '^(.*?):(.*)$'
>   .   my_key: "{{ item|
>   .regex_replace(my_regex, '\\1')|
>   .trim|
>   .regex_replace(' ', '_') }}"
>   .   my_val: "{{ item|
>   .regex_replace(my_regex, '\\2')|
>   .trim }}"
> - debug:
> var: my_agent
> - debug:
> var: my_agent.Logical_Agent_Name
>
> fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an

> > Fix it. The code below works as expected. Mind the indentation.
> >  
> > - set_fact:
> >   . my_agent: "{{ my_agent|default({})|
> >   .   combine({my_key: my_val}) }}"
> >   loop: "{{ my_data.splitlines()|
> >   . select('match', my_regex)|
> >   . list }}"
> >   vars:
> >   . my_regex: '^(.*?):(.*)$'
> >   . my_key: "{{ item|
> >   . regex_replace(my_regex, '\\1')|
> >   . trim|
> >   . regex_replace(' ', '_') }}"
> >   . my_val: "{{ item|
> >   . regex_replace(my_regex, '\\2')|
> >   . trim }}"
> > - debug:
> > var: my_agent
> > - debug:
> > var: my_agent.Logical_Agent_Name  

Fix the indentation. I've put the dots '.' into the code to make the
comparison easier. In addition to this, use your registered data in the loop

   loop: "{{ ag_diag.stdout_lines|

For your convenience the code is also here
https://gist.github.com/vbotka/1e68ef07627dc37b252553b6d838ed20

-- 
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/20200702112417.0974f64d%40gmail.com.


pgpAo2m1blNnq.pgp
Description: OpenPGP digital signature


Re: [ansible-project] Regular Expression in ANSIBLE

2020-07-02 Thread Jenisha T

It's present in a remote server where the playbook is executed. I m facing 
the problem with extraction. Text present in register.

On Thursday, 2 July 2020 at 12:41:37 UTC+5:30 sriniva...@gmail.com wrote:

> Hello - is this log file located in the server where Ansible is installed 
> or remote server ?
>
> On Thu, Jul 2, 2020 at 5:25 AM Jenisha T  wrote:
>
>> Hi
>> I have output from log file as below. I need to extract the string shown 
>> in bold. 
>>
>>  Communication Diagnostic Report
>>
>> ---
>>
>>
>> User Name : username
>>
>> Directory : /path/to/dir
>>
>> Platform Architecture : Linux
>>
>> Version : x.0.00.x
>>
>> Host Name : abcdef1234
>>
>> Logical Name : *abcdef1234*
>>
>> Listen to Network Interface : *ANY
>>
>>
>> processes status
>>
>> ==
>>
>> Listener : *Running as root * 
>>
>>
>> How to extract the value of Logical Name : *abcdef1234 *
>>
>> from the multiline string. 
>>
>>
>> -- 
>> 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/cbdb83e6-d7b4-42ec-8d23-408736d0aeb2n%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/59adf33c-d9c4-4d74-83fc-2e07d2d8e5adn%40googlegroups.com.


Re: [ansible-project] Regular Expression in ANSIBLE

2020-07-02 Thread Srinivas Naram
Hello - is this log file located in the server where Ansible is installed
or remote server ?

On Thu, Jul 2, 2020 at 5:25 AM Jenisha T  wrote:

> Hi
> I have output from log file as below. I need to extract the string shown
> in bold.
>
>  Communication Diagnostic Report
>
> ---
>
>
> User Name : username
>
> Directory : /path/to/dir
>
> Platform Architecture : Linux
>
> Version : x.0.00.x
>
> Host Name : abcdef1234
>
> Logical Name : *abcdef1234*
>
> Listen to Network Interface : *ANY
>
>
> processes status
>
> ==
>
> Listener : *Running as root *
>
>
> How to extract the value of Logical Name : *abcdef1234 *
>
> from the multiline string.
>
>
> --
> 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/cbdb83e6-d7b4-42ec-8d23-408736d0aeb2n%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/CAG-N3P4X4NPOv%2B_QxQLtvELH%3DDomxCWr0weNY%2Bh1vLZnE7Pi3Q%40mail.gmail.com.