Re: [ansible-project] creating RSA key with openssh_keypair

2024-08-01 Thread Veera


Yes  ,  We need a RSA format PEM key  which is compatible with the 
application . 
 Whenever a OPENSSH PRIVATE  Key generated with the playbook is used for 
authentication ,  login to the application  is working but its not  
functioning 100% as expected . 
When a RSA format PEM or id_rsa key ( ssh-keygen -t rsa -b 2048) is used  
then login and functioning of the application is working fine.  (vendor 
recommended RSA format SSH key)


  
On Thursday, August 1, 2024 at 7:51:33 PM UTC+5:30 Felix Fontein wrote:

> Hi,
>
> > However the public-key is showing the caption as ssh-rsa .. and the
> > private key is displaying the label as "-BEGIN OPENSSH PRIVATE
> > KEY- and -END OPENSSH PRIVATE KEY-"
> > 
> > I am looking to create an rsa key-pairs with 2048b , something we
> > used to create with the command ssh-keygen -t rsa -b 2048
> > The private key must begin with "-BEGIN RSA PRIVATE KEY-" and
> > ends with "-END RSA PRIVATE KEY-"
>
> Could you please elaborate why it **must** start with "-BEGIN RSA
> PRIVATE KEY-"? Does your SSH version not accept "-BEGIN OPENSSH
> PRIVATE KEY-"?
>
> In any case, I would suggest to look at the private_key_format option
> of the module.
>
> All the best,
> Felix
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/5d6af433-700c-46c0-865c-68c2b334209cn%40googlegroups.com.


[ansible-project] creating RSA key with openssh_keypair

2024-08-01 Thread Veera
Hi,

When I try to create ssh keypairs with  the 
module ansible.builtin.openssh_keypair , a new  key  pair is generated  as 
expected.

$ cat  test_key1.yml
---
- name: Validate RSA key creation
  hosts: localhost
  gather_facts: no
  vars:
keyfile: "mykey"
  tasks:
- name: create new keypair
  ansible.builtin.openssh_keypair:
path: "./{{ keyfile }}"
force: true
comment: "myk...@myorg.com"
type: rsa
size: 2048
  register: newkey
  no_log: false


- name: print the output file
  debug:
msg: "{{lookup('file', 'mykey')}}"

- name: print the pub key
  debug:
var: newkey.public_key
$
$
$ ap test_key1.yml
[WARNING]: provided hosts list is empty, only localhost is available. Note 
that the implicit localhost does not match 'all'

PLAY [Validate RSA key creation] 
**

TASK [create new keypair] 
*
changed: [localhost]

TASK [print the output file] 
**
ok: [localhost] => {
"msg": "-BEGIN OPENSSH PRIVATE KEY-\n
b3BlbnNzaC1rZXktdjEABG5vbmUEbm9uZQABAAABFwdzc2gtcn\n
NhAwEAAQAAAQEAuxikjvE7gthJQqNpDRmUZlFr6INoQv38QPWL2TA8so5rStPwv0/Q\n
+JhDCnXV16WmPhVN+ZX+cC6RyoHa5mzZY4WocJfGbQ553plcTteHt3j5FFLwbwTeYdeDaX\n
3xB904SCneXVbYjjO/HSLOB7emasY4NIpj24Lq7J06v2/p+tL3yTqqa9oFH94+EYRp/awu\n
LDJ784dVUUR7pEUpWCeNy6PhENfYIzQdzS9xq/fEwLYl6d7cHZoKpOx/WORFyhtkMfvzi5\n
JYCt9UVMfI+wpjJ9tOI/1tOO8YYg53naqfPLTdwTxsqP05hcCKyJyQYerh2GuLZzUSA/Gm\n
vIkJ0O+p/QAAA8iLqnKti6pyrQdzc2gtcnNhAAABAQC7GKSO8TuC2ElCo2kNGZRmUW\n
vog2hC/fxA9YvZMDyyjmtK0/C/T9D4mEMKddXXpaY+FU35lf5wLpHKgdrmbNljhahwl8Zt\n
DnnemVxO14e3ePkUUvBvBN5h14NpffEH3ThIKd5dVtiOM78dIs4Ht6Zqxjg0imPbgursnT\n
q/b+n60vfJOqpr2gUf3j4RhGn9rC4sMnvzh1VRRHukRSlYJ43Lo+EQ19gjNB3NL3Gr98TA\n
tiXp3twdmgqk7H9Y5EXKG2Qx+/OLklgK31RUx8j7CmMn204j/W047xhiDnedqp88tN3BPG\n
yo/TmFwIrInJBh6uHYa4tnNRID8aa8iQnQ76n9AwEAAQAAAQB5FNiifXHjGvBGhRSe\n
WriUgwsPvcNC37ZZn89yrmoJsGu1UHYUiaYWzAtPALV0ywpMUWNWLAEvPqQxZ1pwF2+Und\n
JFk6PhviWWrq9zgr6dOVgRFB/v6Tm2HlA4fD35tewPn7D9vQ+G7+w2AelOS0cTANctAYbg\n
b9hzasmzTM0i+jv4GEDS/zldh8YhDIPIOBctyevjW1Pcx2ttP9pfcaSbpH8t0Cq8AcRKUa\n
tYUlf6IvgJxSjfLF3w6ozteV10esfG372of5ssJFHaTZCnA+3vRRnEr420zYRVTARfJ3qQ\n
/c+EPcqiHf2D90GZ3b/UGdcSGf3Nl/Vs7fcTX+1IxoqhgQCzaY67BHjhlJUQftgdQG\n
xYUjhCxsR1XemXtfdmxavDKraPUnA3iIu4PAv3rUfcT0dY+vrI7TQlrZTDq9C0HdLyC3EY\n
ISzjW72dRzSr0qYAlTbzKYsvon/NukD/qCgWlcn1HMwZtlH4alCIKcjCJs49HYKl1kyzeE\n
AFNI6cRSW5pgAAAIEA30cx2Saxjmz50t1Q7pSuJJPx27a4ktuSljsavlYUeLnnXHZsXveX\n
HLojVoL3EV97Cn2dH1kJ5uSU2rf7UX0dw2MNLzIfM8RmpoKRrKqUS6mwI8pINy7hqctodS\n
u6Y/1lrRU1zwUJiPBIxqFqN4NC0fp9lRXydEf3kmddHLu7OPUAAACBANaEADRqAcDbbzjX\n
cA8qBtjzx65Jkn76WAbPMdH9lvvzxgy6iOB5NrGztfIj7a4I/6cQjWlTY4WOG9cpLKKWfo\n
wNkenr3d7GCXAKQ5z3N5vMWenC/vL6eoFyGV0Evn3Lz3YxZ6xvWGzFXSy66SholaIlngwx\n
qGMYqVyLQlbjPafpEG15a2V5c0BteW9yZy5jb20BAg==\n-END OPENSSH PRIVATE 
KEY-"
}

TASK [print the pub key] 
**
ok: [localhost] => {
"newkey.public_key": "ssh-rsa 
B3NzaC1yc2EDAQABAAABAQC7GKSO8TuC2ElCo2kNGZRmUWvog2hC/fxA9YvZMDyyjmtK0/C/T9D4mEMKddXXpaY+FU35lf5wLpHKgdrmbNljhahwl8ZtDnnemVxO14e3ePkUUvBvBN5h14NpffEH3ThIKd5dVtiOM78dIs4Ht6Zqxjg0imPbgursnTq/b+n60vfJOqpr2gUf3j4RhGn9rC4sMnvzh1VRRHukRSlYJ43Lo+EQ19gjNB3NL3Gr98TAtiXp3twdmgqk7H9Y5EXKG2Qx+/OLklgK31RUx8j7CmMn204j/W047xhiDnedqp88tN3BPGyo/TmFwIrInJBh6uHYa4tnNRID8aa8iQnQ76n9"
}

PLAY RECAP 

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



However the public-key is showing the caption as ssh-rsa .. and the private 
key is displaying the  label as "-BEGIN OPENSSH PRIVATE KEY-  
and  -END OPENSSH PRIVATE KEY-"

I am looking  to create an rsa key-pairs with 2048b  ,  something we used 
to create with the command  ssh-keygen -t rsa -b 2048
The private key must begin with "-BEGIN RSA PRIVATE KEY-" and  ends 
with "-END RSA PRIVATE KEY-"

Is that possible with this module openssh_keypair ?




-- 
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/7bfb2bc8-2052-402f-83f1-4ad37c13239dn%40googlegroups.com.


Re: [ansible-project] Formatting multiple lines using variable as loop

2023-12-15 Thread Veera
Thanks Todd for the details ...


On Saturday, December 16, 2023 at 1:30:25 AM UTC+5:30 Todd Lewis wrote:

> You said, "However the split happens based on ',' , and then we remove 
> the quotes with  map('map', 'trim')) and align the lines with range."
>
> It's true that "split(',')" will split a string containing commas into a 
> list of strings. But the trim filter does nothing with quotes.
>
> Rather, "trim" removes leading and trailing spaces from the string piped 
> into it:
>   a_string | trim
>
> Further, "map('trim')" removes leading and trailing spaces from each 
> string of the list of strings passed to it:
>   [str0, str1, str2] | map('trim')
>
> Finally, "map('map', 'trim')" trims strings two levels deep in lists:
>   [[sa0, sa1], [sb0, bs1], [sc0, sc1]] | map('map', 'trim')
>
> Quotes never play into it. In fact, in what you initially posted, and in 
> my response, the string data contain no quotes.
>
> Also, "range" isn't to align anything. It provides the necessary first 
> parameter to the "extract" filter.
>
> However assuming split with delimiter as comma,  when i try to replace 1 
> with 0  the output is  [msg: "{{ range(my_var | length) | map('extract', 
> (my_var | map('split', ',') | map('map', 'trim')), [*0*]) }}"]
>
> Yes, you changed the "1" to a "0", so you get the first (index=0) item in 
> the list produced by the split.
>
> When it was "1", you got the second item (index=1) in each list produced 
> by the split, that is "color-red", "color-blue", and "color-orange". From 
> your initial post, that's what I thought you wanted.
>
> If what you really want is this:
> new_var:
> - line1 has color-red
> - line2 has color-blue
> - line3 has color-orange
> then you can use this instead:
>
> - name: First and Second parts from split on comma
>   ansible.builtin.set_fact:
> new_var: "{{ my_var | map('regex_replace', '^([^,]*),([^,]*),.*', 
> '\\1 \\2') | map('regex_replace', ' +', ' ') }}"
>
>
>
> On 12/15/23 12:15 PM, Veera wrote:
>
> Hi  Todd Lewis,
>
> Thanks . I am able to understand it . However the split happens based on 
> ',' , and then we remove the quotes with  map('map', 'trim')) and align 
> the lines with range.
> However assuming split with delimiter as comma,  when i try to replace 1 
> with 0  the output is  [msg: "{{ range(my_var | length) | map('extract', 
> (my_var | map('split', ',') | map('map', 'trim')), [0]) }}"]
>  
> ok: [localhost] =>
>   msg:
>   - line1 has
>   - line2 has
>   - line3 has
>
> and when tried to add [0 1] in the  end  [msg: "{{ range(my_var | length) 
> | map('extract', (my_var | map('split', ',') | map('map', 'trim')), [0 1]) 
> }}"]
> it printsok: [localhost] =>
>   msg:
>   - i
>   - i
>   - i
> that is second character in the word line[0]. Is not the split breaks the 
> words  with (',')?
> How to print all the available column? instead of 1( yes the full  file 
> without a comma now )
> Actually I am trying to print like below
>
> line1 has  color-red
> line2 has  color-blue  
> line3 has  color-orange
>
> On Friday, December 15, 2023 at 10:42:43 PM UTC+5:30 Veera wrote:
>
>> Hi  Todd Lewis, 
>>
>> Thanks . I am able to understand it . However the split happens based on 
>> ',' , and then we remove the quotes with  map('map', 'trim')) and align 
>> the lines with range.
>> However assuming split with delimiter as comma,  when i try to replace 1 
>> with 0  the output is  [msg: "{{ range(my_var | length) | map('extract', 
>> (my_var | map('split', ',') | map('map', 'trim')), [1]) }}"]
>>  
>> ok: [localhost] =>
>>   msg:
>>   - line1 has
>>   - line2 has
>>   - line3 has
>>
>> and when tried to add [0 1] in the  end  [msg: "{{ range(my_var | 
>> length) | map('extract', (my_var | map('split', ',') | map('map', 'trim')), 
>> [0 1]) }}"]
>> it printsok: [localhost] =>
>>   msg:
>>   - i
>>   - i
>>   - i
>> that is second cha

Re: [ansible-project] Formatting multiple lines using variable as loop

2023-12-15 Thread Veera
Hi  Todd Lewis,

Thanks . I am able to understand it . However the split happens based on 
',' , and then we remove the quotes with  map('map', 'trim')) and align the 
lines with range.
However assuming split with delimiter as comma,  when i try to replace 1 
with 0  the output is  [msg: "{{ range(my_var | length) | map('extract', 
(my_var | map('split', ',') | map('map', 'trim')), [0]) }}"]
 
ok: [localhost] =>
  msg:
  - line1 has
  - line2 has
  - line3 has

and when tried to add [0 1] in the  end  [msg: "{{ range(my_var | length) | 
map('extract', (my_var | map('split', ',') | map('map', 'trim')), [0 1]) 
}}"]
it printsok: [localhost] =>
  msg:
  - i
  - i
  - i
that is second character in the word line[0]. Is not the split breaks the 
words  with (',')?
How to print all the available column? instead of 1( yes the full  file 
without a comma now )
Actually I am trying to print like below

line1 has  color-red
line2 has  color-blue  
line3 has  color-orange

On Friday, December 15, 2023 at 10:42:43 PM UTC+5:30 Veera wrote:

> Hi  Todd Lewis,
>
> Thanks . I am able to understand it . However the split happens based on 
> ',' , and then we remove the quotes with  map('map', 'trim')) and align 
> the lines with range.
> However assuming split with delimiter as comma,  when i try to replace 1 
> with 0  the output is  [msg: "{{ range(my_var | length) | map('extract', 
> (my_var | map('split', ',') | map('map', 'trim')), [1]) }}"]
>  
> ok: [localhost] =>
>   msg:
>   - line1 has
>   - line2 has
>   - line3 has
>
> and when tried to add [0 1] in the  end  [msg: "{{ range(my_var | length) 
> | map('extract', (my_var | map('split', ',') | map('map', 'trim')), [0 1]) 
> }}"]
> it printsok: [localhost] =>
>   msg:
>   - i
>   - i
>   - i
> that is second character in the word line[0]. Is not the split breaks the 
> words  with (',')?
> How to print all the available column? instead of 1( yes the full  file 
> without a comma now )
> Actually I am trying to print like below
>  line1 has  color-red
> line2 has color-blue  
> line3 has, color-orange
>
>
>
> On Friday, December 15, 2023 at 2:44:45 AM UTC+5:30 Todd Lewis wrote:
>
>> In the code below, note that "range(my_var | length)" is equivalent to "[0, 
>> 1, 2]".
>>
>> In the set_fact, we don't "loop" the task; rather we loop over the data 
>> within the jinja2 expression by using the map filter.
>>
>> utoddl@tango:~/ansible*$ cat veera01.yml*
>> ---
>> # veera01.yml
>> - name: Jinja expressions
>>   hosts: localhost
>>   gather_facts: false
>>   vars:
>> my_var:
>>   - "line1 has , color-red, in  its   middle"
>>   - "line2 has,   color-blue,   in its middle"
>>   - "line3 has,  color-orange, in its middle"
>>   tasks:
>> - name: Split and trim parts from my_var
>>   ansible.builtin.debug:
>> msg: "{{ my_var | map('split', ',') | map('map', 'trim') }}"
>>
>> - name: Extract the "color-*" parts from my_var
>>   ansible.builtin.debug:
>> msg: "{{ range(my_var | length) | map('extract', (my_var | 
>> map('split', ',') | map('map', 'trim')), [1]) }}"
>>
>> - name: Same but as set_fact
>>   ansible.builtin.set_fact:
>> new_var: "{{ range(my_var | length) | map('extract', (my_var | 
>> map('split', ',') | map('map', 'trim')), [1]) }}"
>>
>>
>> utoddl@tango:~/ansible*$ ansible-playbook veera01.yml -v*
>> Using /etc/ansible/ansible.cfg as config file
>>
>> PLAY [Jinja expressions] **
>>
>> TASK [Split and trim parts from my_var] ***
>> ok: [localhost] => 
>>   msg:
>>   - - line1 has
>> - color-red
>> - in  its   middle
>>   - - line2 has
>> - color-blue
>> - in its middle
>>   - - line3 has
>> - color-orange
>> - in its middle
>>
>> TASK [Extract the "color-*" parts from my_var] 
>> ok: [localhost] => 
>>   msg:
>>   - color-red
>>   - color-blue
>>   - color-o

Re: [ansible-project] Formatting multiple lines using variable as loop

2023-12-15 Thread Veera
Hi  Todd Lewis,

Thanks . I am able to understand it . However the split happens based on 
',' , and then we remove the quotes with  map('map', 'trim')) and align the 
lines with range.
However assuming split with delimiter as comma,  when i try to replace 1 
with 0  the output is  [msg: "{{ range(my_var | length) | map('extract', 
(my_var | map('split', ',') | map('map', 'trim')), [1]) }}"]
 
ok: [localhost] =>
  msg:
  - line1 has
  - line2 has
  - line3 has

and when tried to add [0 1] in the  end  [msg: "{{ range(my_var | length) | 
map('extract', (my_var | map('split', ',') | map('map', 'trim')), [0 1]) 
}}"]
it printsok: [localhost] =>
  msg:
  - i
  - i
  - i
that is second character in the word line[0]. Is not the split breaks the 
words  with (',')?
How to print all the available column? instead of 1( yes the full  file 
without a comma now )
Actually I am trying to print like below
 line1 has  color-red
line2 has color-blue  
line3 has, color-orange



On Friday, December 15, 2023 at 2:44:45 AM UTC+5:30 Todd Lewis wrote:

> In the code below, note that "range(my_var | length)" is equivalent to "[0, 
> 1, 2]".
>
> In the set_fact, we don't "loop" the task; rather we loop over the data 
> within the jinja2 expression by using the map filter.
>
> utoddl@tango:~/ansible*$ cat veera01.yml*
> ---
> # veera01.yml
> - name: Jinja expressions
>   hosts: localhost
>   gather_facts: false
>   vars:
> my_var:
>   - "line1 has , color-red, in  its   middle"
>   - "line2 has,   color-blue,   in its middle"
>   - "line3 has,  color-orange, in its middle"
>   tasks:
> - name: Split and trim parts from my_var
>   ansible.builtin.debug:
> msg: "{{ my_var | map('split', ',') | map('map', 'trim') }}"
>
> - name: Extract the "color-*" parts from my_var
>   ansible.builtin.debug:
> msg: "{{ range(my_var | length) | map('extract', (my_var | 
> map('split', ',') | map('map', 'trim')), [1]) }}"
>
> - name: Same but as set_fact
>   ansible.builtin.set_fact:
> new_var: "{{ range(my_var | length) | map('extract', (my_var | 
> map('split', ',') | map('map', 'trim')), [1]) }}"
>
>
> utoddl@tango:~/ansible*$ ansible-playbook veera01.yml -v*
> Using /etc/ansible/ansible.cfg as config file
>
> PLAY [Jinja expressions] **
>
> TASK [Split and trim parts from my_var] ***
> ok: [localhost] => 
>   msg:
>   - - line1 has
> - color-red
> - in  its   middle
>   - - line2 has
> - color-blue
> - in its middle
>   - - line3 has
> - color-orange
> - in its middle
>
> TASK [Extract the "color-*" parts from my_var] 
> ok: [localhost] => 
>   msg:
>   - color-red
>   - color-blue
>   - color-orange
>
> TASK [Same but as set_fact] ***
> ok: [localhost] => changed=false 
>   ansible_facts:
> new_var:
> - color-red
> - color-blue
> - color-orange
>
> PLAY RECAP 
> localhost  : ok=3changed=0unreachable=0failed=0   
>  skipped=0rescued=0ignored=0   
>
>
>
> On 12/14/23 5:50 AM, Veera wrote:
>
> I have a playbook variable output as below 
>
>
> debug:
>   msg: "{{my_var}}}"
>   
> TASK [debug] 
> **
> ok: [localhost] => {
> "msg": [
> "line1 has , color-red, in  its   middle"
> "line2 has,   color-blue,   in its middle"
> "line3 has,  color-orange, in its middle"
> ]
> }
>
> I want to use the output lines as  an input for another variable using 
> set_fact , as like below . 
>
>   - name: Filtering  the color data  
> ansible.builtin.set_fact:
>   new_var: "{{ item.split(',')[1] }}"
> loop: "{{ var1 }}"
>
> and I am looking for the data like below
>   color-red
>   color-blue
>   color-orange 
>
>  - debug: 
>  var:  new_var
> gives only color-red
>  
>  But my  var1 looping process the first line only in from the my_var and 
> n

[ansible-project] Formatting multiple lines using variable as loop

2023-12-14 Thread Veera
I have a playbook variable output as below 


debug:
  msg: "{{my_var}}}"
  
TASK [debug] 
**
ok: [localhost] => {
"msg": [
"line1 has , color-red, in  its   middle"
"line2 has,   color-blue,   in its middle"
"line3 has,  color-orange, in its middle"
]
}

I want to use the output lines as  an input for another variable using 
set_fact , as like below . 

  - name: Filtering  the color data  
ansible.builtin.set_fact:
  new_var: "{{ item.split(',')[1] }}"
loop: "{{ var1 }}"

and I am looking for the data like below
  color-red
  color-blue
  color-orange

 - debug: 
 var:  new_var
gives only color-red
 
 But my  var1 looping process the first line only in from the my_var and 
not the next 2 lines.
 This is an example and I may expect lines from my_var from 0 to 100's.

How to print the column[]of output) with multiple lines ??

-- 
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/3490a8af-689c-4cb1-8670-1495258df226n%40googlegroups.com.


[ansible-project] using extra-vars with list and dict

2023-11-16 Thread Veera
Hi,

I am missing the format of  input the extra-vars with multiple choices . 
In the playbook , I am passing 2 variables as extra vars  and they are 
working fine .

ansible-playbook myplaybook.yml -e "server_ip=10.100.100.100 
 host_names=myserver1_10.100.100.100"
   
   and able to execute my playbook successfully.  However when I have 
multiple IP's to feed in like below 
 
ansible-playbook myplaybook.yml -e "server_ip='10.100.100.100', 
'10.100.100.101' '10.100.100.10N' 
host_names='myserver1_10.100.100.100', 'myserver2_10.100.100.102', 
.'myserver10N_10.100.100.10N' "
  
   The playbook uses a temporary inventory  and looking to input the same 
with hostnames as myserver_IP one after the other .  
  ansible.builtin.add_host:
hostname: '{{ host_names }}'
groups: my_group
ansible_ssh_private_key_file: "{{ mykeypath }}"
ansible_ssh_user: "root"
ansible_ssh_extra_args: '-o StrictHostKeyChecking=no'

Two extra vars as lists to be passed  and  the items in extra_vars lists 
are to be processed 1+1 at a time . (ie .. the IP 10.100.100.105  must be 
processed  along with host_names=myserver105_10.100.100.105"


   


-- 
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/a144a34b-2744-458f-b943-94606d55020dn%40googlegroups.com.


Re: [ansible-project] using a variable from one task in the next

2023-10-31 Thread Veera

Hi , 

 I am re-opening this thread as I get a new question on above the existing 
one.
Sorry  for that..(not lazy to open another)

Is there a way to use the output of play1 , which is a list(of variables) 
to be passed variable to the second play2
The playbook for illustration only .

---
- name: play 1
  hosts: localhost
  gather_facts: no
  tasks: 
- name: task1 in play1
  shell: 'cat list_of_servers'
  register: task1_output
   
- set_fact:
server_list: "{{task1_output.stdout}}"

- name: print the servers collected
  debug: 
msg: "{{server_list}}"

- name: play 2  
  hosts: localhost
  gather_facts: no
  tasks:
- name: printing the smb.conf from the target servers
  debug: 
msg: "{{lookup('file', '/etc/samba/smb.conf')}}"

- name: printing the /etc/issue from the target servers
  debug: 
msg: "{{lookup('file', '/etc/issue')}}"


Let's assume that after  multiple tasks execution  in play1, I got a list 
of servers. (list exactly ... in set_fact)
server1
server11
server111


I want to use those variables as an input to the second play(play2).
Logically .. the second play must be executed with  (- e server1)   and 
after all the tasks in play2  executed .. it should re-run play2 with (-e 
server 11) and the loop should continue until the  server111.

Is it possible to pass the variables which are the output from play1 as an 
input variable to play with multiple tasks ?
On looping ., is there a way to repeat the play2(with all its  tasks) for 
the each listed item of the variables .. server1.. server11.. server111)


$ ap Untitled-2.yml

PLAY [play 1] 
*

TASK [task1 in play1] 
*
changed: [localhost]

TASK [set_fact] 
***
ok: [localhost]

TASK [print the servers collected] 

ok: [localhost] =>
  msg: |-
server1.example.com
server11.example.com
server111.example.com

PLAY [play 2] 
*

TASK [printing the smb.conf from the target servers] 
**
fatal: [localhost]: FAILED! =>
  msg: The 'file' lookup had an issue accessing the file 
'/etc/samba/smb.conf'. file not found, use -v to see paths searched

PLAY RECAP 

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


On Thursday, September 21, 2023 at 8:25:02 PM UTC+5:30 Rowe, Walter P. 
(Fed) wrote:

> Brian / Todd .. good eyes!
>
>
> Walter
> --
> Walter Rowe, Division Chief
> Infrastructure Services, OISM
> Mobile: 202.355.4123 <(202)%20355-4123>
>
> On Sep 21, 2023, at 10:22 AM, Brian Coca  wrote:
>
> You are confusing scopes, `set_fact` is PER HOST, not a global. So you
> defined the variable on server1 but are trying to read it from
> 127.0.0.1.
>
> So to access in the 2nd play you need to go through hostvars:
> {{hostvasr['server1']['reg_name']
> -- 
> --
> 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-proje...@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%2FCACVha7f1zJc8ni3tG415F2EWiQDHZDyTVNnTZsvSvzgCzmgbSw%2540mail.gmail.com&data=05%7C01%7Cwalter.rowe%40nist.gov%7C8af8d8d876cf4490a1b808dbbaae4ad3%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638309029959489682%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=j7qzTtXfQ1g3uGSzohc4lw6cWSlGY3ySy6c67uEuia0%3D&reserved=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/804eb93b-9883-4d45-9c0c-137f714ecdcen%40googlegroups.com.


Re: [ansible-project] template for rows in a table

2023-10-25 Thread Veera
Thanks Vladimir,   ... Very much helpful ..

On Friday, October 20, 2023 at 11:26:30 PM UTC+5:30 Vladimir Botka wrote:

> On Fri, 20 Oct 2023 08:40:56 -0700 (PDT)
> Veera  wrote:
>
> > the "cols" are printed as like below (not as [green, red, yellow, 
> > blue]).
> > ...
> > "msg": [
> > [
> > "green",
> > "toronto",
> > "English"
> > ],
> > [
> > "red",
> > "montreal",
> > "French"
> > ],
> > [
> > "yellow",
> > "mumbai",
> > "Hindi"
> > ],
> > [
> > "blue",
> > "dubai",
> > "Arabic"
> > ]
> > ]
>
> > > On Fri, 20 Oct 2023, 16:08 Vladimir Botka  wrote:
> > > 
> > >> msg: |-
> > >> color cities lang
> > >> green toronto English
> > >> red montreal French
> > >> yellow mumbai Hindi
> > >> blue dubai Arabic
>
> What you see depends on the callback. Try
>
> shell> ANSIBLE_STDOUT_CALLBACK=yaml ansible-playbook playbook.yml
>
> Learn about formatting:
>
> * Try filters: *to_yaml*, *to_nice_yaml*. Try the option *indent*
> * Try the filter *indent*
> * Try other callbacks
>
> Links:
>
>
> https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_filters.html#formatting-data-yaml-and-json
> https://jinja.palletsprojects.com/en/latest/templates/#jinja-filters.indent
> https://docs.ansible.com/ansible/latest/plugins/callback.html
> https://docs.ansible.com/ansible/latest/collections/index_callback.html
>
> https://docs.ansible.com/ansible/latest/reference_appendices/config.html#default-stdout-callback
>
>
> -- 
> 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/b1c3dc9e-7866-4379-a7be-dbb75632bd00n%40googlegroups.com.


Re: [ansible-project] template for rows in a table

2023-10-20 Thread Veera
Hi  Vladimir,

Thanks . It helps to learn a lot.
Any recommended link to learn the jinja2 formatting?.

in btw,  the "cols" are printed as like below (not as [green, red, yellow, 
blue]).
 is  there ansible/jinja version conflict or I miss a bit?

- name: playbook to print the list as table
  hosts: localhost
  vars:
color:
  - green
  - red
  - yellow
  - blue
cities:
 - toronto
 - montreal
 - mumbai
 - dubai
lang:
 - English
 - French
 - Hindi
 - Arabic
fnames: [color, cities, lang]
cols: |
  {% filter from_yaml %}
  {% for i in fnames %}
  - {{ lookup('vars', i ) }}
  {% endfor %}
  {% endfilter %}
max: "{{ cols|map('map', 'length')|map('max') }}"
frmt: |
  {% filter from_yaml %}
  {% for i in max %}
  - '%-{{ i }}s '
  {% endfor %}
  {% endfilter %}


  tasks: 
- name: print the cols
  ansible.builtin.debug: 
msg: "{{cols}}"

- name: print the max
  ansible.builtin.debug: 
msg: "{{max}}"

- name: print the frmt
  ansible.builtin.debug: 
msg: "{{frmt}}"

- set_fact:
rows: "{{ rows|d(cols.0)|zip(item)|map('flatten') }}"
  loop: "{{ cols[1:] }}"

- name: print the frmt
  ansible.builtin.debug: 
msg: "{{rows}}"

And the output is as below

PLAY [playbook to print the list as table] 


TASK [Gathering Facts] 

Friday 20 October 2023  18:24:15 +0300 (0:00:00.036)   0:00:00.036 

ok: [localhost]

TASK [print the cols] 
*
Friday 20 October 2023  18:24:18 +0300 (0:00:02.702)   0:00:02.738 

ok: [localhost] => {
"msg": [
[
"green",
"red",
"yellow",
"blue"
],
[
"toronto",
"montreal",
"mumbai",
"dubai"
],
[
"English",
"French",
"Hindi",
"Arabic"
]
]
}

TASK [print the max] 
**
Friday 20 October 2023  18:24:18 +0300 (0:00:00.125)   0:00:02.863 

ok: [localhost] => {
"msg": [
6,
8,
7
]
}

TASK [print the frmt] 
*
Friday 20 October 2023  18:24:18 +0300 (0:00:00.109)   0:00:02.973 

ok: [localhost] => {
"msg": [
"%-6s ",
"%-8s ",
"%-7s "
]
}

TASK [set_fact] 
***
Friday 20 October 2023  18:24:18 +0300 (0:00:00.111)   0:00:03.085 

ok: [localhost] => (item=['toronto', 'montreal', 'mumbai', 'dubai'])
ok: [localhost] => (item=['English', 'French', 'Hindi', 'Arabic'])

TASK [print the frmt] 
*
Friday 20 October 2023  18:24:18 +0300 (0:00:00.075)   0:00:03.161 

ok: [localhost] => {
"msg": [
[
"green",
"toronto",
"English"
],
[
"red",
"montreal",
"French"
],
[
"yellow",
"mumbai",
"Hindi"
],
[
"blue",
"dubai",
"Arabic"
]
]
}

PLAY RECAP 

localhost  : ok=6changed=0unreachable=0failed=0 
   skipped=0rescued=0ignored=0
#
#
#ansible --version
ansible [core 2.13.11]
  config file = /home/user/ansible/test-snippets/ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', 
'/usr/share/ansible/plugins/modules']
  ansible python module location = 
/home/user/ansible/kube-ansible/lib/python3.8/site-packages/ansible
  ansible collection location = 
/home/user/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/user/ansible/kube-ansible/bin/ansible
  python version = 3.8.10 (default, May 26 2023, 14:05:08) [GCC 9.4.0]
  jinja version = 3.1.2
  libyaml = True




On Friday, October 20, 2023 at 7:55:34 PM UTC+5:30 Abhijeet Janwalkar wrote:

> Hi Vladimir,
>
> I am really interested in learning how you provide such code.
> From where can I learn more?
>
> Warm regards,
> Abhi
>
> On Fri, 2

Re: [ansible-project] template for rows in a table

2023-10-20 Thread Veera
Hi  Vladimir,

Thanks . It helps to learn a lot.
Any useful like to learn jijna2 in details will be helpful .

in Btw,  why the "cols" are printed as like below , instead of you have 
mentioned?  is  there ansible/jinja version conflict or I miss a bit?

- name: playbook to print the list as table
  hosts: localhost
  vars:
color:
  - green
  - red
  - yellow
  - blue
cities:
 - toronto
 - montreal
 - mumbai
 - dubai
lang:
 - English
 - French
 - Hindi
 - Arabic
fnames: [color, cities, lang]
cols: |
  {% filter from_yaml %}
  {% for i in fnames %}
  - {{ lookup('vars', i ) }}
  {% endfor %}
  {% endfilter %}
max: "{{ cols|map('map', 'length')|map('max') }}"
frmt: |
  {% filter from_yaml %}
  {% for i in max %}
  - '%-{{ i }}s '
  {% endfor %}
  {% endfilter %}


  tasks: 
- name: print the cols
  debug: 
msg: "{{cols}}"

- name: print the max
  debug: 
msg: "{{max}}"

- name: print the frmt
  debug: 
msg: "{{frmt}}"

- set_fact:
rows: "{{ rows|d(cols.0)|zip(item)|map('flatten') }}"
  loop: "{{ cols[1:] }}"

- name: print the frmt
  debug: 
msg: "{{rows}}"






On Friday, October 20, 2023 at 7:55:34 PM UTC+5:30 Abhijeet Janwalkar wrote:

> Hi Vladimir,
>
> I am really interested in learning how you provide such code.
> From where can I learn more?
>
> Warm regards,
> Abhi
>
> On Fri, 20 Oct 2023, 16:08 Vladimir Botka  wrote:
>
>> Declare the list of columns
>>
>>   fnames: [color, cities, lang]
>>
>> and get the columns
>>
>>   cols: |
>> {% filter from_yaml %}
>> {% for i in fnames %}
>> - {{ lookup('vars', i ) }}
>> {% endfor %}
>> {% endfilter %}
>>
>> gives
>>
>>   cols:
>> - [green, red, yellow, blue]
>> - [toronto, montreal, mumbai, dubai]
>> - [English, French, Hindi, Arabic]
>>
>> Find the maximal lengths
>>
>>   max: "{{ cols|map('map', 'length')|map('max') }}"
>>
>> gives
>>
>>   max: [6, 8, 7]
>>
>> and create the list of formats
>>
>>   frmt: |
>> {% filter from_yaml %}
>> {% for i in max %}
>> - '%-{{ i }}s   '
>> {% endfor %}
>> {% endfilter %}
>>
>> gives
>>
>>   frmt: ['%-6s   ', '%-8s   ', '%-7s   ']
>>
>> Get the rows
>>
>> - set_fact:
>> rows: "{{ rows|d(cols.0)|zip(item)|map('flatten') }}"
>>   loop: "{{ cols[1:] }}"
>>
>> gives
>>
>>   rows:
>> - [green, toronto, English]
>> - [red, montreal, French]
>> - [yellow, mumbai, Hindi]
>> - [blue, dubai, Arabic]
>>
>>  and write the table
>>
>> - debug:
>> msg: |
>>   {% for i in range(fnames|length) %}
>>   {{ frmt[i] % fnames[i] }}{% endfor %}
>>
>>   {% for j in rows %}
>>   {% for i in range(fnames|length) %}
>>   {{ frmt[i] % j[i] }}{% endfor %}
>>
>>   {% endfor %}
>>
>> gives
>>
>>   msg: |-
>> colorcities lang
>> greentorontoEnglish
>> red  montreal   French
>> yellow   mumbai Hindi
>> blue dubai  Arabic
>>
>> -- 
>> 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-proje...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/20231020160828.02da4038%40gmail.com
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/91dfa286-4ba4-4792-a5d5-8866b755bce8n%40googlegroups.com.


[ansible-project] template for rows in a table

2023-10-20 Thread Veera
Hi,

Looking for a template which  prints the  list's items in the horizontal 
(rows) of a tables.
I have the below list and trying to print  as  a table.

  vars:
color:
  - green
  - red
  - yellow
  - blue
cities:
 - toronto
 - montreal
 - mumbai
 - dubai
   lang:
 - English
 - French
 - Hindi 
 - Arabic

and a desired out as below

  color cities   lang 
  green toronto  English
  red   montreal French
  yellowmumbai   hindi
  blue  dubaibangla



-- 
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/d7e3b787-6972-486d-a1f1-ad5d5e3216ean%40googlegroups.com.


Re: [ansible-project] what is ansible.builtin.file vs just file module

2023-10-20 Thread Veera
In FCQN , "builtin" exists for only ansible's builtin(native) modules .
We have other  modules too from community or vendors ..

https://docs.ansible.com/ansible/latest/collections/index_module.html 

On Friday, October 20, 2023 at 4:53:19 PM UTC+5:30 Rowe, Walter P. (Fed) 
wrote:

> It is now recommended that all modules be called by their FQCN (fully 
> qualified community name). 
>
> These ansible.builtin.file and file are the same, but ansible.builtin.file 
> will always guarantee which file module you mean to reference in case some 
> other community package also has a module named file.
>
> Walter
> --
> Walter Rowe, Division Chief
> Infrastructure Services, OISM
> Mobile: 202.355.4123 <(202)%20355-4123>
>
> On Oct 20, 2023, at 6:26 AM, Sameer Modak  wrote:
>
> Hello Team, 
>
> I just want to know why we have builtin for all modules in ansible earlier 
> it was just module name
>
> -- 
> 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/8ac74d5a-a341-49aa-bf17-69e3323f0ec1n%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/1cbb44d4-59fe-4dfe-b4b7-58edf8bb77d7n%40googlegroups.com.


Re: [ansible-project] Filter_data manipulation of the debug output .

2023-10-19 Thread Veera
Here is the  stat_out details 
- ansible.builtin.set_fact:
stat_out: "{{ uri_result['json']['resources'] | selectattr('name', 
'==','LinuxOsUpdateExtension') | map(attribute='properties') 
|map(attribute='instanceView')|map(attribute='status')|map(attribute='message') 
}}"

TASK [debug] 
**
ok: [localhost] =>
  msg:
  - 'Extension Message: Action Completed. [ActivityId=], 
OperationResult: {"activityId": "xxx-xx", "sequenceNumber": 0, 
"inputStartTime": "2023-08-18T05:34:24.920507Z", "lastModifiedTime": 
"2023-08-18T06:01:56.188600Z", "extensionTriggerTime": 
"2023-08-18T05:34:57.745409Z", "osName": "CentOS", "osVersion": "9", 
"action": "Patching", "actionStatus": "Success", "patchServiceUsed": "YUM", 
"errors": null, "patchDetails": {"rebootNeeded": true, "rebootStatus": 
"Completed", "maintenanceWindowExceeded": false, "retriggerCount": 09, 
"notSelectedPatchCount": 0, "pendingPatchCount": 0, "installedPatchCount": 
16, "failedPatchCount": 0, "patches": "eJxxx==",
"excludedPatchCount": 0}, "assessmentDetails": {"countByCategory": 
{"security": 0, "other": 0}, "totalCount": 0, "patches": 
"eJyLjgUAARUAuQ==", "rebootPending": null}, "logs": "kgjhsdcgdgscf/Y"}'

- name:  status of the output
  debug:
msg: "status  of {{serverName}} is  {{ [9] | map('extract', 
stat_out[0].split(',')) }}"
  register: server_status 
  ignore_errors: yes
  
The output is 

TASK [status of the output] 
*******
ok: [localhost] =>
  msg: 'status  of client11  is  ['' "Status": "Completed"'']'

On Wednesday, October 18, 2023 at 1:52:44 PM UTC+5:30 dulh...@mailbox.org 
wrote:

>   
> can you provide a bit more context, i.e. where does the variable 
> `stat_out` comes from. 
> Or maybe even better prodvide what debugging the entire variable throws at 
> you 
>   
>debug: 
>  var: stat_out 
>   
> in order to see the data structur you are getting 
>   
>
> On 10/18/2023 8:02 AM CEST Veera  wrote: 
>   
>   
> From the below debug module , I try filter the ouput 
>
> - name:  status of the output
>   debug:
> msg: "status  of {{serverName}} is  {{ [9] | map('extract', 
> stat_out[0].split(',')) }}"
>   register: server_status 
>
>   
> The output is 
>
> TASK [status of the output] 
> ***
> ok: [localhost] =>
>   msg: 'status  of client11  is  ['' "Status": "Completed"'']' 
>
>   
>   
>  and when  I try to  still filter the output , but missing a delimiter 
> (like cut -d: -f1). 
>   
>
>  Expecting the output as below .  
>msg: 'status  of the server client11.example.com  is  [Completed]' 
>   
> Any String(Word) like Completed or Failed to be captured in [] 
>
>  
>
>

-- 
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/24c474a8-d6fc-4f6c-82de-6c2e8e609a81n%40googlegroups.com.


[ansible-project] Filter_data manipulation of the debug output .

2023-10-17 Thread Veera
>From the below debug module , I try filter the ouput

- name:  status of the output
  debug:
msg: "status  of {{serverName}} is  {{ [9] | map('extract', 
stat_out[0].split(',')) }}"
  register: server_status 

  
The output is 

TASK [status of the output] 
***
ok: [localhost] =>
  msg: 'status  of client11  is  ['' "Status": "Completed"'']'

 
 
 and when  I try to  still filter the output , but missing a delimiter 
(like cut -d: -f1). 
 

 Expecting the output as below . 
   msg: 'status  of the server client11.example.com  is  [Completed]'

Any String(Word) like Completed or Failed to be captured in [] 

-- 
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/5cc06e34-062e-4513-81d5-64db5c183488n%40googlegroups.com.


Re: [ansible-project] split for data manitpulation

2023-10-15 Thread Veera
Hi  Vladimir ,

I got it by using the  join  -  s1_34: "{{ [[1], [3, 4]]| map('map', 
'extract', arr)| join(',')}


On Sunday, October 15, 2023 at 1:08:39 AM UTC+5:30 Vladimir Botka wrote:

> On Sat, 14 Oct 2023 10:32:51 -0700 (PDT)
> Veera  wrote:
>
> > Is there a way to combine the 2 positional values ...
> > to print like below
> > - two
> > - four five
>
> Split the string and trim the items
>
> arr: "{{ myline|split(',')|map('trim') }}"
>
> gives
>
> arr:
> - This line is a test
> - two
> - three
> - four
> - five
> - '6'
> - seven
>
> A list of lists the structure that describes what you want
>
> s1_34: "{{ [[1], [3, 4]]|
> map('map', 'extract', arr)|
> map('join', ' ') }}"
>
> gives
>
> s1_34:
> - two
> - four five
>
> You can substitute *arr* in *s1_34* if you want a 'one-liner'.
>
>
> -- 
> 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/15ad36b7-c542-4cc1-975e-d37bfd3b13f0n%40googlegroups.com.


Re: [ansible-project] split for data manitpulation

2023-10-14 Thread Veera
Hi Todd,

Is there a way to combine the 2 positional  values .

 "{{ [2, 4, 5] | map('extract', myline.split(',')) }}" 
as 
 "{{ [2, 4 5] | map('extract', myline.split(',')) }}" 
  to print  like below
  - two
 -  four five

I tried to combine .. but missing a bit
 "{{ [2, combine [4 5] | map('extract', myline.split(',')) }}" or  printing 
"two" as  a item and  "{{ [4 5] | map('extract', myline.split(',')) 
|combine }}"

or a different filter instead of combine can help?


On Tuesday, August 29, 2023 at 5:24:04 PM UTC+5:30 Todd Lewis wrote:

> You have 6 delimiters, so only 7 fields. Your maximum index therefore is 6.
>
> Setting that issue aside, you can use map(), like so:
>
> "{{ [2, 4, 5] | map('extract', myline.split(',')) }}"
>
> Cheers,
> --
> Todd
>
>
> On 8/29/23 3:40 AM, Veera wrote:
>
> Hi, 
>
> I have this playbook to print the columns  5 and 6 using the debug.
>
> ---
> - name: playbook to print columns
>   hosts: localhost
>   gather_facts: no
>   vars:
> myline: This line is a test, two, three, four, five, 6, seven 
>   tasks:
> - name: play to  print
>   debug:
> msg: 
>   - "{{ myline.split(',')[5] }}"
>   - "{{ myline.split(',')[6] }}"
>
> It prints the details , But is there a way to print the columns  4,7 and 
> 11 with a single split option. (instead of listing under msg: )
>
>  - name: play to  print
>   debug:
> msg:  "{{ myline.split(',')[4][7][11] }}"
>
> Do split accepts only one square bracket[] parameter? 
>  
>   
>
>
> -- 
> 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/61d732eb-26b2-460f-98de-1db41a6deccan%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/ansible-project/61d732eb-26b2-460f-98de-1db41a6deccan%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>

-- 
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/062d69ec-9f66-4595-ad31-693d7961ef23n%40googlegroups.com.


Re: [ansible-project] Formatting the dict items with debug

2023-10-14 Thread Veera
Thanks Vladimir .. rich info for me ..

On Saturday, October 14, 2023 at 8:58:23 PM UTC+5:30 Vladimir Botka wrote:

> On Sat, 14 Oct 2023 01:01:28 -0700 (PDT)
> Veera  wrote:
>
> > - debug:
> > msg: "{{ result.stdout }}"
> > 
> > ok: [localhost] => {
> > "msg": {
> > "access_token": "xx",
> > "expires_in": 43200,
> > "token_type": "xx"
> > }
> > }
>
> For example, given the file
>
> shell> cat /tmp/test.json 
> {
> "access_token": "xx",
> "expires_in": 43200,
> "token_type": "xx"
> }
>
> The value of *result.stdout* is *AnsibleUnsafeText*. What you see
> depends on the callback. The below play
>
> shell> cat pb.yml
> - hosts: all
> tasks:
> - command: cat /tmp/test.json
> register: result
> - debug:
> var: result.stdout
>
> gives JSON with the default callback
>
> shell> ANSIBLE_STDOUT_CALLBACK=default ansible-playbook pb.yml
> ...
> ok: [localhost] => {
> "result.stdout": {
> "access_token": "xx",
> "expires_in": 43200,
> "token_type": "xx"
> }
> }
>
> The same task gives YAML with the yaml callback
>
> shell> ANSIBLE_STDOUT_CALLBACK=yaml ansible-playbook pb2.yml
> ...
> ok: [localhost] => 
> result.stdout:
> access_token: xx
> expires_in: 43200
> token_type: xx
>
> You can test the type of the attribute *stdout*
>
> - debug:
> var: result.stdout|type_debug
>
> gives
>
> result.stdout|type_debug: AnsibleUnsafeText
>
>
> > filter the access token alone
>
> Convert the text to dictionary and get the *access_token* as well.
> It's up to you where you put the vars
>
> vars:
>
> test_data: "{{ result.stdout|from_json }}"
> access_token: "{{ test_data.access_token }}"
>
> Example of a complete playbook for testing
>
> shell> cat pb.yml
> - hosts: all
>
> vars:
>
> test_data: "{{ result.stdout|from_json }}"
> access_token: "{{ test_data.access_token }}"
>
> tasks:
>
> - command: cat /tmp/test.json
> register: result
> - debug:
> var: result.stdout
> - debug:
> var: result.stdout|type_debug
> - debug:
> var: test_data|type_debug
> - debug:
> var: test_data
> - debug:
> var: access_token
>
>
> -- 
> 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/10c295f5-79bd-49ee-84dd-76944f6a2bb5n%40googlegroups.com.


Re: [ansible-project] Formatting the dict items with debug

2023-10-14 Thread Veera
It worked and its my miss again to combine it ..  :)

On Saturday, October 14, 2023 at 8:36:11 PM UTC+5:30 Dick Visser wrote:

> Yes, so you should combine them like:
>
>   - debug:
>   msg: "{{ (result.stdout|from_json).access_token }}"
>
>
>
> On Sat, 14 Oct 2023 at 16:10, Veera  wrote:
>
>>
>> when I try with 
>>  - debug:
>>msg: "{{ result }}"
>>
>> the output is 
>>
>> TASK [debug] 
>> **
>> ok: [localhost] => {
>> "msg": {
>> "changed": true,
>> "cmd": "curl -X POST 'https://xx.com/auth/login' -H 
>> 'Content-Type: application/json' -d @.mycred.json",
>> -- trimmed lines 
>> "rc": 0,
>>-- trimmed lines 
>> "stdout": 
>> "{\"access_token\":\"X\",\"token_type\":\"Bearer\",\"expires_in\":86400}",
>> "stdout_lines": [
>> 
>> "{\"access_token\":\"X\",\"token_type\":\"Bearer\",\"expires_in\":86400}"
>> ]
>> }
>> }
>>
>>
>> The output for the 
>>   - debug:
>>   msg: "{{ result.stdout |from_json  }}"
>>
>> is
>>
>>
>> TASK [debug] 
>> **
>> ok: [localhost] => {
>> "msg": {
>> "access_token": "XX",
>> "expires_in": 86400,
>> "token_type": "Bearer"
>> }
>> }
>>
>>
>>
>> when I use  the 
>>  - debug:
>>  msg: "{{ result.stdout.access_token }}"
>>
>> the error is 
>>
>> TASK [debug] 
>> **
>> fatal: [localhost]: FAILED! => {"msg": "The task includes an option with 
>> an undefined variable. The error was: 
>> 'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 
>> 'access_token'\n\nThe error appears to be in '/home/user/check.yml': line 
>> 32, column 7, but may\nbe elsewhere in the file depending on the exact 
>> syntax problem.\n\nThe offending line appears to be:\n\n\n- debug:\n   
>>^ here\n"}
>>
>> On Saturday, October 14, 2023 at 6:31:49 PM UTC+5:30 Will McDonald wrote:
>>
>>> Is there any reason you can't just use result.stdout.access_token?
>>>
>>> $ cat debug-token.yml
>>> - name: debug vars
>>>   hosts: localhost
>>>   gather_facts: no
>>>
>>>   vars:
>>> result:
>>>   stdout:
>>> access_token: xx
>>> expires_in: 4320
>>> token_type: yy
>>>
>>>   tasks:
>>> - name: debug the result
>>>   ansible.builtin.debug:
>>> var: result
>>>
>>> - name: extract the token
>>>   ansible.builtin.debug:
>>> msg: "{{ result.stdout.access_token }}"
>>>
>>>
>>> $ ansible-playbook debug-token.yml
>>>
>>> PLAY [debug vars] 
>>> ******
>>>
>>> TASK [debug the result] 
>>> 
>>> ok: [localhost] => {
>>> "result": {
>>> "stdout": {
>>> "access_token": "xx",
>>> "expires_in": 4320,
>>> "token_type": "yy"
>>> }
>>> }
>>> }
>>>
>>> TASK [extract the token] 
>>> ***
>>> ok: [localhost] => {
>>> "msg": "xx"
>>> }
>>>
>>>
>>> On Sat, 14 Oct 2023 at 13:43, Veera  wrote:
>>>
>>>> I need only the output or the v

Re: [ansible-project] Formatting the dict items with debug

2023-10-14 Thread Veera

when I try with 
 - debug:
   msg: "{{ result }}"

the output is 

TASK [debug] 
**
ok: [localhost] => {
"msg": {
"changed": true,
"cmd": "curl -X POST 'https://xx.com/auth/login' -H 
'Content-Type: application/json' -d @.mycred.json",
-- trimmed lines 
"rc": 0,
   -- trimmed lines 
"stdout": 
"{\"access_token\":\"X\",\"token_type\":\"Bearer\",\"expires_in\":86400}",
"stdout_lines": [

"{\"access_token\":\"X\",\"token_type\":\"Bearer\",\"expires_in\":86400}"
]
}
}


The output for the 
  - debug:
  msg: "{{ result.stdout |from_json  }}"

is


TASK [debug] 
**
ok: [localhost] => {
"msg": {
"access_token": "XX",
"expires_in": 86400,
"token_type": "Bearer"
}
}



when I use  the 
 - debug:
 msg: "{{ result.stdout.access_token }}"

the error is 

TASK [debug] 
**
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an 
undefined variable. The error was: 
'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 
'access_token'\n\nThe error appears to be in '/home/user/check.yml': line 
32, column 7, but may\nbe elsewhere in the file depending on the exact 
syntax problem.\n\nThe offending line appears to be:\n\n\n- debug:\n   
   ^ here\n"}

On Saturday, October 14, 2023 at 6:31:49 PM UTC+5:30 Will McDonald wrote:

> Is there any reason you can't just use result.stdout.access_token?
>
> $ cat debug-token.yml
> - name: debug vars
>   hosts: localhost
>   gather_facts: no
>
>   vars:
> result:
>   stdout:
> access_token: xx
> expires_in: 4320
> token_type: yy
>
>   tasks:
> - name: debug the result
>   ansible.builtin.debug:
> var: result
>
> - name: extract the token
>   ansible.builtin.debug:
> msg: "{{ result.stdout.access_token }}"
>
>
> $ ansible-playbook debug-token.yml
>
> PLAY [debug vars] 
> **
>
> TASK [debug the result] 
> ****
> ok: [localhost] => {
> "result": {
> "stdout": {
> "access_token": "xx",
> "expires_in": 4320,
> "token_type": "yy"
> }
> }
> }
>
> TASK [extract the token] 
> ***
> ok: [localhost] => {
> "msg": "xx"
> }
>
>
> On Sat, 14 Oct 2023 at 13:43, Veera  wrote:
>
>> I need only the output or the value of the below(trying to set_fact the 
>> access_token)
>> access_token": "xx"
>>
>>
>>
>>
>> On Saturday, October 14, 2023 at 6:01:54 PM UTC+5:30 Dick Visser wrote:
>>
>>> What is your desired output then??
>>>
>>> Sent from Gmail Mobile
>>>
>>>
>>> On Sat, 14 Oct 2023 at 10:01, Veera  wrote:
>>>
>>>> Hi,
>>>>
>>>> I have the below output  from my playbook using 
>>>> - debug:
>>>> msg: "{{ result.stdout }}"
>>>>
>>>> TASK [debug] 
>>>> **
>>>> ok: [localhost] => {
>>>> "msg": {
>>>> "access_token": "xx",
>>>> "expires_in": 43200,
>>>> "token_type": "xx"
>>>> }
>>>> }
>>>>
>>>>
>>>>  and  when I tried to filter the access token alone  , with map   by
>>>> "{{ result.stdout | map('ext

Re: [ansible-project] Formatting the dict items with debug

2023-10-14 Thread Veera

when I try with 
 - debug:
 msg: "{{ result }}"


TASK [debug] 
**
ok: [localhost] => {
"msg": {
"changed": true,
"cmd": "curl -X POST 'https://xxx.com/auth/login' -H 
'Content-Type: application/json' -d @.mycred.json",
-- trimmed lines 
"rc": 0,
   -- trimmed lines 
"stdout": 
"{\"access_token\":\"X\",\"token_type\":\"Bearer\",\"expires_in\":86400}",
"stdout_lines": [

"{\"access_token\":\"X\",\"token_type\":\"Bearer\",\"expires_in\":86400}"
]
}
}


The output for the 
  - debug:
  msg: "{{ result.stdout |from_json  }}"

is


TASK [debug] 
**
ok: [localhost] => {
"msg": {
"access_token": "X",
"expires_in": 86400,
"token_type": "Bearer"
}
}



when I use  the 
 - debug:
 msg: "{{ result.stdout.access_token }}"

the error is 

TASK [debug] 
**
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an 
undefined variable. The error was: 
'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 
'access_token'\n\nThe error appears to be in 
'/home/user/nvs/check_vault.yml': line 32, column 7, but may\nbe elsewhere 
in the file depending on the exact syntax problem.\n\nThe offending line 
appears to be:\n\n\n- debug:\n  ^ here\n"}

On Saturday, October 14, 2023 at 6:31:49 PM UTC+5:30 Will McDonald wrote:

> Is there any reason you can't just use result.stdout.access_token?
>
> $ cat debug-token.yml
> - name: debug vars
>   hosts: localhost
>   gather_facts: no
>
>   vars:
> result:
>   stdout:
> access_token: xx
> expires_in: 4320
> token_type: yy
>
>   tasks:
> - name: debug the result
>   ansible.builtin.debug:
> var: result
>
> - name: extract the token
>   ansible.builtin.debug:
> msg: "{{ result.stdout.access_token }}"
>
>
> $ ansible-playbook debug-token.yml
>
> PLAY [debug vars] 
> **
>
> TASK [debug the result] 
> ****
> ok: [localhost] => {
> "result": {
> "stdout": {
> "access_token": "xx",
> "expires_in": 4320,
> "token_type": "yy"
> }
> }
> }
>
> TASK [extract the token] 
> ***
> ok: [localhost] => {
> "msg": "xx"
> }
>
>
> On Sat, 14 Oct 2023 at 13:43, Veera  wrote:
>
>> I need only the output or the value of the below(trying to set_fact the 
>> access_token)
>> access_token": "xx"
>>
>>
>>
>>
>> On Saturday, October 14, 2023 at 6:01:54 PM UTC+5:30 Dick Visser wrote:
>>
>>> What is your desired output then??
>>>
>>> Sent from Gmail Mobile
>>>
>>>
>>> On Sat, 14 Oct 2023 at 10:01, Veera  wrote:
>>>
>>>> Hi,
>>>>
>>>> I have the below output  from my playbook using 
>>>> - debug:
>>>> msg: "{{ result.stdout }}"
>>>>
>>>> TASK [debug] 
>>>> **
>>>> ok: [localhost] => {
>>>> "msg": {
>>>> "access_token": "xx",
>>>> "expires_in": 43200,
>>>> "token_type": "xx"
>>>> }
>>>> }
>>>>
>>>>
>>>>  and  when I tried to filter the access token alone  , with map   by
>>>> "{{ result.stdout | map('extract

Re: [ansible-project] Formatting the dict items with debug

2023-10-14 Thread Veera
I need only the output or the value of the below(trying to set_fact the 
access_token)
access_token": "xx"




On Saturday, October 14, 2023 at 6:01:54 PM UTC+5:30 Dick Visser wrote:

> What is your desired output then??
>
> Sent from Gmail Mobile
>
>
> On Sat, 14 Oct 2023 at 10:01, Veera  wrote:
>
>> Hi,
>>
>> I have the below output  from my playbook using 
>> - debug:
>> msg: "{{ result.stdout }}"
>>
>> TASK [debug] 
>> **
>> ok: [localhost] => {
>> "msg": {
>> "access_token": "xx",
>> "expires_in": 43200,
>> "token_type": "xx"
>> }
>> }
>>
>>
>>  and  when I tried to filter the access token alone  , with map   by
>> "{{ result.stdout | map('extract', access_token) }}" ., it errors as 
>> below
>>
>> The task includes an option with an undefined variable. The error was: 
>> 'access_token' is  undefined\n\n 
>>
>> and  when I tried to filter the access token alone  , with map   by
>>  msg: "{{ result.stdout | map(attribute='access_token') }}" ., it errors 
>> as below
>>
>> What I am missing here  to get the desired output  here?
>>
>>
>> -- 
>> 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/6a7a5ed1-6c6b-4660-8da9-1388898923fen%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/6a7a5ed1-6c6b-4660-8da9-1388898923fen%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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/f1f16814-e47b-4251-8bea-9e9660ead1fcn%40googlegroups.com.


[ansible-project] Formatting the dict items with debug

2023-10-14 Thread Veera
Hi,

I have the below output  from my playbook using 
- debug:
msg: "{{ result.stdout }}"

TASK [debug] 
**
ok: [localhost] => {
"msg": {
"access_token": "xx",
"expires_in": 43200,
"token_type": "xx"
}
}


 and  when I tried to filter the access token alone  , with map   by
"{{ result.stdout | map('extract', access_token) }}" ., it errors as below

The task includes an option with an undefined variable. The error was: 
'access_token' is  undefined\n\n 

and  when I tried to filter the access token alone  , with map   by
 msg: "{{ result.stdout | map(attribute='access_token') }}" ., it errors as 
below

What I am missing here  to get the desired output  here?


-- 
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/6a7a5ed1-6c6b-4660-8da9-1388898923fen%40googlegroups.com.


[ansible-project] Using multiple variables with Assert

2023-10-10 Thread Veera
Hi,

I am trying with the first task of the playbook with assert module to 
validate the supported versions. If Assert is success, then only the next 
tasks will be executed .

- name: Playbook to test the conditional
  hosts: localhost
  vars:
 rhel_ver:
   - 9
   - 8
   - 7
centos_ver:
- 8
- 7  
  tasks:
  - name: Check the OS version and proceed based on the OS
ansible.builtin.assert:
that:
- ansible_distribution == "CentOS" and 
ansible_distribution_major_version == "{{ centos_ver }}"
- ansible_distribution == "RedHat" and 
ansible_distribution_major_version == "{{ rhel_ver }}"
   fail_msg: "Unsupported OS version. Exiting . "
   success_msg: "Supported OS version and proceeding to next task"

   - debug:
 msg: "Completed"

The Asset have to be Success with multiple conditions .. If either the 
distribution is RedHat or CentOS(not both conditions need to be true)  and 
the major version is atleast one of the value from the variables(of its OS 
distro). 



 



-- 
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/c2457c47-2460-47d4-86d0-4e872f7c5dd9n%40googlegroups.com.


Re: [ansible-project] using a variable from one task in the next

2023-09-21 Thread Veera
yes.  Exactly .. 
I did set_fact on a remote_host and try to re-call  the value of the  
variable  in the localhost.


*So to access in the 2nd play you need to go through 
hostvars:{{hostvasr['server1']['reg_name']*

Do you mean I have to use like below?

- name: print  the collected hostname
  debug:
 msg: "{{hostvars['server1']['reg_name'] }}"

On Thursday, September 21, 2023 at 7:53:22 PM UTC+5:30 Brian Coca wrote:

> You are confusing scopes, `set_fact` is PER HOST, not a global. So you
> defined the variable on server1 but are trying to read it from
> 127.0.0.1.
>
> So to access in the 2nd play you need to go through hostvars:
> {{hostvasr['server1']['reg_name']
> -- 
> --
> 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/5d7389a8-f596-4868-a439-88f5de5fb48en%40googlegroups.com.


[ansible-project] using a variable from one task in the next

2023-09-21 Thread Veera
I have a 2 tasks in a playbook and from task1  I have  a variable collected 
from the register output as below.

- name: Playbook to collect the actual hostname 
  hosts: server1
  become: yes
  tasks:
- name: collect the actual hostname
  shell: 'hostname'
  register: short_name
 
- name: collect the hostname for the next task
  set_fact: 
reg_name: "{{ short_name.stdout_lines[-1].split('.')[1] }}"


- name: Playbook to test the new hostname collections 
  hosts: 127.0.0.1
  become: yes
  tasks:
- name: print  the collected hostname
  debug:
msg: {{reg_name  }}

 collecting  the host's shortname using set_fact is  working .  However the 
data stored using set_fact in reg_name is  not carry to the next task. 
Is there an option/module available to have the variable from one task to 
be made available to the next?


-- 
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/e414a185-f743-4618-ab14-b4449dfecf6dn%40googlegroups.com.


Re: [ansible-project] split for data manitpulation

2023-08-29 Thread Veera
Thanks  Todd. 
 I  got the desired output  and it answers the other thread also .
https://groups.google.com/g/ansible-project/c/ZqZuw3do-5g/m/hMlDvLceAQAJ  
 (Now I understand it is a string.. )





On Tuesday, August 29, 2023 at 5:24:04 PM UTC+5:30 Todd Lewis wrote:

> You have 6 delimiters, so only 7 fields. Your maximum index therefore is 6.
>
> Setting that issue aside, you can use map(), like so:
>
> "{{ [2, 4, 5] | map('extract', myline.split(',')) }}"
>
> Cheers,
> --
> Todd
>
>
> On 8/29/23 3:40 AM, Veera wrote:
>
> Hi, 
>
> I have this playbook to print the columns  5 and 6 using the debug.
>
> ---
> - name: playbook to print columns
>   hosts: localhost
>   gather_facts: no
>   vars:
> myline: This line is a test, two, three, four, five, 6, seven 
>   tasks:
> - name: play to  print
>   debug:
> msg: 
>   - "{{ myline.split(',')[5] }}"
>   - "{{ myline.split(',')[6] }}"
>
> It prints the details , But is there a way to print the columns  4,7 and 
> 11 with a single split option. (instead of listing under msg: )
>
>  - name: play to  print
>   debug:
> msg:  "{{ myline.split(',')[4][7][11] }}"
>
> Do split accepts only one square bracket[] parameter? 
>  
>   
>
>
> -- 
> 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/61d732eb-26b2-460f-98de-1db41a6deccan%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/ansible-project/61d732eb-26b2-460f-98de-1db41a6deccan%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>

-- 
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/0191ec3a-4cf5-4d63-9fcf-b39761c012f0n%40googlegroups.com.


Re: [ansible-project] Formatting the output by line by line

2023-08-29 Thread Veera
Yes.. My  replies went partially uploaded and they did not appeared
yesterday.

I tried twice and it seems some glitch.
Suddenly they appeared.  (Not sure about its reported as spam?)

I will share the full details ..

On Tue, 29 Aug, 2023, 7:47 pm Todd Lewis,  wrote:

> Could you please back up a step and show the debug task that's producing
> this?
> If it's just a string, then you'll have to do some sort of pattern
> matching and replacement operations on that string.
> On the other hand, if it's a data structure, you can do quite a bit of
> filtering and templating with Jinja2 to produce the output you seek.
> But without seeing what you're starting from, there's no way to make a
> reasonable suggestion.
>
> On 8/28/23 4:56 AM, Veera wrote:
>
> Hi,
>
> My play book print the debug output as below
> TASK [Print the  status of the server]
> ***
> ok: [localhost] => {
> "msg": [
> "Extension Message: Patching Successful.
> [ActivityId=xxx-1f8f-4e44-95af-], OperationResult: {\"
> activityId\": \"xxx-1f8f-4e44-95af-\", \"sequenceNumber\":
> 8, \"inputStartTime\": \"2023-08-28T05:45:40.500520Z\", \"lastModifiedTime
> \": \"2023-08-28T06:14:43.449672Z\", \"extensionTriggerTime\": \"
> 2023-08-28T05:45:53.268037Z\", \"osName\": \"CentOS Stream\", \"osVersion
> \": \"8\", \"action\": \"Patching\", \"actionStatus\": \"Success\", \"
> patchServiceUsed\": \"YUM\", \"errors\": null, \"patchDetails\": {\"
> rebootNeeded\": true, \"rebootStatus\": \"Completed\", \"
> maintenanceWindowExceeded\": false, \"retriggerCount\": 61, \"
> notSelectedPatchCount\": 0, \"pendingPatchCount\": 0, \"
> installedPatchCount\": 98, \"failedPatchCount\": 0, \"patches\": \"
> xxx=\", \"
> excludedPatchCount\": 0}, \"assessmentDetails\": {\"countByCategory\": {\"
> security\": 0, \"other\": 0}, \"totalCount\": 0, \"patches\": \"
> X==\", \"rebootPending\": null}, \"logs\": \"
> yyy"}"
> ]
> }
>
> I need to break the output  like below
>
> Extension Message: Patching Successful.
> [ActivityId=xxx-1f8f-4e44-95af-]
> OperationResult: activityId: xxx-1f8f-4e44-95af-
> sequenceNumber: 8
> inputStartTime: 2023-08-28T05:45:40.500520Z
> lastModifiedTime: "2023-08-28T06:14:43.449672Z
>
> and so on..
>
> --
> 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/f7b49add-d473-4e08-9527-e3ed864ca825n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/f7b49add-d473-4e08-9527-e3ed864ca825n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
> --
> Todd
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ansible-project/ZqZuw3do-5g/unsubscribe.
> To unsubscribe from this group and all its topics, 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/584f136d-c317-79c3-e1d4-56a02781b743%40gmail.com
> <https://groups.google.com/d/msgid/ansible-project/584f136d-c317-79c3-e1d4-56a02781b743%40gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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/CALNY%2B%2BQJo8G%3DH-T1b1qe2kzn58ZEmkQ4Af3rZMXWU4X0ujd-OQ%40mail.gmail.com.


Re: [ansible-project] Formatting the output by line by line

2023-08-29 Thread Veera
Got a better output when added  *stdout_callback = yaml*  to the ansible.cfg
However the output lengthy line remains the same .  

No luck when tried to split() also . It has multiple  sub-elements  which 
is making it complex . 

As mentioned initially , I need to break the output  like below.

Extension Message: Patching Successful. 
[ActivityId=xxx-1f8f-4e44-95af-]
OperationResult: activityId: xxx-1f8f-4e44-95af-
sequenceNumber: 8
inputStartTime: 2023-08-28T05:45:40.500520Z
lastModifiedTime: "2023-08-28T06:14:43.449672Z





On Monday, August 28, 2023 at 4:50:07 PM UTC+5:30 dulh...@mailbox.org wrote:

> so, my suggestion was to add 
>   
> *stdout_callback = yaml* to the [defaults] section of that file and see 
> whether the output suits you better. 
>   
>   
>
> On 08/28/2023 1:11 PM CEST Veera  wrote: 
>   
>   
> my ansible.cfg is a custom one which I am using from the same location and 
> it has no more specific lines to format. 
>   
> $ansible --version | grep 'ansible.cfg'
>   config file = /home/myuser/ansible/ansible.cfg
> $pwd
> /home/myuser/ansible/
> $ cat ansible.cfg
> [defaults]
> inventory = ./inventory
> host_key_checking = False
> $ 
> On Monday, August 28, 2023 at 2:59:06 PM UTC+5:30 dulh...@mailbox.org 
> wrote: 
>
> *no ansible.cfg involved* seems impossible to me. 
>   
> ansible --version | grep 'ansible.cfg' (in the location you run the 
> playbook from) should reveal which one is effective. 
>   
> Or am I understanding something badly wrong here? 
>   
>
> On 08/28/2023 11:22 AM CEST Veera  wrote: 
>   
>   
> Hi , 
>   
>  Sorry ... No *ansible.cfg*  involved. 
> After multiple filtering  of (the output) I  reached to this output.  
> I want to enhance it further .   
>
> On Monday, August 28, 2023 at 2:47:42 PM UTC+5:30 dulh...@mailbox.org 
> wrote: 
>
> wondering whether *stdout_callback: yaml* in the *ansible.cfg* might be 
> doing that 
>
> On 08/28/2023 10:56 AM CEST Veera  wrote: 
>   
>   
> Hi, 
>   
> My play book print the debug output as below  
> TASK [Print the  status of the server] 
> ***
>  
>
> ok: [localhost] => { 
> "msg": [ 
> "Extension Message: Patching Successful. 
> [ActivityId=xxx-1f8f-4e44-95af-], OperationResult: {\"
> activityId\": \"xxx-1f8f-4e44-95af-\", \"sequenceNumber\": 
> 8, \"inputStartTime\": \"2023-08-28T05:45:40.500520Z\", \"lastModifiedTime
> \": \"2023-08-28T06:14:43.449672Z\", \"extensionTriggerTime\": \"
> 2023-08-28T05:45:53.268037Z\", \"osName\": \"CentOS Stream\", \"osVersion
> \": \"8\", \"action\": \"Patching\", \"actionStatus\": \"Success\", \"
> patchServiceUsed\": \"YUM\", \"errors\": null, \"patchDetails\": {\"
> rebootNeeded\": true, \"rebootStatus\": \"Completed\", \"
> maintenanceWindowExceeded\": false, \"retriggerCount\": 61, \"
> notSelectedPatchCount\": 0, \"pendingPatchCount\": 0, \"
> installedPatchCount\": 98, \"failedPatchCount\": 0, \"patches\": \"
> xxx=\", \"
> excludedPatchCount\": 0}, \"assessmentDetails\": {\"countByCategory\": {\"
> security\": 0, \"other\": 0}, \"totalCount\": 0, \"patches\": \"
> X==\", \"rebootPending\": null}, \"logs\": \"
> yyy"}" 
> ] 
> } 
>   
> I need to break the output  like below 
>   
> Extension Message: Patching Successful. 
> [ActivityId=xxx-1f8f-4e44-95af-] 
> OperationResult: activityId: xxx-1f8f-4e44-95af- 
> sequenceNumber: 8 
> inputStartTime: 2023-08-28T05:45:40.500520Z 
> lastModifiedTime: "2023-08-28T06:14:43.449672Z 
>   
> and so on..  
>
>  
>
> -- 
>
> 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/9a1a2eea-2b38-412e-9fcb-a4f7afd6e485n%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/ansible-project/9a1a2eea-2b38-412e-9fcb-a4f7afd6e485n%40googlegroups.com?utm_medium=email&utm_source=footer>.
>  
>
>
>   
> --- 
>
> gunnar wagner | fichtestr. 1, 19386 lübz | fon: 0176 7808 9090
>

-- 
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/9d6a3dff-8ff8-4924-a515-fef08b2cf34an%40googlegroups.com.


Re: [ansible-project] Formatting the output by line by line

2023-08-29 Thread Veera

By adding  *stdout_callback = yaml  *anisble.cfg .,  I get better formatted 
syntax.
But I am unable to split the lengthy single line.

unable to either convert to lists or split the line to grep and cut the  
words(strings) from the output.  
The content have multiple sub-elements .

As mentioned initially ,  I have to print a few dict items from the 
lengthy  like below .





*Extension Message: Patching Successful. 
[ActivityId=xxx-1f8f-4e44-95af-]OperationResult: 
activityId: xxx-1f8f-4e44-95af-sequenceNumber: 
8inputStartTime: 2023-08-28T05:45:40.500520ZlastModifiedTime: 
"2023-08-28T06:14:43.449672Z*







On Monday, August 28, 2023 at 4:50:07 PM UTC+5:30 dulh...@mailbox.org wrote:

> so, my suggestion was to add 
>   
> *stdout_callback = yaml* to the [defaults] section of that file and see 
> whether the output suits you better. 
>   
>   
>
> On 08/28/2023 1:11 PM CEST Veera  wrote: 
>   
>   
> my ansible.cfg is a custom one which I am using from the same location and 
> it has no more specific lines to format. 
>   
> $ansible --version | grep 'ansible.cfg'
>   config file = /home/myuser/ansible/ansible.cfg
> $pwd
> /home/myuser/ansible/
> $ cat ansible.cfg
> [defaults]
> inventory = ./inventory
> host_key_checking = False
> $ 
> On Monday, August 28, 2023 at 2:59:06 PM UTC+5:30 dulh...@mailbox.org 
> wrote: 
>
> *no ansible.cfg involved* seems impossible to me. 
>   
> ansible --version | grep 'ansible.cfg' (in the location you run the 
> playbook from) should reveal which one is effective. 
>   
> Or am I understanding something badly wrong here? 
>   
>
> On 08/28/2023 11:22 AM CEST Veera  wrote: 
>   
>   
> Hi , 
>   
>  Sorry ... No *ansible.cfg*  involved. 
> After multiple filtering  of (the output) I  reached to this output.  
> I want to enhance it further .   
>
> On Monday, August 28, 2023 at 2:47:42 PM UTC+5:30 dulh...@mailbox.org 
> wrote: 
>
> wondering whether *stdout_callback: yaml* in the *ansible.cfg* might be 
> doing that 
>
> On 08/28/2023 10:56 AM CEST Veera  wrote: 
>   
>   
> Hi, 
>   
> My play book print the debug output as below  
> TASK [Print the  status of the server] 
> ***
>  
>
> ok: [localhost] => { 
> "msg": [ 
> "Extension Message: Patching Successful. 
> [ActivityId=xxx-1f8f-4e44-95af-], OperationResult: {\"
> activityId\": \"xxx-1f8f-4e44-95af-\", \"sequenceNumber\": 
> 8, \"inputStartTime\": \"2023-08-28T05:45:40.500520Z\", \"lastModifiedTime
> \": \"2023-08-28T06:14:43.449672Z\", \"extensionTriggerTime\": \"
> 2023-08-28T05:45:53.268037Z\", \"osName\": \"CentOS Stream\", \"osVersion
> \": \"8\", \"action\": \"Patching\", \"actionStatus\": \"Success\", \"
> patchServiceUsed\": \"YUM\", \"errors\": null, \"patchDetails\": {\"
> rebootNeeded\": true, \"rebootStatus\": \"Completed\", \"
> maintenanceWindowExceeded\": false, \"retriggerCount\": 61, \"
> notSelectedPatchCount\": 0, \"pendingPatchCount\": 0, \"
> installedPatchCount\": 98, \"failedPatchCount\": 0, \"patches\": \"
> xxx=\", \"
> excludedPatchCount\": 0}, \"assessmentDetails\": {\"countByCategory\": {\"
> security\": 0, \"other\": 0}, \"totalCount\": 0, \"patches\": \"
> X==\", \"rebootPending\": null}, \"logs\": \"
> yyy"}" 
> ] 
> } 
>   
> I need to break the output  like below 
>   
> Extension Message: Patching Successful. 
> [ActivityId=xxx-1f8f-4e44-95af-] 
> OperationResult: activityId: xxx-1f8f-4e44-95af- 
> sequenceNumber: 8 
> inputStartTime: 2023-08-28T05:45:40.500520Z 
> lastModifiedTime: "2023-08-28T06:14:43.449672Z 
>   
> and so on..  
>
>  
>
> -- 
>
> 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/9a1a2eea-2b38-412e-9fcb-a4f7afd6e485n%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/ansible-project/9a1a2eea-2b38-412e-9fcb-a4f7afd6e485n%40googlegroups.com?utm_medium=email&utm_source=footer>.
>  
>
>
>   
> --- 
>
> gunnar wagner | fichtestr. 1, 19386 lübz | fon: 0176 7808 9090
>

-- 
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/39c09df5-170b-4815-82f0-0046a031c5ddn%40googlegroups.com.


[ansible-project] split for data manitpulation

2023-08-29 Thread Veera
Hi,

I have this playbook to print the columns  5 and 6 using the debug.

---
- name: playbook to print columns
  hosts: localhost
  gather_facts: no
  vars:
myline: This line is a test, two, three, four, five, 6, seven 
  tasks:
- name: play to  print
  debug:
msg: 
  - "{{ myline.split(',')[5] }}"
  - "{{ myline.split(',')[6] }}"

It prints the details , But is there a way to print the columns  4,7 and 11 
with a single split option. (instead of listing under msg: )

 - name: play to  print
  debug:
msg:  "{{ myline.split(',')[4][7][11] }}"

Do split accepts only one square bracket[] parameter? 
 
  


-- 
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/61d732eb-26b2-460f-98de-1db41a6deccan%40googlegroups.com.


Re: [ansible-project] Formatting the output by line by line

2023-08-28 Thread Veera
my ansible.cfg is a custom one which I am using from the same location and 
it has no more specific lines to format.

$ansible --version | grep 'ansible.cfg'
  config file = /home/myuser/ansible/ansible.cfg
$pwd
/home/myuser/ansible/
$ cat ansible.cfg
[defaults]
inventory = ./inventory
host_key_checking = False
$
On Monday, August 28, 2023 at 2:59:06 PM UTC+5:30 dulh...@mailbox.org wrote:

> *no ansible.cfg involved* seems impossible to me. 
>   
> ansible --version | grep 'ansible.cfg' (in the location you run the 
> playbook from) should reveal which one is effective. 
>   
> Or am I understanding something badly wrong here? 
>   
>
> On 08/28/2023 11:22 AM CEST Veera  wrote: 
>   
>   
> Hi , 
>   
>  Sorry ... No *ansible.cfg*  involved. 
> After multiple filtering  of (the output) I  reached to this output.  
> I want to enhance it further .   
>
> On Monday, August 28, 2023 at 2:47:42 PM UTC+5:30 dulh...@mailbox.org 
> wrote: 
>
> wondering whether *stdout_callback: yaml* in the *ansible.cfg* might be 
> doing that 
>
> On 08/28/2023 10:56 AM CEST Veera  wrote: 
>   
>   
> Hi, 
>   
> My play book print the debug output as below  
> TASK [Print the  status of the server] 
> ***
>  
>
> ok: [localhost] => { 
> "msg": [ 
> "Extension Message: Patching Successful. 
> [ActivityId=xxx-1f8f-4e44-95af-], OperationResult: {\"
> activityId\": \"xxx-1f8f-4e44-95af-\", \"sequenceNumber\": 
> 8, \"inputStartTime\": \"2023-08-28T05:45:40.500520Z\", \"lastModifiedTime
> \": \"2023-08-28T06:14:43.449672Z\", \"extensionTriggerTime\": \"
> 2023-08-28T05:45:53.268037Z\", \"osName\": \"CentOS Stream\", \"osVersion
> \": \"8\", \"action\": \"Patching\", \"actionStatus\": \"Success\", \"
> patchServiceUsed\": \"YUM\", \"errors\": null, \"patchDetails\": {\"
> rebootNeeded\": true, \"rebootStatus\": \"Completed\", \"
> maintenanceWindowExceeded\": false, \"retriggerCount\": 61, \"
> notSelectedPatchCount\": 0, \"pendingPatchCount\": 0, \"
> installedPatchCount\": 98, \"failedPatchCount\": 0, \"patches\": \"
> xxx=\", \"
> excludedPatchCount\": 0}, \"assessmentDetails\": {\"countByCategory\": {\"
> security\": 0, \"other\": 0}, \"totalCount\": 0, \"patches\": \"
> X==\", \"rebootPending\": null}, \"logs\": \"
> yyy"}" 
> ] 
> } 
>   
> I need to break the output  like below 
>   
> Extension Message: Patching Successful. 
> [ActivityId=xxx-1f8f-4e44-95af-] 
> OperationResult: activityId: xxx-1f8f-4e44-95af- 
> sequenceNumber: 8 
> inputStartTime: 2023-08-28T05:45:40.500520Z 
> lastModifiedTime: "2023-08-28T06:14:43.449672Z 
>   
> and so on..  
>
>

-- 
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/9a1a2eea-2b38-412e-9fcb-a4f7afd6e485n%40googlegroups.com.


Re: [ansible-project] Formatting the output by line by line

2023-08-28 Thread Veera
Hi ,

 Sorry ... No *ansible.cfg*  involved.
After multiple filtering  of (the output) I  reached to this output. 
I want to enhance it further .  

On Monday, August 28, 2023 at 2:47:42 PM UTC+5:30 dulh...@mailbox.org wrote:

> wondering whether *stdout_callback: yaml* in the *ansible.cfg* might be 
> doing that 
>
> On 08/28/2023 10:56 AM CEST Veera  wrote: 
>   
>   
> Hi, 
>   
> My play book print the debug output as below  
> TASK [Print the  status of the server] 
> ***
>  
>
> ok: [localhost] => { 
> "msg": [ 
> "Extension Message: Patching Successful. 
> [ActivityId=xxx-1f8f-4e44-95af-], OperationResult: {\"
> activityId\": \"xxx-1f8f-4e44-95af-\", \"sequenceNumber\": 
> 8, \"inputStartTime\": \"2023-08-28T05:45:40.500520Z\", \"lastModifiedTime
> \": \"2023-08-28T06:14:43.449672Z\", \"extensionTriggerTime\": \"
> 2023-08-28T05:45:53.268037Z\", \"osName\": \"CentOS Stream\", \"osVersion
> \": \"8\", \"action\": \"Patching\", \"actionStatus\": \"Success\", \"
> patchServiceUsed\": \"YUM\", \"errors\": null, \"patchDetails\": {\"
> rebootNeeded\": true, \"rebootStatus\": \"Completed\", \"
> maintenanceWindowExceeded\": false, \"retriggerCount\": 61, \"
> notSelectedPatchCount\": 0, \"pendingPatchCount\": 0, \"
> installedPatchCount\": 98, \"failedPatchCount\": 0, \"patches\": \"
> xxx=\", \"
> excludedPatchCount\": 0}, \"assessmentDetails\": {\"countByCategory\": {\"
> security\": 0, \"other\": 0}, \"totalCount\": 0, \"patches\": \"
> X==\", \"rebootPending\": null}, \"logs\": \"
> yyy"}" 
> ] 
> } 
>   
> I need to break the output  like below 
>   
> Extension Message: Patching Successful. 
> [ActivityId=xxx-1f8f-4e44-95af-] 
> OperationResult: activityId: xxx-1f8f-4e44-95af- 
> sequenceNumber: 8 
> inputStartTime: 2023-08-28T05:45:40.500520Z 
> lastModifiedTime: "2023-08-28T06:14:43.449672Z 
>   
> and so on..  
>   
>
>  
>
> -- 
> 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/f7b49add-d473-4e08-9527-e3ed864ca825n%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/ansible-project/f7b49add-d473-4e08-9527-e3ed864ca825n%40googlegroups.com?utm_medium=email&utm_source=footer>.
>  
>
>
>   
> --- 
>
> gunnar wagner | fichtestr. 1, 19386 lübz | fon: 0176 7808 9090
>

-- 
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/cecd2143-9483-44c6-ba73-08cb943b7525n%40googlegroups.com.


[ansible-project] Formatting the output by line by line

2023-08-28 Thread Veera
Hi,

My play book print the debug output as below 
TASK [Print the  status of the server] 
***
ok: [localhost] => {
"msg": [
"Extension Message: Patching Successful. 
[ActivityId=xxx-1f8f-4e44-95af-], OperationResult: {\"
activityId\": \"xxx-1f8f-4e44-95af-\", \"sequenceNumber\": 
8, \"inputStartTime\": \"2023-08-28T05:45:40.500520Z\", \"lastModifiedTime\": 
\"2023-08-28T06:14:43.449672Z\", \"extensionTriggerTime\": \"
2023-08-28T05:45:53.268037Z\", \"osName\": \"CentOS Stream\", \"osVersion\": 
\"8\", \"action\": \"Patching\", \"actionStatus\": \"Success\", \"
patchServiceUsed\": \"YUM\", \"errors\": null, \"patchDetails\": {\"
rebootNeeded\": true, \"rebootStatus\": \"Completed\", \"
maintenanceWindowExceeded\": false, \"retriggerCount\": 61, \"
notSelectedPatchCount\": 0, \"pendingPatchCount\": 0, \"installedPatchCount
\": 98, \"failedPatchCount\": 0, \"patches\": \"
xxx=\", \"
excludedPatchCount\": 0}, \"assessmentDetails\": {\"countByCategory\": {\"
security\": 0, \"other\": 0}, \"totalCount\": 0, \"patches\": \"
X==\", \"rebootPending\": null}, \"logs\": \"
yyy"}"
]
}

 
I need to break the output  like below

Extension Message: Patching Successful. 
[ActivityId=xxx-1f8f-4e44-95af-]
OperationResult: activityId: xxx-1f8f-4e44-95af-
sequenceNumber: 8
inputStartTime: 2023-08-28T05:45:40.500520Z
lastModifiedTime: "2023-08-28T06:14:43.449672Z

and so on.. 

-- 
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/f7b49add-d473-4e08-9527-e3ed864ca825n%40googlegroups.com.


[ansible-project] Re: uri post to avoid duplicate

2023-08-23 Thread Veera
Thanks .. I am able to achieve it with the above logic and with "assert"  
module for exiting the playbook if failed . 

On Saturday, August 19, 2023 at 10:34:16 PM UTC+5:30 Atul Nasir wrote:

> - name: Check if project name exists
>   uri:
> url: "{{ webapp_url }}/api/orgs"
> method: GET
> return_content: yes
> validate_certs: no
> user: "{{ user }}"
> password: "{{ password }}"
> force_basic_auth: yes
>   register: existing_projects
>
> - name: Check if project name exists in the response
>   set_fact:
> project_already_exists: "{{ project_name in existing_projects.json | 
> json_query('*.name') }}"
>
> - name: REST POST Example if project name doesn't exist
>   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
>   when: not project_already_exists
>
> On Thursday, August 17, 2023 at 1:18:48 AM UTC-7 Veera wrote:
>
>> 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/60255b5e-09af-4ff2-acf8-a428c981e954n%40googlegroups.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.


Re: [ansible-project] reading the key file contents

2023-08-08 Thread Veera
Hi all,

Thanks for the valuable inputs and directions . 
I was looking for a new approach which I was failing and you all confirmed 
the best and secure way is to have the key as a file with  appropriate 
permissions .  I will be proceeding with the same setup which I already 
have ..



On Tuesday, August 8, 2023 at 4:01:02 AM UTC+5:30 Brian Coca wrote:

> You cannot use a string for an ssh key, it is a file as ansible must
> pass a file to `ssh` command line client (which does not accept a
> string).
> If you only have a string, you have to write the string to a file
> before the connection starts and remove it once it ends. doing this
> securely is not trivial and the reason the ssh connection plugin does
> not attempt to do so.
> -- 
> --
> 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/0792e9c1-dc6a-4b66-8196-6e2e2ed831a2n%40googlegroups.com.


Re: [ansible-project] Re: Filtering_data manipulation

2023-08-07 Thread Veera
Thanks all ..
I am able to get the desired output with templates ..

On Tuesday, August 1, 2023 at 11:04:35 AM UTC+5:30 Felix Fontein wrote:

> Hi,
>
> > Yes. Or if you feel like ignoring the warnings^* about using
> > variables in copy's "content":
> > 
> > - name: Write to the file
> >   ansible.builtin.copy:
> > content: |
> > {% for server in servers %}
> > {{ server }}
> > {% endfor %}
> > dest: "{{my_inv}}"
> > 
> > ^* I do it quite often, looking for cases where the promised
> > unexpected surprises happen, but I haven't found them yet. It'll
> > probably happen some day when it least convenient. :)
>
> I got bitten by this somewhen in the past when the input for `content`
> turned out to be valid JSON. Ansible parsed it and converted it to the
> Python representation of the dictionary, which wasn't valid JSON
> anymore (`"` converted to `'`).
>
> But that's something rather special, for many simple templates such as
> yours it's no problem at all (and I also use `content` for that).
>
> Cheers,
> Felix
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/24cfe05d-7c60-4909-9dca-a016aba18723n%40googlegroups.com.


[ansible-project] reading the key file contents

2023-08-07 Thread Veera
In a playbook , I gathered the user key into the variable "user_key"  and 
using a add_host module to login to the server and execute the required  
tasks .

- name: Writing the key to a file 
  ansible.builtin.copy:
content: "{{ user_key }}"
dest: /tmp/new_inst.pem
mode: '0600'
follow: yes
  register: keyfile


- name:  create a temp inventory
  ansible.builtin.add_host:
hostname: '{{ servera }}'
groups: mygroup
ansible_ssh_private_key_file: "{{ keyfile.dest }}"
ansible_ssh_user: "root"
ansible_ssh_extra_args: '-o StrictHostKeyChecking=no'

- name: validate the httpd in new hosts
  hosts: mygroup
  gather_facts: true
  become: yes
  environment:
ANSIBLE_HOST_KEY_CHECKING: "False"
  tasks:
- name: Start service httpd, if not started
  service:
name: httpd
   state: started
   
All works fine  using the above.
However is there an option to read the  content of the key directly , read 
the contents of the keyfile to the  add_host  module  with something like 
"ansible_ssh_private_key" ??
I want to avoid writing the key to a file, chmod 600 and then  remove it 
after execution.

Also ,  is there a  way to  read the variable "user_key"   when manually 
feed during the  ansible-playbook command , like  for the same above codes 
usage .

# ansible-playbook playbook -e "user_key={{ssh_content}}"
where  ssh_contentis a python variable which  have the  exact key_value 
details from another  program 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/bf4f3205-cc71-4584-a607-ceece3ae2d5dn%40googlegroups.com.


Re: [ansible-project] Executing ansible through SSH

2023-08-04 Thread Veera
Thanks .. its working now

On Friday, August 4, 2023 at 4:14:49 PM UTC+5:30 Dick Visser wrote:

> Try removing the semi colon after false 
>
> On Fri, 4 Aug 2023 at 12:25, Veera  wrote:
>
>> Hi ,
>>
>> I have 3 servers serverA ,serverB , and serverC.
>> From serverA , I am trying to execute the playbook on serverB  which is 
>> the control node(Where ansible is available).
>>
>> The playbook when run from serverB(login with ssh) with executing as 
>> below works fine and got the expected output. 
>>  
>> # export ANSIBLE_HOST_KEY_CHECKING=False 
>> # ansible-playbook /home/ansible/playbook1.yml --limit serverC  
>> --key-file /home/ansible/priv_key.file
>>
>> The playbook has "become: true" 
>>
>> From ServerA ,  I am executing the  below command using a bash script and 
>> the script works. But the execution is not happening 
>>
>> #!/bin/bash
>> ssh   -i  .ssh/serverb_key  root@serverB  "export 
>> ANSIBLE_HOST_KEY_CHECKING=False; ansible-playbook 
>>  /home/ansible/playbook1.yml --limit serverC  --key-file 
>> /home/ansible/priv_key.file"
>>
>> The requirement is  to initiate the script from serverA  -  which will 
>> execute the playbook in serverB and do the changes in serverC. 
>>  I even try with the "&" at the end to execute the ansible-playbook in 
>> the background ..but still the same result.  ""export 
>> ANSIBLE_HOST_KEY_CHECKING=False; ansible-playbook 
>>  /home/ansible/playbook1.yml --limit serverC  --key-file 
>> /home/ansible/priv_key.file &"
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> -- 
>> 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/591279df-3595-477f-a30f-dc86a4ea5959n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/591279df-3595-477f-a30f-dc86a4ea5959n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> -- 
> 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/71155c6e-e096-484f-86ef-b055d0cf390cn%40googlegroups.com.


[ansible-project] Executing ansible through SSH

2023-08-04 Thread Veera
Hi ,

I have 3 servers serverA ,serverB , and serverC.
>From serverA , I am trying to execute the playbook on serverB  which is the 
control node(Where ansible is available).

The playbook when run from serverB(login with ssh) with executing as below 
works fine and got the expected output. 
 
# export ANSIBLE_HOST_KEY_CHECKING=False 
# ansible-playbook /home/ansible/playbook1.yml --limit serverC  --key-file 
/home/ansible/priv_key.file

The playbook has "become: true" 

>From ServerA ,  I am executing the  below command using a bash script and 
the script works. But the execution is not happening 

#!/bin/bash
ssh   -i  .ssh/serverb_key  root@serverB  "export 
ANSIBLE_HOST_KEY_CHECKING=False; ansible-playbook 
 /home/ansible/playbook1.yml --limit serverC  --key-file 
/home/ansible/priv_key.file"

The requirement is  to initiate the script from serverA  -  which will 
execute the playbook in serverB and do the changes in serverC. 
 I even try with the "&" at the end to execute the ansible-playbook in the 
background ..but still the same result.  ""export 
ANSIBLE_HOST_KEY_CHECKING=False; ansible-playbook 
 /home/ansible/playbook1.yml --limit serverC  --key-file 
/home/ansible/priv_key.file &"











-- 
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/591279df-3595-477f-a30f-dc86a4ea5959n%40googlegroups.com.


[ansible-project] Re: Filtering_data manipulation

2023-07-31 Thread Veera
Here it is 

TASK [debug] 
**
ok: [localhost] => {
"msg": [
"servera",
"serverb",
"serverc",
"serverd",
"centos8-latest"
]
}

TASK [debug] 
**
ok: [localhost] => {
"msg": "The List of VMs   is  ['servera', 'serverb', 'serverc', 
'serverd',  'centos8-latest']"
}

TASK [write the server list to the file /tmp/output.txt] 
**
ok: [localhost]

PLAY RECAP 

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

$ cat /tmp/output.txt
["servera", "serverb", "serverc", "serverd", "centos8-latest"]

On Tuesday, August 1, 2023 at 12:17:12 AM UTC+5:30 Todd Lewis wrote:

> I mean, what does the output of
>
> - name: Dump result
>   ansible.builtin.debug:
> msg: "{{ result }}"
>
> look like? It presumably has a 'json' field? Which itself contains a 
> 'value'?
> Without a reasonable approximation of your input, I can't possibly suggest 
> how to create expected output from it.
>
> On Monday, July 31, 2023 at 2:43:20 PM UTC-4 Veera wrote:
>
>> it looks like 
>> 'servera',  'serverb', 'serverc', 'serverd'
>>
>>
>> and I want result to be like ..
>> $cat /tmp/my_inv
>> servera
>> serverb
>> serverc
>> serverd
>>
>>
>> On Tuesday, August 1, 2023 at 12:00:58 AM UTC+5:30 Todd Lewis wrote:
>>
>>> What does your "result" look like?
>>>
>>> On Monday, July 31, 2023 at 1:11:16 PM UTC-4 Veera wrote:
>>>
>>>> While collecting the inventory from a dynamic source , I am able to  
>>>> filter the hostname and print them as below as expected.
>>>>
>>>> servera
>>>> serverb
>>>> serverc
>>>> serverd
>>>>
>>>> when set to facts with set_fact  also fine  and print in the order one 
>>>> below the other.
>>>> However when I try to write into a file with copy module , 
>>>>  
>>>> - name:  Write to the file 
>>>>   ansible.builtin.copy:
>>>> content: "{{ result['json']['value'] |map(attribute='hostname') 
>>>> }}"
>>>> dest: "{{my_inv}}" 
>>>>
>>>> the format collapses as below.
>>>> 'servera',  'serverb', 'serverc', 'serverd'
>>>>
>>>> How can I write the  output  in the list format(line by line)  as  this 
>>>> file will be used to read  as an inventory for other tasks . 
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>

-- 
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/a7a2ddf1-1da3-4576-96fe-252da18d8394n%40googlegroups.com.


[ansible-project] Re: Filtering_data manipulation

2023-07-31 Thread Veera
it looks like 
'servera',  'serverb', 'serverc', 'serverd'


and I want result to be like ..
$cat /tmp/my_inv
servera
serverb
serverc
serverd


On Tuesday, August 1, 2023 at 12:00:58 AM UTC+5:30 Todd Lewis wrote:

> What does your "result" look like?
>
> On Monday, July 31, 2023 at 1:11:16 PM UTC-4 Veera wrote:
>
>> While collecting the inventory from a dynamic source , I am able to  
>> filter the hostname and print them as below as expected.
>>
>> servera
>> serverb
>> serverc
>> serverd
>>
>> when set to facts with set_fact  also fine  and print in the order one 
>> below the other.
>> However when I try to write into a file with copy module , 
>>  
>> - name:  Write to the file 
>>   ansible.builtin.copy:
>> content: "{{ result['json']['value'] |map(attribute='hostname') 
>> }}"
>> dest: "{{my_inv}}" 
>>
>> the format collapses as below.
>> 'servera',  'serverb', 'serverc', 'serverd'
>>
>> How can I write the  output  in the list format(line by line)  as  this 
>> file will be used to read  as an inventory for other tasks . 
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>

-- 
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/ae265b5e-0464-49ef-bf4a-1366bab82b7bn%40googlegroups.com.


[ansible-project] Filtering_data manipulation

2023-07-31 Thread Veera
While collecting the inventory from a dynamic source , I am able to  filter 
the hostname and print them as below as expected.

servera
serverb
serverc
serverd

when set to facts with set_fact  also fine  and print in the order one 
below the other.
However when I try to write into a file with copy module , 
 
- name:  Write to the file 
  ansible.builtin.copy:
content: "{{ result['json']['value'] |map(attribute='hostname') }}"
dest: "{{my_inv}}" 

the format collapses as below.
'servera',  'serverb', 'serverc', 'serverd'

How can I write the  output  in the list format(line by line)  as  this 
file will be used to read  as an inventory for other tasks . 









-- 
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/5b260cfe-2fff-4baf-a5fc-51eadb41234en%40googlegroups.com.


Re: [ansible-project] handling error codes

2023-07-31 Thread Veera
Thanks Todd,  

It worked and  Yes I  could have referred the doc status_code 
<https://docs.ansible.com/ansible/latest/collections/ansible/builtin/uri_module.html#parameter-status_code>
  in 
depth  . 

On Monday, July 31, 2023 at 5:43:04 PM UTC+5:30 Todd Lewis wrote:

> status_code 
> <https://docs.ansible.com/ansible/latest/collections/ansible/builtin/uri_module.html#parameter-status_code>
>  
> takes a list. The default is [200], but you can say
>
> status_code:
>   - 200
>   - 409
>
> Cheers,
> --
> Todd
>
>
> On 7/31/23 7:56 AM, Veera wrote:
>
> Hi , 
>
> I have a playbook  with the  below lines .
>
> $ cat double_check.yml
> ---
> - name: playbook to test the status of the web
>   hosts: centos8-latest
>   tasks:
> - block:
> - name: Install the  httpd packages
>   ansible.builtin.yum:
> name: httpd
> state: latest
>
> - name: Enable and Start the httpd service
>   ansible.builtin.service:
> name: httpd
> state: started
> enabled: true
>
> - name: Check web site from web server
>   ansible.builtin.uri:
> url: http://{{ ansible_fqdn }}
> return_content: true
> status_code: 200
>   register: example_webpage
>   failed_when: example_webpage.status != 200
>
>
>
>   rescue:
> - name: Restart web server
>   ansible.builtin.service:
> name: httpd
> state: restarted
>
> #we still can have handlers to  demo this playbook  
>
> This Playbook works as expected  until  the status code is 200.
> [user@centos8-latest html]$ ls -l
> total 4
> -rw-r--r-- 1 root root 104 Jul 28 10:36 index.html
> [user@centos8-latest html]#
>
> If there is no index.html , CentOS/redhat  shows its  apache foundation 
> page which is returning a different  status code[409 ] . which is causing 
> the task to fail .
>
> I am expecting  the Status Code 200  [success] ,  409[already running] and 
> 404/others[failed]
> How can we handle this error?  Ignore_error=yes  is not required.
> If  Status Code = 200 , then no change required . ( a handler to be 
> called  after that )
> if status code=409 , it should pass and still continue to next task (if 
> added). (no handler to be called  )
> other codes/404 can fail.
>
>
> Is there an option to declare "status code =200 or 409 "in the single line?
> Or we have to  handle them with 2 different play ? possible ?
>
>
>

-- 
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/5b03c9d4-09a3-483f-9025-3b65cef97509n%40googlegroups.com.


[ansible-project] handling error codes

2023-07-31 Thread Veera
Hi ,

I have a playbook  with the  below lines .

$ cat double_check.yml
---
- name: playbook to test the status of the web
  hosts: centos8-latest
  tasks:
- block:
- name: Install the  httpd packages
  ansible.builtin.yum:
name: httpd
state: latest

- name: Enable and Start the httpd service
  ansible.builtin.service:
name: httpd
state: started
enabled: true

- name: Check web site from web server
  ansible.builtin.uri:
url: http://{{ ansible_fqdn }}
return_content: true
status_code: 200
  register: example_webpage
  failed_when: example_webpage.status != 200



  rescue:
- name: Restart web server
  ansible.builtin.service:
name: httpd
state: restarted

#we still can have handlers to  demo this playbook  

This Playbook works as expected  until  the status code is 200.
[user@centos8-latest html]$ ls -l
total 4
-rw-r--r-- 1 root root 104 Jul 28 10:36 index.html
[user@centos8-latest html]#

If there is no index.html , CentOS/redhat  shows its  apache foundation 
page which is returning a different  status code[409 ] . which is causing 
the task to fail .

I am expecting  the Status Code 200  [success] ,  409[already running] and 
404/others[failed]
How can we handle this error?  Ignore_error=yes  is not required.
If  Status Code = 200 , then no change required . ( a handler to be called  
after that )
if status code=409 , it should pass and still continue to next task (if 
added). (no handler to be called  )
other codes/404 can fail.


Is there an option to declare "status code =200 or 409 "in the single line?
Or we have to  handle them with 2 different play ? possible ?





-- 
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/8a3da674-b6cb-4868-ae41-9d690f7b6ca9n%40googlegroups.com.


Re: [ansible-project] Variable to be selected from the options

2023-07-26 Thread Veera
Thanks Walter

On Wednesday, July 26, 2023 at 6:31:15 PM UTC+5:30 Rowe, Walter P. (Fed) 
wrote:

> Using ansible's order of precedence you can set the default value in the 
> playbook and override it with extra_vars.
>
>
> *override.yaml:*
>
>
> ---
>
> - name: test overriding playbook variable
>
>   hosts: all
>
>   become: false
>
>   gather_facts: false
>
>   vars:
>
> rebootSetting: "ifRequired"
>
>   tasks:
>
> - name: reboot setting
>
>   debug: var=rebootSetting
>
>
> *Execution: note the first test does not provide an extra_var value for 
> rebootSetting, while the second and third do provide one.*
>
>
> *% ansible-playbook -i localhost, override.yaml *
>
>
> PLAY [test overriding playbook variable] 
> ***
>
>
> TASK [reboot setting] 
> **
>
> ok: [localhost] => {
>
> "rebootSetting": "ifRequired"
>
> }
>
>
> PLAY RECAP 
> *
>
> localhost  : ok=1changed=0unreachable=0
> failed=0skipped=0rescued=0ignored=0   
>
>
> *% ansible-playbook -i localhost, override.yaml -e rebootSetting=Never*
>
>
> PLAY [test overriding playbook variable] 
> ***
>
>
> TASK [reboot setting] 
> **
>
> ok: [localhost] => {
>
> "rebootSetting": "Never"
>
> }
>
>
> PLAY RECAP 
> *
>
> localhost  : ok=1changed=0unreachable=0
> failed=0skipped=0rescued=0ignored=0   
>
>
> *% ansible-playbook -i localhost, override.yaml -e rebootSetting=Always*
>
>
> PLAY [test overriding playbook variable] 
> ***
>
>
> TASK [reboot setting] 
> **
>
> ok: [localhost] => {
>
> "rebootSetting": "Always"
>
> }
>
>
> PLAY RECAP 
> *****
>
> localhost  : ok=1changed=0unreachable=0
> failed=0skipped=0rescued=0ignored=0   
>
>
>
> Walter
> --
> Walter Rowe, Division Chief
> Infrastructure Services, OISM
> Mobile: 202.355.4123 <(202)%20355-4123>
>
> On Jul 26, 2023, at 8:39 AM, Veera  wrote:
>
> Hi, 
>
> I have the below variable defined  in my playbook.
> reboot_option: 
> - IfRequired
> - Never
>  - Always
>
> while calling the same  variable from the playbook ,   the value 
> "IfRequired'  must be the default.
>  "rebootSetting": "{{ reboot_option | default(Ifrequired) }}" 
>
> While executing the playbook without extra-vars reboot_option then by 
> "ifrequired " need to the default,.
> If the playbook is executed with -e "reboot_option=Never" or "Always"  
> then it should select the given option.
>
> how to call the dictionary items with default as "Ifrequired"? 
> Or I have to declare  the variables in a different way ?
>
>
>
>
>
>
> -- 
> 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/90154402-8d8b-4041-8a9f-d1bbea023a6en%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/ansible-project/90154402-8d8b-4041-8a9f-d1bbea023a6en%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
>

-- 
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/eef714c1-9047-488a-a3aa-cf0311bf5985n%40googlegroups.com.


[ansible-project] Variable to be selected from the options

2023-07-26 Thread Veera
Hi,

I have the below variable defined  in my playbook.
reboot_option: 
- IfRequired
- Never
 - Always

while calling the same  variable from the playbook ,   the value 
"IfRequired'  must be the default.
 "rebootSetting": "{{ reboot_option | default(Ifrequired) }}" 

While executing the playbook without extra-vars reboot_option then by 
"ifrequired " need to the default,.
If the playbook is executed with -e "reboot_option=Never" or "Always"  then 
it should select the given option.

how to call the dictionary items with default as "Ifrequired"? 
Or I have to declare  the variables in a different way ?





-- 
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/90154402-8d8b-4041-8a9f-d1bbea023a6en%40googlegroups.com.


Re: [ansible-project] lineinfile module to replace a string

2023-06-21 Thread Veera
Thanks . It worked as expected 

On Tuesday, June 20, 2023 at 1:46:19 AM UTC+5:30 Dick Visser wrote:

> On Mon, 19 Jun 2023 at 21:37, Veera  wrote:
>
>> Yes.. It's basically another yaml file. 
>>
>> I'm asking because string manipulation of otherwise structured data will 
> become messy quickly - as you have found out.
> If you must keep all the comments then you'll have to use logic to handle 
> that.
> Whenever someone edits the file, or by some software update, your logic 
> might break.
> I would either template the entire thing out, based on a config that you 
> have in your ansible code.
> Or, use a combination of slurp and write out the structure. This will 
> remove any comments, but one could argue that that is not required anyway.
> For example:
>
>   vars:
> filename:* /etc/myagent/myfile*
> config_opts:
>   logging.files:
> path: /var/log/newfile
>
>   tasks:
> - slurp:
> src: "{{ filename }}"
>   register: foo
>
> - set_fact:
> foo: "{{ foo.content | b64decode | from_yaml | 
> combine(config_opts) }}"
>
> - copy:
> content: "{{ foo | to_nice_yaml }}"
> dest: "{{ filename }}"
>
>

-- 
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/88283545-d526-4cc5-8106-3abb1c2dd51cn%40googlegroups.com.


Re: [ansible-project] lineinfile module to replace a string

2023-06-19 Thread Veera
Yes.. It's basically another yaml file.

On Tue, 20 Jun, 2023, 12:24 am Dick Visser,  wrote:

> What kind of file is this?
> It looks like yaml?
>
> On Mon, 19 Jun 2023 at 18:47, Veera  wrote:
>
>> Hi,
>>
>> I am trying to replace a  line/string   in a 224   lines file .
>> Trying with replace and lineinfile module  , but seems i am missing a
>> bit..
>>
>> below is the string to consider:
>>
>> logging.files:
>>   # Configure the path where the logs are written. The default is the
>> logs directory
>>   # under the home path (the binary location).
>>   path: /var/log/original
>> .
>> Here I want to replace the " /var/log/original"  to " /var/log/newfile"
>> and I have to search based on the string "logging.files:"  which is 3 lines
>> above.
>>
>>
>>
>> *- name: Configuring the inputs for the filereplace:path:
>> /etc/myagent/myfile*
>> *after: 'logging.files:'here  i want to search 4th  line below
>> the match.. similar to grep -A3)*
>>
>>
>> *regexp: ' path: /var/log/original 'replace: " path:
>> /var/log/newfile  "*
>>
>> * I have multiple lines with similar entries and I cannot replace
>> directly (based on first match too)*
>>
>> --
>> 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/2f54435b-b00c-48b5-b349-53f2953c5725n%40googlegroups.com
>> <https://groups.google.com/d/msgid/ansible-project/2f54435b-b00c-48b5-b349-53f2953c5725n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> Sent from Gmail Mobile
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ansible-project/hIYZwIgSsgc/unsubscribe.
> To unsubscribe from this group and all its topics, 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/CAF8BbLbPajg-fNs1sc-kW9EtQENxOxsrZQM3hZdmrRu7GgkkEA%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CAF8BbLbPajg-fNs1sc-kW9EtQENxOxsrZQM3hZdmrRu7GgkkEA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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/CALNY%2B%2BRhudqcCHQobHMxXYuZQfmUygKAMQwqr9TTuvRBidkD0Q%40mail.gmail.com.


[ansible-project] lineinfile module to replace a string

2023-06-19 Thread Veera
Hi,

I am trying to replace a  line/string   in a 224   lines file .
Trying with replace and lineinfile module  , but seems i am missing a bit..

below is the string to consider:

logging.files:
  # Configure the path where the logs are written. The default is the logs 
directory
  # under the home path (the binary location).
  path: /var/log/original
.
Here I want to replace the " /var/log/original"  to " /var/log/newfile"  
and I have to search based on the string "logging.files:"  which is 3 lines 
above.  



*- name: Configuring the inputs for the filereplace:path: 
/etc/myagent/myfile*
*after: 'logging.files:'here  i want to search 4th  line below the 
match.. similar to grep -A3)*


*regexp: ' path: /var/log/original 'replace: " path: 
/var/log/newfile  "*

* I have multiple lines with similar entries and I cannot replace directly 
(based on first match too)*

-- 
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/2f54435b-b00c-48b5-b349-53f2953c5725n%40googlegroups.com.


Re: [ansible-project] Calling the inventory created by first task to the second one

2023-06-14 Thread Veera
Thanks a lot  . I am able to overcome it .
I was missing the   indent after the add_host earlier for the second task 
and now I can .

On Wednesday, June 14, 2023 at 6:18:25 PM UTC+5:30 Dick Visser wrote:

>
> https://docs.ansible.com/ansible/latest/collections/ansible/builtin/add_host_module.html
>
> On Wed, 14 Jun 2023 at 14:33, Veera  wrote:
>
>> Hi,
>>
>> I have a  playbook book with 2 tasks in it .
>> In the first tasks, I have playbooks to create a VM  and  build OS  on 
>> it  and  able to login  to the VM manually (for testing)  , and the final 
>> play creates a temporary  inventory file like below.
>>
>> [dev-vm1]
>> mytestvm1 ansible_ssh_private_key_file: mykey.pem   ansible_ssh_user: 
>> "root" ansible_ssh_extra_args: '-o StrictHostKeyChecking=no'
>>
>> the second tasks has a bunch of plays which needs to login to the 
>> mytestvm1(using the temp inventory file)above and execute  .
>>
>> I have a main.yml like this 
>>
>> - name: main.play
>>   hosts: localhost
>>   tasks:
>>   play1:
>>   play2:
>>   play3
>>
>> - hosts:  dev-vm1
>>   become: true 
>>   gather_facts: true 
>>   tasks: 
>>play1:
>>play2:
>>play2
>> 
>> I don't want to 
>>- split them into 2 separate  playbooks
>> - run with  -i inventory file 
>>
>> want to pass the inventory directly to be processed by the second play ...
>> 
>>
>>
>>
>>
>>
>>
>> -- 
>> 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/f94670a3-f141-49ab-94ad-7c1cdd8e3fdan%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/f94670a3-f141-49ab-94ad-7c1cdd8e3fdan%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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/6a346b6e-8442-4061-9836-4ab890d61cf7n%40googlegroups.com.


[ansible-project] Calling the inventory created by first task to the second one

2023-06-14 Thread Veera
Hi,

I have a  playbook book with 2 tasks in it .
In the first tasks, I have playbooks to create a VM  and  build OS  on it  
and  able to login  to the VM manually (for testing)  , and the final play 
creates a temporary  inventory file like below.

[dev-vm1]
mytestvm1 ansible_ssh_private_key_file: mykey.pem   ansible_ssh_user: 
"root" ansible_ssh_extra_args: '-o StrictHostKeyChecking=no'

the second tasks has a bunch of plays which needs to login to the 
mytestvm1(using the temp inventory file)above and execute  .

I have a main.yml like this 

- name: main.play
  hosts: localhost
  tasks:
  play1:
  play2:
  play3

- hosts:  dev-vm1
  become: true 
  gather_facts: true 
  tasks: 
   play1:
   play2:
   play2

I don't want to 
   - split them into 2 separate  playbooks
- run with  -i inventory file 

want to pass the inventory directly to be processed by the second play ...







-- 
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/f94670a3-f141-49ab-94ad-7c1cdd8e3fdan%40googlegroups.com.


[ansible-project] Formatting with set_fact

2023-06-13 Thread Veera
Hi, 

While using set_facts , I am combining a hostname and dns name .
myhost = linuxhost1
mydns = example.com.

while  combining them  with set_fact 

ansible.builtin.set_fact:
   my_fqdn:  "{{myhost}}.{{mydns}}"
  
This gives the desired output of "linuxhost1.example.com." 
The last dot can be cut with [:-1] with debug , however I want to set this 
in set_fact itself as I am trying to write the FQDN without a dot to the 
inventory file. 




-- 
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/ebdb13fe-035d-473a-9904-277a11d8e285n%40googlegroups.com.


Re: [ansible-project] Formatting in debug

2023-05-17 Thread Veera
The setfact task has  the contents of a  keystone rc file .  
However I  got the result by writing it into a file , replace the string, 
read the required lines and then deleted the file ..

On Monday, May 15, 2023 at 3:32:21 PM UTC+5:30 Dick Visser wrote:

> On Mon, 15 May 2023 at 10:25, Veera  wrote:
> >
> >
> > yes... I was using set_fact and the output shown above is the debug 
> output of the set_fact.
>
> OK, so my question is: what does your set_fact task look like? I.e.
> where do you get that string from?
>

-- 
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/2c2b1e20-d691-457c-8a4d-6b0c4e3a558bn%40googlegroups.com.


Re: [ansible-project] Formatting in debug

2023-05-15 Thread Veera

yes...  I was using set_fact and the output shown above is  the debug 
output of the set_fact.

Still to fetch the URL alone from the output(debug) of the set_fact ,  and 
to set it as a new variable( using set_fact) ... which is what i am looking 
for .. 

On Monday, May 15, 2023 at 1:27:54 PM UTC+5:30 Dick Visser wrote:

> On Mon, 15 May 2023 at 08:24, Veera  wrote:
>
>> Hello,
>>
>> While i try to  grep/cut the url from my below debug output , I am unable 
>> to get the exact output.  I tried with split, dict2items ,item2dicts  to 
>> break it and grep the exact line . 
>>
>> TASK [debug] 
>> *
>> Monday 15 May 2023  09:10:06 +0300 (0:00:00.027)   0:00:02.906 
>> 
>> ok: [localhost] => {
>> "msg": "export OS_AUTH_URL=https://mydomain.net:9001/v3\nexport 
>> OS_PROJECT_ID=abcdefghijklmnopqwertyuu\nexport OS_PROJECT_NAME=\"
>> my_project\"\nexport OS_USER_DOMAIN_NAME=\"Default\"\nif [ -z \"
>> $OS_USER_DOMAIN_NAME\" ]; then unset OS_USER_DOMAIN_NAME; fi\nexport 
>> OS_PROJECT_DOMAIN_ID=\"default\"\nif [ -z \"$OS_PROJECT_DOMAIN_ID\" ]; 
>> then unset OS_PROJECT_DOMAIN_ID; fi\nunset OS_TENANT_ID\nunset 
>> OS_TENANT_NAME\nexport OS_USERNAME=\"my_project\"\nexport 
>> OS_INTERFACE=public\nexport OS_IDENTITY_API_VERSION=3"
>> }
>>
>>
>>
>>  I need only the  string "https://mydomain.net:9001/v3";
>> from the above debug output as a variable for my next play .
>>
>>
> Don't parse the console output, use set_fact to fetch it.
> The important question is: what does your debug command look like?
> It all sounds like you should be doing something simpler earlier on
>
>
>

-- 
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/3457c537-3fef-4ff2-82fa-79b8d636ac36n%40googlegroups.com.


Re: [ansible-project] Formatting in debug

2023-05-14 Thread Veera
Hi,

No  STDOUT  or stdout_lines present.  After "msg" the output has only one 
line inside a {} .

On Monday, May 15, 2023 at 12:04:25 PM UTC+5:30 Kosala Atapattu wrote:

> If you get more verbose, you the the output with STDOUT and STDOUT_LINES. 
> STDOUT_LINESis the closest you get for what you're after. May be 
> callback_plugin may help... not sure, never tried that.
>
> Cheers,
> *Kosala*
>
>
>
>
> On Mon, May 15, 2023 at 6:24 PM Veera  wrote:
>
>> Hello,
>>
>> While i try to  grep/cut the url from my below debug output , I am unable 
>> to get the exact output.  I tried with split, dict2items ,item2dicts  to 
>> break it and grep the exact line . 
>>
>> TASK [debug] 
>> *
>> Monday 15 May 2023  09:10:06 +0300 (0:00:00.027)   0:00:02.906 
>> 
>> ok: [localhost] => {
>> "msg": "export OS_AUTH_URL=https://mydomain.net:9001/v3\nexport 
>> OS_PROJECT_ID=abcdefghijklmnopqwertyuu\nexport OS_PROJECT_NAME=\"
>> my_project\"\nexport OS_USER_DOMAIN_NAME=\"Default\"\nif [ -z \"
>> $OS_USER_DOMAIN_NAME\" ]; then unset OS_USER_DOMAIN_NAME; fi\nexport 
>> OS_PROJECT_DOMAIN_ID=\"default\"\nif [ -z \"$OS_PROJECT_DOMAIN_ID\" ]; 
>> then unset OS_PROJECT_DOMAIN_ID; fi\nunset OS_TENANT_ID\nunset 
>> OS_TENANT_NAME\nexport OS_USERNAME=\"my_project\"\nexport 
>> OS_INTERFACE=public\nexport OS_IDENTITY_API_VERSION=3"
>> }
>>
>>
>>
>>  I need only the  string "https://mydomain.net:9001/v3";
>> from the above debug output as a variable for my next play .
>>
>>
>>
>>
>> -- 
>> 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/7bc37be6-dd57-47c4-b634-54cb521489b5n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/7bc37be6-dd57-47c4-b634-54cb521489b5n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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/154966ff-2723-49b0-9100-f32471f90f24n%40googlegroups.com.


[ansible-project] Formatting in debug

2023-05-14 Thread Veera
Hello,

While i try to  grep/cut the url from my below debug output , I am unable 
to get the exact output.  I tried with split, dict2items ,item2dicts  to 
break it and grep the exact line . 

TASK [debug] 
*
Monday 15 May 2023  09:10:06 +0300 (0:00:00.027)   0:00:02.906 

ok: [localhost] => {
"msg": "export OS_AUTH_URL=https://mydomain.net:9001/v3\nexport 
OS_PROJECT_ID=abcdefghijklmnopqwertyuu\nexport OS_PROJECT_NAME=\"my_project
\"\nexport OS_USER_DOMAIN_NAME=\"Default\"\nif [ -z \"$OS_USER_DOMAIN_NAME\" 
]; then unset OS_USER_DOMAIN_NAME; fi\nexport OS_PROJECT_DOMAIN_ID=\"default
\"\nif [ -z \"$OS_PROJECT_DOMAIN_ID\" ]; then unset OS_PROJECT_DOMAIN_ID; fi
\nunset OS_TENANT_ID\nunset OS_TENANT_NAME\nexport OS_USERNAME=\"my_project
\"\nexport OS_INTERFACE=public\nexport OS_IDENTITY_API_VERSION=3"
}



 I need only the  string "https://mydomain.net:9001/v3";
from the above debug output as a variable for my next play .




-- 
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/7bc37be6-dd57-47c4-b634-54cb521489b5n%40googlegroups.com.


[ansible-project] Re: printing the items on dictionary format

2023-03-16 Thread Veera
Thanks Todd,

It works . 

"Not sure what you're trying to do with subelements."   -  I want to avoid 
 printing messages of  other dict items ( asia) from vars  during the 
execution (in the  skipping), which prints some sensitive info on the 
screen.  
Turning on no_log  is not helpful in registering the output. 
So , I was trying to call only the variables under n_america when I 
 execute the task  and i got it .  However for now skipping shows the items 
from asia during the play .



 

On Wednesday, March 15, 2023 at 12:03:29 AM UTC+5:30 Todd Lewis wrote:

> Not sure what you're trying to do with subelements.
> You could do this:
> ---
> - name: Print world details
>
>   hosts: localhost
>   gather_facts: no
>   vars:
> world:
>   asia:
> country: india
> state:   maha
> city:mumbai
>   n_america:
> nation:   canada
> province: quebec
> city: montreal
>   tasks:
> - name: Printing details of montreal
>   ansible.builtin.debug:
> msg: "{{ item.value.city | default(item.key ~ ' has no city') }}"
>   loop: "{{ world | dict2items }}"
>   when: item.key == 'n_america'
>
> On Tuesday, March 14, 2023 at 8:58:27 AM UTC-4 Veera wrote:
>
>> I have the items defined in  the file  vars/myvars.yml as below:
>>
>> *world:*
>> * asia:*
>> * country:  india*
>> * state: maha *
>> * city:mumbai*
>>  
>> * n_america:*
>> *   nation:  canada*
>> *   province : quebec*
>> *   city:  montreal*
>>
>> When I try to  print them with a loop and subelements , i am missing 
>> something 
>> * - name:  play to print the details*
>> *   hosts: localhost*
>> *   gather_facts: no*
>> *   vars: *
>> *- vars/myvars.yml*
>> *   tasks:*
>> *   - name: printing the details of montreal*
>> *  debug:*
>> *  msg: "{{  item[2] ['city']}}"*
>> *   loop: "{{   world | subelements('n_america') | 
>> dict2items   }}"*
>>
>> I receive a error like  "obj must be a list of dicts or a nested 
>> dict"}
>> 
>>
>> msg: with "*world .**n_america.city" will work *
>> I want to print this through loop only , as i need to process other 
>> items  also.
>>
>> Thanks ,, 
>>   
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/7bfd7866-57f4-4067-82d9-f1fd71786950n%40googlegroups.com.


Re: [ansible-project] printing the items on dictionary format

2023-03-14 Thread Veera
Thanks .. You mean with the "loop" enabled .. It did not work in both modes.

I am looking for a way so that this particular play will process  the 
variables(items) under *n_america   in *
*vars_files : *
*- vars/myvars.yml*


On Tuesday, March 14, 2023 at 6:39:53 PM UTC+5:30 Avinash Jadhav wrote:

> Hi 
>
>   you can try this way 
>
>>  
>
>
>> - name: printing the details of montreal
>>   debug:
>>
> msg: "{{ item.value.city }}"
>
>
>>   loop: "{{ world | subelements('n_america') | dict2items }}"
>>
>

-- 
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/c20b94cc-6be1-419f-a258-a2b2474548c0n%40googlegroups.com.


[ansible-project] printing the items on dictionary format

2023-03-14 Thread Veera
I have the items defined in  the file  vars/myvars.yml as below:

*world:*
* asia:*
* country:  india*
* state: maha *
* city:mumbai*
 
* n_america:*
*   nation:  canada*
*   province : quebec*
*   city:  montreal*

When I try to  print them with a loop and subelements , i am missing 
something 
* - name:  play to print the details*
*   hosts: localhost*
*   gather_facts: no*
*   vars: *
*- vars/myvars.yml*
*   tasks:*
*   - name: printing the details of montreal*
*  debug:*
*  msg: "{{  item[2] ['city']}}"*
*   loop: "{{   world | subelements('n_america') | dict2items  
 }}"*

I receive a error like  "obj must be a list of dicts or a nested dict"}


msg: with "*world .**n_america.city" will work *
I want to print this through loop only , as i need to process other items  
also.

Thanks ,, 
  

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/efca87fe-9c3e-457d-a82a-3d7d20ca3981n%40googlegroups.com.


Re: [ansible-project] read password from a variable

2023-03-10 Thread Veera
Yes.. I uses  Ubuntu 22 . but when executed manually source exists.
Failing when called through the  playbook with the mentioned error. 

@ToddWill  it exists until the next play executes in the same playbook 
?  
 I required  the processed source variables for the next 
play(only ) . 
On Friday, March 10, 2023 at 9:27:26 PM UTC+5:30 Todd Lewis wrote:

> Even if it worked, its effects will go away as soon as the shell running 
> it closes. It won't persist to another task.
>
> On Friday, March 10, 2023 at 10:45:06 AM UTC-5 Antony Stone wrote:
>
>> On Friday 10 March 2023 at 16:39:17, Veera wrote: 
>>
>> > Its a problem with "pexpect" module requirement and it worked after 
>> "pip3 
>> > install pexpect". 
>> > However , now "source ./myenv" is not working 
>> > 
>> > msg": "The command was not found or was not executable: source" 
>> > 
>> > Since source is a shell inbuilt command . Is there a way to overcome it 
>> ? 
>> > I tried multiple options .. 
>>
>> "source" is a Bash built-in, but are you sure the remote machine is using 
>> Bash 
>> as its shell? 
>>
>> If it's a modern Debian (ore derivative) machine and it's using /bin/sh, 
>> that's Dash, not Bash, and Dash does not have the "source" command. 
>>
>>
>> Antony. 
>>
>> -- 
>> The Free Software Foundation Europe was formed on this day in 2001 
>> https://fsfe.org 
>>
>> Please reply to the list; 
>> please *don't* CC me. 
>>
>

-- 
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/970d8de7-0f4d-445b-99a0-02afce9fb66dn%40googlegroups.com.


Re: [ansible-project] read password from a variable

2023-03-10 Thread Veera
 to run the script and retrieve the password value.
>
> Each of these options has its own pros and cons, so it's important to 
> choose the one that best suits your use case and security requirements.
> [image: Avinash Jadhav]
> my_pwd: hiddenpass - name: source the environment variable file shell: " 
> source ./myenv" while executing i am prompted with a password so I am using 
> the expect module to pass the password name: Case insensitive password 
> string match ansible.builtin.expect: command: source ./myenv responses: 
> (?i)password: "{{ my_pwd }}" # you don't want to show passwords in your 
> logs no_log: true it fails with below error: fatal: [127.0.0.1]: FAILED! => 
> { "censored": "the output has been hidden due to the fact that 'no_log: 
> true' was specified for this result", "changed": false } if i set no_log: 
> false , then i receive the below error "msg": "Failed to import the 
> required Python library (pexpect) Is there any other way/module to read the 
> password from the variable ? 
>
> Yes, there are other ways to read a password from a variable in Ansible 
> without using the expect module.
>
> One way is to use the vars_prompt module to prompt the user for the 
> password at runtime. Here's an example:
>
> yamlCopy code
> - name: Prompt for password
>   vars_prompt:
> - name: my_pwd
>   prompt: "Enter your password"
>   private: true
> - name: Source the environment variable file
>   shell: "source ./myenv"
>
> When this playbook runs, the user will be prompted to enter their 
> password, and the value will be stored in the my_pwd variable. The private: 
> true option ensures that the password is not displayed on the screen as 
> it is being entered.
>
> Another option is to store the password in an encrypted file using Ansible 
> Vault and then use the ansible-vault command to retrieve the value at 
> runtime. Here's an example:
>
>
>
> On Thu, Mar 9, 2023, 11:37 PM dulhaver via Ansible Project <
> ansible...@googlegroups.com> wrote:
>
>> I am not sure, but am wondering whether maybe the remote host needs to be 
>> able t*o import the required Python library (pexpect) for this to work 
>> ... can that be it?* 
>>   
>>   
>>
>> On 03/09/2023 6:58 PM CET Veera  wrote: 
>>   
>>   
>> While sourcing a  profile file , I have to enter a password  in my play. 
>>   
>> *my_pwd: hiddenpass* 
>>   
>> *- name:  source the environment variable file * 
>> *  shell: " source ./myenv*" 
>>   
>> while executing  i am prompted with a password  
>> so I am using the expect module to pass the password 
>>
>> *name: Case insensitive password string match* 
>>
>>
>>
>>
>>
>> *  ansible.builtin.expect:command: source./myenv
>> responses:  (?i)password: "{{  my_pwd  }}"# you don't want 
>> to show passwords in your logs  no_log: true* 
>>   
>> it fails with below error: 
>>
>>
>>
>> *fatal: [127.0.0.1]: FAILED! => {"censored": "the output has been 
>> hidden due to the fact that 'no_log: true' was specified for this result",  
>>   "changed": false}* 
>>   
>> if i set no_log: false ,  then  i receive the below error 
>> *"msg": "Failed to import the required Python library (pexpect)* 
>>   
>>
>> Is there any other way/module  to read  the password from the variable ? 
>>   
>>   
>>
>>  
>> -- 
>> 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/89d10c26-89ba-4d7e-9f3e-c9c4c554a604n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/89d10c26-89ba-4d7e-9f3e-c9c4c554a604n%40googlegroups.com?utm_medium=email&utm_source=footer>.
>>  
>>
>>
>> -- 
>> 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/669854888.204262.1678385227259%40office.mailbox.org
>>  
>> <https://groups.google.com/d/msgid/ansible-project/669854888.204262.1678385227259%40office.mailbox.org?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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/080b225c-c330-4406-bb67-d4eec99c48d7n%40googlegroups.com.


[ansible-project] read password from a variable

2023-03-09 Thread Veera
While sourcing a  profile file , I have to enter a password  in my play.

*my_pwd: hiddenpass*

*- name:  source the environment variable file *
*  shell: " source ./myenv*"
 
while executing  i am prompted with a password 
so I am using the expect module to pass the password
  
*name: Case insensitive password string match*





*  ansible.builtin.expect:command: source./myenv
responses:  (?i)password: "{{  my_pwd  }}"# you don't want 
to show passwords in your logs  no_log: true*

it fails with below error:



*fatal: [127.0.0.1]: FAILED! => {"censored": "the output has been 
hidden due to the fact that 'no_log: true' was specified for this result",  
  "changed": false}*

if i set no_log: false ,  then  i receive the below error
*"msg": "Failed to import the required Python library (pexpect)*


Is there any other way/module  to read  the password from the variable ?


-- 
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/89d10c26-89ba-4d7e-9f3e-c9c4c554a604n%40googlegroups.com.


Re: [ansible-project] split with multiple columns in debug

2023-02-28 Thread Veera
Thanks Vladimir  !!!

On Tuesday, February 28, 2023 at 12:41:46 PM UTC+5:30 Vladimir Botka wrote:

> On Mon, 27 Feb 2023 21:07:45 -0800 (PST)
> Veera  wrote:
>
> > load_avg: "{{ up_out.stdout_lines[0].split()[7:] }}"
>
> Given the registered variable *up_out*
>
> - command: uptime
> register: up_out
>
> Use the filter community.general.jc to parse the stdout. The utility
> *jc* "converts the output of many commands, file-types, and strings
> to JSON or YAML". For example,
>
> uptime: "{{ up_out.stdout|community.general.jc('uptime') }}"
>
> gives
>
> uptime:
> load_15m: 1.21
> load_1m: 1.84
> load_5m: 1.41
> time: 07:57:41
> time_hour: 7
> time_minute: 57
> time_second: 41
> uptime: 11 days, 18:12
> uptime_days: 11
> uptime_hours: 18
> uptime_minutes: 12
> uptime_total_seconds: 1015920
> users: 2
>
> The first three attributes come from "load average". Quoting from man
> uptime: "The averages are taken over the three time intervals." Now,
> the usage is trivial. For example,
>
> load_average: >
> {{ uptime.load_1m }},
> {{ uptime.load_5m}},
> {{ uptime.load_15m }}
>
> gives
>
> load_average: |-
> 1.84, 1.41, 1.21
>
> -- 
> 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/5e9ee466-5e48-4e6a-87f9-0e67834443a8n%40googlegroups.com.


Re: [ansible-project] split with multiple columns in debug

2023-02-27 Thread Veera
Thanks Walter.. the options helped me a lot. 

On Monday, February 27, 2023 at 11:49:05 PM UTC+5:30 Rowe, Walter P. (Fed) 
wrote:

> If you want the commas removed you can do that too.
>
>   - "{{ text_to_split1.replace(',','').split()[-3:] }}"
>   - "{{ text_to_split2.replace(',','').split()[-3:] }}"
>
> ok: [localhost] => {
> "msg": [
> [
> "0.02",
> "0.05",
> "0.00"
> ],
> [
> "1.08",
> "0.99",
> "1.05"
> ]
> ]
> }
>
>
> Walter
> --
> Walter Rowe, Division Chief
> Infrastructure Services, OISM
>

-- 
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/42fc8d28-fbd3-44a1-8e56-54dd9e4783dan%40googlegroups.com.


Re: [ansible-project] split with multiple columns in debug

2023-02-27 Thread Veera
Thanks a lot for the valuable input..

On Monday, February 27, 2023 at 11:30:52 PM UTC+5:30 Hearn, Stan J. wrote:

> Veera,
>
>  
>
> Be careful splitting uptime on white space because when a system is up 
> less than 24 hours, it will show 
>
>  
>
> 12:58:10 up  6:51,  0 users,  load average: 1.08, 0.99, 1.05
>
>  
>
> which will have one less white space and your desired output will be 
> position 6.
>
>  
>
> I would recommend splitting the output on comma.   The fourth value will 
> always be load average.
>
>  
>
> Regards,
>
> Stan
>
>  
>
> *From:* 'Rowe, Walter P. (Fed)' via Ansible Project <
> ansible...@googlegroups.com> 
> *Sent:* Monday, February 27, 2023 12:28 PM
> *To:* ansible...@googlegroups.com
> *Subject:* [EXTERNAL] Re: [ansible-project] split with multiple columns 
> in debug
>
>  
>
> load_avg: "{{ up_out.stdout_lines[0].split()[7:] }}"
>
>  
>
> Just use [7:] to get from position 7 on in your list.
>
>  
>
>
>
> ---
>
> - name: test splitting text
>
>   hosts: localhost
>
>   become: false
>
>   gather_facts: false
>
>   vars:
>
> text_to_split: "18:37:01 up 5 days,  4:37,  2 users,  load average: 
> 0.02, 0.05, 0.00"
>
>   tasks:
>
> - name: get the load average text
>
>   debug:
>
> msg: "{{ text_to_split.split()[7:] }}"
>
>
>
>
>
>
>
>
>
>
>
>
>
> *% ansible-playbook -i localhost, split.yml*
>
>  
>
> PLAY [test splitting text] 
> *
>
>  
>
> TASK [get the load average text] 
> ***
>
> ok: [localhost] => {
>
> "msg": [
>
> "load",
>
> "average:",
>
> "0.02,",
>
> "0.05,",
>
> "0.00"
>
> ]
>
> }
>
>  
>
> PLAY RECAP 
> *
>
> localhost  : ok=1changed=0unreachable=0
> failed=0skipped=0rescued=0ignored=0   
>
>  
>
>
> Walter
> --
> Walter Rowe, Division Chief
> Infrastructure Services, OISM
> Mobile: 202.355.4123 <(202)%20355-4123>
>
>
>
> On Feb 27, 2023, at 11:46 AM, Veera  wrote:
>
>  
>
> Hi, 
>
>  
>
> When I try to split the output of uptime to capture the "load average from 
> the below line
>
>  
>
> $ uptime
>  18:37:01 up 5 days,  4:37,  2 users,  load average: 0.02, 0.05, 0.00
>
>  
>
> using the below playbook 
>
>  
>
> ---
> - name: uptime_collect22
>   hosts: localhost
>   gather_facts: no
>   tasks:
> - name:  register the uptime
>   shell: "uptime"
>   register: up_out
>
> - set_fact:
> #load_avg: "{{ up_out.stdout_lines[0].split()[[7],[8],[9],[10]] }}"
> load_avg: "{{ up_out.stdout_lines[0].split()[7] }}"
>
> - name: print the load average
>   debug:
> var: load_avg
>
>  
>
> when i execute i got the output debug as 
>
> TASK [print the   load average  ] 
> ***
> ok: [my-client-2] => {
> "load_avg": "load"
> }
>
>  
>
> I can split the stdout lines . How can I split/print with  multiple 
> columns similar to awk '{print $7,$8,$9,$10}'  .?
>
> Expected output:  "load average: 0.02, 0.05, 0.00"  
>
>  
>
> I can achieve it with shell module with uptime |awk '{print $8,$9,$10, 
> $11, $12}'
>
> However I want to check the  ansible filtering and split 
>
>  
>
>  
>
>  
>
> -- 
> 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/31258954-4fc0-4ef7-91b1-2fb7f92b5066n%40googlegroups.com
>  
> <https://urldefense.com/v3/__https:/gcc02.safelinks.protection.outlook.com/?url=https*3A*2F*2Fgroups.google.com*2Fd*2Fmsgid*2Fansible-project*2F31258954-4fc0-4ef7-91b1-2fb7f92b5066n*2540googlegroups.

[ansible-project] split with multiple columns in debug

2023-02-27 Thread Veera
Hi,

When I try to split the output of uptime to capture the "load average from 
the below line

$ uptime
 18:37:01 up 5 days,  4:37,  2 users,  load average: 0.02, 0.05, 0.00

using the below playbook 

---
- name: uptime_collect22
  hosts: localhost
  gather_facts: no
  tasks:
- name:  register the uptime
  shell: "uptime"
  register: up_out

- set_fact:
#load_avg: "{{ up_out.stdout_lines[0].split()[[7],[8],[9],[10]] }}"
load_avg: "{{ up_out.stdout_lines[0].split()[7] }}"

- name: print the load average
  debug:
var: load_avg

when i execute i got the output debug as 
TASK [print the   load average  ] 
***
ok: [my-client-2] => {
"load_avg": "load"
}

I can split the stdout lines . How can I split/print with  multiple columns 
similar to awk '{print $7,$8,$9,$10}'  .?
Expected output:  "load average: 0.02, 0.05, 0.00"  

I can achieve it with shell module with uptime |awk '{print $8,$9,$10, $11, 
$12}'
However I want to check the  ansible filtering and split 


-- 
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/31258954-4fc0-4ef7-91b1-2fb7f92b5066n%40googlegroups.com.


Re: [ansible-project] Playbook skips the debug for no reason

2022-11-16 Thread Veera
Thanks  .. I have set the indent right and it was working .
Actucally i tried various verbosity level and indent  in the debug module , 
which was not helping .

However , in future I will avoid bringing in atleast  indent releated 
issues here .. 

On Wednesday, November 16, 2022 at 2:06:20 AM UTC+5:30 Brian Coca wrote:

> @Todd Lewis why I favor gist/pastebin for showing the code, both in
> groups and/or irc/matrix
>
> A 2nd best is using 'text format' and monospaced fonts.
>
>
> --
> 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/a3be713c-cc18-4584-9339-ee0afa5d5b9dn%40googlegroups.com.


[ansible-project] Playbook skips the debug for no reason

2022-11-15 Thread Veera
Hi,

I am not sure why the playbook skips the debug to print the output.
Am i missing some thing ?

- name:  Collect the JDK  version of the updated  package
  shell:  "/apps/jdk1.8.0_351/bin/java -version"
  register: jdkstat


- debug:
var: jdkstat.stdout
verbosity: 2

However the log shows the  logs are registered under jdkstat.err  . 

changed: [server1] => {
"changed": true,
"cmd": "/apps/jdk1.8.0_351/bin/java -version",
"delta": "0:00:00.066018",
"end": "2022-11-15 12:45:45.676558",
"invocation": {
"module_args": {
"_raw_params": "/apps/jdk1.8.0_351/bin/java -version",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"stdin_add_newline": true,
"strip_empty_ends": true,
"warn": true
}
},
"rc": 0,
"start": "2022-11-15 12:45:45.610540",
"stderr": "java version \"1.8.0_351\"\nJava(TM) SE Runtime Environment 
(build 1.8.0_351-b10)\nJava HotSpot(TM) 64-Bit Server VM (build 25.351-b10, 
mixed mode)",
"stderr_lines": [
"java version \"1.8.0_351\"",
"Java(TM) SE Runtime Environment (build 1.8.0_351-b10)",
"Java HotSpot(TM) 64-Bit Server VM (build 25.351-b10, mixed mode)"
],
"stdout": "",
"stdout_lines": []
}

TASK [debug] 
*
task path: /home/veera/myplay.yml:34
skipping: [server1] => {
"skipped_reason": "Verbosity threshold not met."


Even i change the debug  module content to below:, still no output in debug

- debug:
var: jdkstat.err
verbosity: 2





-- 
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/b1aea577-3c6b-4182-9cbc-a8599511e0f2n%40googlegroups.com.


[ansible-project] Prompt option listing all the servers in inventory

2022-11-14 Thread Veera
Hi ,

I am trying to confirm the hosts which are selected for the  execution  
with the prompt option.  However I am prompted with all the servers in my 
inventory .(not sure how it pulls , may be *ansible_play_batch)*

Help me on what i am missing?

*- name: Playbook to update the package in the given list of servers*















*  hosts: server1  gather_facts: no  vars_files:- 
vars/postcheck_vars.yml  vars_prompt: - name: confirm  the below list 
of servers are part of patching for the given wave   prompt: >-
 You have selected  {{ ansible_play_batch }} . Do you want to continue? 
Press y  tasks:- name: Waiting for confirmation  fail:  when: 
confirm.lower() != 'y'*



*If i replace server1  with  group1 , all the servers in the group has to 
be listed(prompted) before the execution of the play . *

-- 
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/99403b0a-55bf-4094-bf6f-286abeca8085n%40googlegroups.com.


Re: [ansible-project] copy registered content to a file which is called from variable

2022-11-10 Thread Veera
Whatever "vars" is, it doesn't have any data with that name -  
exactly...  it will be a new file to be created by the copy's "dest ."


compare_out.stdout is having   the output of hundreds of lines to be 
printed parallely .  I have disabled the printing of its output (to reduce 
screen space) by 
register: compare_out
no_log: true 

###
Perhaps you mean this:

  dest="{{ comp_file }}"

Whatever. In any case, if I were you, I'd throw in a debug step and print 
out the values of "compare_out.stdout" and, er, whatever you think "dest" 
is supposed to be ("vars"? but I think you just mean "comp_file").
### ###
 on the above ,  I am trying to write the compare_out.stdout  which is 100+ 
lines  to a file which  have to created by  calling the variable "{{ 
comp_file }}"  as dest using copy .


may be we need template? Jinja ?  
Learn to study more ..  :-)



On Friday, November 11, 2022 at 1:34:15 AM UTC+5:30 uto...@gmail.com wrote:

> Wait a second. You're saying "{{ vars[ comp_file ] }}", but
>
>   
> comp_file="/home/user1/ansible/patching/logs/2022-11-10/server1-compare-2022-11-10.txt"
>
> So you're trying to pull a value from the "vars" dict with the key of
>   "
> /home/user1/ansible/patching/logs/2022-11-10/server1-compare-2022-11-10.txt
> ".
>
> Whatever "vars" is, it doesn't have any data with that name.
>
> Perhaps you mean this:
>
>   dest="{{ comp_file }}"
>
> Whatever. In any case, if I were you, I'd throw in a debug step and print 
> out the values of "compare_out.stdout" and, er, whatever you think "dest" 
> is supposed to be ("vars"? but I think you just mean "comp_file").
>
>
> On 11/10/22 1:26 PM, Veera wrote:
>
>
> Thanks for pointing  as i did notice that , and I have corrected the  
> three left braces on "exec_date". 
>
> Second, mustaches (i.e. "{{" … "}}") never nest  <<  Yes , I tried earlier 
> that and even now after reverting back , still the same issue .. 
> Execution error for the play below.
>
> fatal: [server1 -> localhost]: FAILED! => {"msg": "The task includes an 
> option with an undefined variable. The error was: 'dict object' has no 
> attribute 
> u'/home/user1/ansible/patching/logs/2022-11-10/server1-compare-2022-11-10.txt'\n\nThe
>  
> error appears to be in 
> '/home/unixops/ansible/linux_patching/compare_sanity.yml': line 7, column 
> 3, but may\nbe elsewhere in the file depending on the exact syntax 
> problem.\n\nThe offending line appears to be:\n\n\n- name: create compare 
> file using precheck and postcheck sanity checks\n  ^ here\n"}
>
>
> On Thursday, November 10, 2022 at 10:24:51 PM UTC+5:30 uto...@gmail.com 
> wrote:
>
>> A couple of things. First,
>>
>> comp_file: /logs/{{ exec_date }}/{{ inventory_hostname }}-compare-{{{ 
>> exec_date }}.txt
>>
>> has three left braces on "exec_date".
>>
>> Second, mustaches (i.e. "{{" … "}}") never nest. So
>>
>> copy   content="{{ compare_out.stdout }}" dest="{{ vars[ {{ comp_file 
>> }} ] }}"
>>
>> should be
>>
>> copy   content="{{ compare_out.stdout }}" dest="{{ vars[ comp_file ] 
>> }}"
>>
>> Well, at least that's "dest=" without nested mustaches. Whether it's 
>> right or not I don't know, but it's less wrong this way.
>>
>>
>> On 11/10/22 9:16 AM, Veera wrote:
>>
>> Hi, 
>>
>> I am trying to copy the  contents from a register output  to a file  in 
>> the local server.
>> However , I have challenges in re-calling the variable filename in the 
>> copy command.
>>
>> Correct me what I am missing. in dest="{{ vars[ {{ comp_file }} ] }}"  or 
>> "{{ compare_out.stdout }}"  in the last lines ..
>>
>>
>> [vee@server]$ grep comp_file  vars/postcheck_vars.yml
>> comp_file: /logs/{{ exec_date }}/{{ inventory_hostname }}-compare-{{{ 
>> exec_date }}.txt
>>
>> [vee@server]$ cat  compare_sanity.yml
>> - name: comparing file1 and file2 
>>   local_action: command /usr/bin/sdiff "{{ logs_dir }}"{{ 
>> inventory_hostname }}-Pre-{{ exec_date }}.txt   "{{ logs_dir }}"{{ 
>> inventory_hostname }}-Post-{{ exec_date }}.txt
>>   register: compare_out
>>   ignore_errors: yes
>>   no_log: True
>>
>> - name: create output  file
>>   local_action:
>> copy   content="{{ compare_out.stdout }}" dest="{{ vars[ {{ comp_file 
>> }} ] }}"
>>   [vee@server]$
>>
>>
>

-- 
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/ce5a217b-b8b5-456a-9a86-f27bcac9ba2en%40googlegroups.com.


Re: [ansible-project] copy registered content to a file which is called from variable

2022-11-10 Thread Veera
Attaching a screenshot to show the format still miss something [image: 
IMG-2022-WA.jpg]

On Thursday, November 10, 2022 at 11:56:40 PM UTC+5:30 Veera wrote:

>
> Thanks for pointing  as i did notice that , and I have corrected the  
> three left braces on "exec_date".
>
> Second, mustaches (i.e. "{{" … "}}") never nest  <<  Yes , I tried earlier 
> that and even now after reverting back , still the same issue .. 
> Execution error for the play below.
>
> fatal: [server1 -> localhost]: FAILED! => {"msg": "The task includes an 
> option with an undefined variable. The error was: 'dict object' has no 
> attribute 
> u'/home/user1/ansible/patching/logs/2022-11-10/server1-compare-2022-11-10.txt'\n\nThe
>  
> error appears to be in 
> '/home/unixops/ansible/linux_patching/compare_sanity.yml': line 7, column 
> 3, but may\nbe elsewhere in the file depending on the exact syntax 
> problem.\n\nThe offending line appears to be:\n\n\n- name: create compare 
> file using precheck and postcheck sanity checks\n  ^ here\n"}
>
>
> On Thursday, November 10, 2022 at 10:24:51 PM UTC+5:30 uto...@gmail.com 
> wrote:
>
>> A couple of things. First,
>>
>> comp_file: /logs/{{ exec_date }}/{{ inventory_hostname }}-compare-{{{ 
>> exec_date }}.txt
>>
>> has three left braces on "exec_date".
>>
>> Second, mustaches (i.e. "{{" … "}}") never nest. So
>>
>> copy   content="{{ compare_out.stdout }}" dest="{{ vars[ {{ comp_file 
>> }} ] }}"
>>
>> should be
>>
>> copy   content="{{ compare_out.stdout }}" dest="{{ vars[ comp_file ] 
>> }}"
>>
>> Well, at least that's "dest=" without nested mustaches. Whether it's 
>> right or not I don't know, but it's less wrong this way.
>>
>>
>> On 11/10/22 9:16 AM, Veera wrote:
>>
>> Hi, 
>>
>> I am trying to copy the  contents from a register output  to a file  in 
>> the local server.
>> However , I have challenges in re-calling the variable filename in the 
>> copy command.
>>
>> Correct me what I am missing. in dest="{{ vars[ {{ comp_file }} ] }}"  or 
>> "{{ compare_out.stdout }}"  in the last lines ..
>>
>>
>> [vee@server]$ grep comp_file  vars/postcheck_vars.yml
>> comp_file: /logs/{{ exec_date }}/{{ inventory_hostname }}-compare-{{{ 
>> exec_date }}.txt
>>
>> [vee@server]$ cat  compare_sanity.yml
>> - name: comparing file1 and file2 
>>   local_action: command /usr/bin/sdiff "{{ logs_dir }}"{{ 
>> inventory_hostname }}-Pre-{{ exec_date }}.txt   "{{ logs_dir }}"{{ 
>> inventory_hostname }}-Post-{{ exec_date }}.txt
>>   register: compare_out
>>   ignore_errors: yes
>>   no_log: True
>>
>> - name: create output  file
>>   local_action:
>> copy   content="{{ compare_out.stdout }}" dest="{{ vars[ {{ comp_file 
>> }} ] }}"
>>   [vee@server]$
>>
>>
>>

-- 
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/002d3ea7-5689-4af0-b4d7-2435794f858cn%40googlegroups.com.


Re: [ansible-project] copy registered content to a file which is called from variable

2022-11-10 Thread Veera

Thanks for pointing  as i did notice that , and I have corrected the  three 
left braces on "exec_date".

Second, mustaches (i.e. "{{" … "}}") never nest  <<  Yes , I tried earlier 
that and even now after reverting back , still the same issue .. 
Execution error for the play below.

fatal: [server1 -> localhost]: FAILED! => {"msg": "The task includes an 
option with an undefined variable. The error was: 'dict object' has no 
attribute 
u'/home/user1/ansible/patching/logs/2022-11-10/server1-compare-2022-11-10.txt'\n\nThe
 
error appears to be in 
'/home/unixops/ansible/linux_patching/compare_sanity.yml': line 7, column 
3, but may\nbe elsewhere in the file depending on the exact syntax 
problem.\n\nThe offending line appears to be:\n\n\n- name: create compare 
file using precheck and postcheck sanity checks\n  ^ here\n"}


On Thursday, November 10, 2022 at 10:24:51 PM UTC+5:30 uto...@gmail.com 
wrote:

> A couple of things. First,
>
> comp_file: /logs/{{ exec_date }}/{{ inventory_hostname }}-compare-{{{ 
> exec_date }}.txt
>
> has three left braces on "exec_date".
>
> Second, mustaches (i.e. "{{" … "}}") never nest. So
>
> copy   content="{{ compare_out.stdout }}" dest="{{ vars[ {{ comp_file 
> }} ] }}"
>
> should be
>
> copy   content="{{ compare_out.stdout }}" dest="{{ vars[ comp_file ] 
> }}"
>
> Well, at least that's "dest=" without nested mustaches. Whether it's right 
> or not I don't know, but it's less wrong this way.
>
>
> On 11/10/22 9:16 AM, Veera wrote:
>
> Hi, 
>
> I am trying to copy the  contents from a register output  to a file  in 
> the local server.
> However , I have challenges in re-calling the variable filename in the 
> copy command.
>
> Correct me what I am missing. in dest="{{ vars[ {{ comp_file }} ] }}"  or 
> "{{ compare_out.stdout }}"  in the last lines ..
>
>
> [vee@server]$ grep comp_file  vars/postcheck_vars.yml
> comp_file: /logs/{{ exec_date }}/{{ inventory_hostname }}-compare-{{{ 
> exec_date }}.txt
>
> [vee@server]$ cat  compare_sanity.yml
> - name: comparing file1 and file2 
>   local_action: command /usr/bin/sdiff "{{ logs_dir }}"{{ 
> inventory_hostname }}-Pre-{{ exec_date }}.txt   "{{ logs_dir }}"{{ 
> inventory_hostname }}-Post-{{ exec_date }}.txt
>   register: compare_out
>   ignore_errors: yes
>   no_log: True
>
> - name: create output  file
>   local_action:
> copy   content="{{ compare_out.stdout }}" dest="{{ vars[ {{ comp_file 
> }} ] }}"
>   [vee@server]$
>
>
>

-- 
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/0a534562-0f6a-42a6-80c7-8fc4f9a8ecc6n%40googlegroups.com.


[ansible-project] copy registered content to a file which is called from variable

2022-11-10 Thread Veera
Hi,

I am trying to copy the  contents from a register output  to a file  in the 
local server.
However , I have challenges in re-calling the variable filename in the copy 
command.

Correct me what I am missing. in dest="{{ vars[ {{ comp_file }} ] }}"  or 
"{{ compare_out.stdout }}"  in the last lines ..


[vee@server]$ grep comp_file  vars/postcheck_vars.yml
comp_file: /logs/{{ exec_date }}/{{ inventory_hostname }}-compare-{{{ 
exec_date }}.txt

[vee@server]$ cat  compare_sanity.yml
- name: comparing file1 and file2 
  local_action: command /usr/bin/sdiff "{{ logs_dir }}"{{ 
inventory_hostname }}-Pre-{{ exec_date }}.txt   "{{ logs_dir }}"{{ 
inventory_hostname }}-Post-{{ exec_date }}.txt
  register: compare_out
  ignore_errors: yes
  no_log: True

- name: create output  file
  local_action:
copy   content="{{ compare_out.stdout }}" dest="{{ vars[ {{ comp_file 
}} ] }}"
  [vee@server]$


-- 
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/a1e96432-f332-4bb4-974a-4c556efd447fn%40googlegroups.com.


Re: [ansible-project] yum module to skip checking the yum repositories

2022-11-09 Thread Veera
Thanks ,, I already checked the link anddisable_plugin . Both are not 
helpful .
I will have to use  command/shell -  module to call rpm  to install the  
local package 




On Wednesday, November 9, 2022 at 10:29:30 PM UTC+5:30 lat...@gmail.com 
wrote:

> Attempting to grok this, so you want to install an RPM on a system that 
> has no repos configured.
>
> Maybe try cacheonly as mentioned on 
> https://docs.ansible.com/ansible/latest/collections/ansible/builtin/yum_module.html
>
> I do not have an RPM based system here to test on. You could use the RPM 
> command line or use the disable_plugin as I suspect fastestmirrors is 
> getting called. I would maybe also try 
> disabling install_repoquery. Yellowdog is designed to check repos, that is 
> the main goal of it.
>
> On Wed, Nov 9, 2022 at 9:15 AM Veera  wrote:
>
>> Hi,
>>
>> I have the below snippet , which installs the local package . However in 
>> servers which have not subscribed to  satellite/Redhat , the  playbook 
>> hungs as it continue to search for the  repositories in the backgroud.
>>
>> - name: Installing the  local rpm rpm packages in the server 
>> yum:
>>   name: /tmp/-2.3.2.2105-1.x86_64.rpm
>>   state: present
>>   disable_gpg_check: yes
>> ignore_errors: true
>> register: result_t1
>> tags: install_localpackage
>>
>> In yum module , there is no exact option to skip looking  into  the yum  
>> repositories or cache , to override this step.  
>> Is there any  option available in yum to skip looking into yum or have to 
>> write a bash script with "rpm -i " to replace it ?
>>
>>
>> -- 
>> 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/f6f03839-8c77-4777-9d69-600d230ad078n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/f6f03839-8c77-4777-9d69-600d230ad078n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> -- 
> - Andrew "lathama" Latham -
>

-- 
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/ed07bca0-edfd-4cda-8665-99baed016e33n%40googlegroups.com.


[ansible-project] yum module to skip checking the yum repositories

2022-11-09 Thread Veera
Hi,

I have the below snippet , which installs the local package . However in 
servers which have not subscribed to  satellite/Redhat , the  playbook 
hungs as it continue to search for the  repositories in the backgroud.

- name: Installing the  local rpm rpm packages in the server 
yum:
  name: /tmp/-2.3.2.2105-1.x86_64.rpm
  state: present
  disable_gpg_check: yes
ignore_errors: true
register: result_t1
tags: install_localpackage

In yum module , there is no exact option to skip looking  into  the yum  
repositories or cache , to override this step.  
Is there any  option available in yum to skip looking into yum or have to 
write a bash script with "rpm -i " to replace it ?


-- 
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/f6f03839-8c77-4777-9d69-600d230ad078n%40googlegroups.com.


[ansible-project] print the register output with proper format on the screen

2022-11-08 Thread Veera
Hi everyone ,

I am trying to   print 2  files in my ansible server itself, which are 
already copied from other servers ,  which means the filenames have 
hostnames and date within it.

- name: compare the output files 
 local_action:  command  /usr/bin/sdiff   "{{ logs_dir }}"/{{ 
inventory_hostname }}-Precheck-{{ ansible_date_time.date }}.txt "{{ 
logs_dir }}"/{{ inventory_hostname }}-Postcheck-{{ansible_date_time.date 
}}.txt
register: result

- debug:
  var:  result.output

I am able to print the output I expected ..but it collapses   than expected.
Is there a way to Print them as like as in a linux bash"  # diff file1 
file2 "

redirecting the output to a file and printing is also  helping






-- 
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/1d41c3c5-05e7-432c-aa45-fea87746bf8en%40googlegroups.com.


[ansible-project] Unable to connect to a single ansible client for unknown reasons

2022-04-29 Thread Veera
Hi,

I am able to connect to all the clients in my new Linux environment,  and 
however one of the client is failng . 

All the servers are running RHEL7 and one server is  failing. zlib also 
installed in the server as like in other servers.
The ssh keys are pushed to all servers and password less authentication is 
working fine .

However when a playbook or an adhoc command is executed ,it fails with the 
below error.

[user1@ansiblenode1 ansible]$ ssh controlnode11
Last login: Fri Apr 29 07:52:26 2022 from ansiblenode1
[user1@controlnode11 ~]$ exit
logout
Connection to controlnode11 closed.
[user1@ansiblenode1 ansible]$ ansible controlnode11 -m command -a "uptime"
An exception occurred during task execution. To see the full traceback, use 
-vvv. The error was: zipimport.ZipImportError: can't decompress data; zlib 
not available
controlnode11 | FAILED! => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"module_stderr": "Shared connection to controlnode11 closed.\r\n",
"module_stdout": "Traceback (most recent call last):\r\n File 
\"/home/user1/.ansible/tmp/ansible-tmp-1651233186.52-29701-82175276342050/AnsiballZ_command.py\",
 
line 102, in \r\n _ansiballz_main()\r\n File 
\"/home/user1/.ansible/tmp/ansible-tmp-1651233186.52-29701-82175276342050/AnsiballZ_command.py\",
 
line 94, in _ansiballz_main\r\n invoke_module(zipped_mod, temp_path, 
ANSIBALLZ_PARAMS)\r\n File 
\"/home/user1/.ansible/tmp/ansible-tmp-1651233186.52-29701-82175276342050/AnsiballZ_command.py\",
 
line 37, in invoke_module\r\n from ansible.module_utils import 
basic\r\nzipimport.ZipImportError: can't decompress data; zlib not 
available\r\n",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
}
[user1@ansiblenode1 ansible]$

-- 
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/3101a80c-54a0-490e-a48d-68ed106d41can%40googlegroups.com.


[ansible-project] reading a log file with hostname in the playbook processed

2019-08-08 Thread Veera

I am trying to   create a log  file   with hostname with  it by using the 
shell  variable and not from {{  ansible_hostname }} , as I have my 
playbooks have gather_facts  disabled.

Unable to fetch the source file as ansible is  unable to get the exact file 
in src.?

what need to be changed for the line  "src: /var/tmp/patchreport_$(hostname 
-s)_$(date +%F) "


- name: myplay
  hosts: myhost5
  remote_user: root
  gather_facts: no
  tasks:
- name: Collecting  the patch result
  ignore_errors: yes
  shell: grep "`date '+%b.%d'`" /var/log/yum.log > /var/tmp/
patchreport_$(hostname -s)_$(date +%F)
  register: patchlog


- name: Fetch  the  Patch  result for the server
  fetch:
src: /var/tmp/patchreport_$(hostname -s)_$(date +%F)
dest: /home/devops/patch_reports
  when:  patchlog.changed

-- 
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/ed35f884-b9b4-4ab9-bef1-8c14591fa940%40googlegroups.com.


Re: [ansible-project] playbook without hosts desribed

2019-08-07 Thread Veera
Hi kai,

Thanks for the  inputs.

"for security reasons".   - I mean that we have disabled gather_facts for 
better  performance.  And we want other users to play the playbook with  
access to the same inventory .
I am looking for a way to avoid them  running "ansible-playbook pb.yml -e 
myvar=all"and to always  use "myvar=hostname."

is there a way to stop  a particular user to stop using " myvar=all" based 
on inventory  or other modes?

 


On Wednesday, August 7, 2019 at 11:07:16 PM UTC+5:30, Kai Stian Olstad 
wrote:
>
> On 07.08.2019 18:55, Veera wrote: 
> > Hi, 
> > 
> > Is there a way that  we can use a playbook with no "hosts: XXX" 
>  defined. 
>
> No, hosts is a required attribute for a play. 
>
>
> > All the servers are available in the inventory file defined in the 
> > ansible.cfg , but  the playbooks have  to be run  based on a single or 
> > multiple client on the ad-hoc request based. 
>
> You can always set hosts: all and use the --limit to only run on some 
> hosts. 
>
>
> > Is there a way to remove 
> > 
> > 
> >   hosts: all 
> > 
> > 
> >   and  have the same playbook working for security reasons ? 
>
> I don't understand what you mean by "for security reasons". 
>
>
> >   In the meantime when a play is to be executed in all the clients they 
> have 
> > to be mentioned from the  command line(or jenkins) 
>
> You can use a variable for hosts an set it with extra vars on the command 
> line 
>
> - hosts: '{{ myvar }}' 
>
> ansible-playbook pb.yml -e myvar=all 
>
>
> -- 
> Kai Stian Olstad 
>

-- 
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/30444812-fe0f-4a1a-8fba-b7a79bf15be6%40googlegroups.com.


[ansible-project] playbooks with no gatherfacts and using fqdn

2019-08-07 Thread Veera
Hi ,

I  am trying to create a logfile with the hostname and date . 
 But due to  some Infra limitations I have to disable the gather facts.


- name: collect report 
  ignore_errors: yes
  shell: grep "`date '+%b.%d'`" /var/log/yum.log > /home/devops/
patchreport_$(date +%F)
  register: updated

 

Is there a way I can use the hostname or the IP which the  ansible play 
uses  for execution . I  am looking for a file name to be created with /home
/devops/severname_$(date +%F).
As gather_facts are disabled , {{ andible_fqdn }} will not work . any 
substitute method to achieve it ?


-- 
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/135339c5-ded3-45f0-a8ef-c59bd14397e7%40googlegroups.com.


[ansible-project] playbook without hosts desribed

2019-08-07 Thread Veera
Hi,

Is there a way that  we can use a playbook with no "hosts: XXX"  defined.
All the servers are available in the inventory file defined in the  
ansible.cfg , but  the playbooks have  to be run  based on a single or 
multiple client on the ad-hoc request based.

Is there a way to remove


 hosts: all


 and  have the same playbook working for security reasons ?
 In the meantime when a play is to be executed in all the clients they have 
to be mentioned from the  command line(or jenkins)


-- 
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/d73c3466-800a-4b27-8416-178474e2906f%40googlegroups.com.


Re: [ansible-project] shell module with multiple arguments using variables

2019-08-03 Thread Veera
Finally ,,, I got the right combination .. Thaks for all .. 


 name: List the   status of the puppet services
  ignore_errors: yes
  shell: "{{ item }}"
  with_items:
 -  pp_stat
 - pr_date
  register: pupstat
- debug:
msg: "{{ pupstat.results|map(attribute='stdout_lines')|list }}"






On Friday, August 2, 2019 at 8:41:31 PM UTC+5:30, Veera wrote:
>
>
> Now .. I am able to print the output of items using  debug module with 
> items.. 
>  .. but  "stdout_lines"  is  not working ...  
>
> -
>  name: List the   status of the puppet services
>   ignore_errors: yes
>   shell: "{{ item }}"
>   with_items:
> - "{{ pp_stat }}"
> - "{{ pr_date }}"
>   register: pupstat
> - debug:
> var: "{{ item.stdout_lines}}"
>   with_items:
> - "{{ pupstat.results }}"
>
>
>
>
>
> the output is as below:
>
> TASK [debug] 
> *
> ok: [myhost] => (item={'_ansible_parsed': True, 'stderr_lines': [], u
> 'changed': True, u'stdout': u'puppetd (pid  5881) is running...', 
> '_ansible_item_result': True, u'delta': u'0:00:00.027518', 'stdout_lines': 
> [u'puppetd (pid  5881) is running...'], '_ansible_item_label': 
> u'/etc/init.d/puppet 
> status', u'end': u'2019-08-02 19:05:43.608320', '_ansible_no_log': False, 
> 'failed': False, u'cmd': u'/etc/init.d/puppet status', 'item': 
> u'/etc/init.d/puppet 
> status', u'stderr': u'', u'rc': 0, u'invocation': {u'module_args': {u
> 'warn': True, u'executable': None, u'_uses_shell': True, u'_raw_params': 
> u'/etc/init.d/puppet 
> status', u'removes': None, u'argv': None, u'creates': None, u'chdir': None
> , u'stdin': None}}, u'start': u'2019-08-02 19:05:43.580802', 
> '_ansible_ignore_errors': True}) => {
> "": "VARIABLE IS NOT DEFINED!",
> "item": {
> "changed": true,
> "cmd": "/etc/init.d/puppet status",
> "delta": "0:00:00.027518",
> "end": "2019-08-02 19:05:43.608320",
> "failed": false,
> "invocation": {
> "module_args": {
> "_raw_params": "/etc/init.d/puppet status",
> "_uses_shell": true,
> "argv": null,
> "chdir": null,
> "creates": null,
> "executable": null,
> "removes": null,
> "stdin": null,
> "warn": true
> }
> },
> "item": "/etc/init.d/puppet status",
> "rc": 0,
> "start": "2019-08-02 19:05:43.580802",
> "stderr": "",
> "stderr_lines": [],
> "stdout": "puppetd (pid  5881) is running...",
> "stdout_lines": [
> "puppetd (pid  5881) is running..."
> ]
> }
> }
> ok: [myhost] => (item={'_ansible_parsed': True, 'stderr_lines': [], u
> 'changed': True, u'stdout': u'= as on  date of ===\nFri 
> Aug  2 19:05:48 +04 2019', '_ansible_item_result': True, u'delta': u
> '0:00:00.005896', 'stdout_lines': [u'= as on  date of ==='
> , u'Fri Aug  2 19:05:48 +04 2019'], '_ansible_item_label': u"echo 
> '= as on  date of ==='; date", u'end': u'2019-08-02 
> 19:05:48.695987', '_ansible_no_log': False, 'failed': False, u'cmd': u"echo 
> '= as on  date of ==='; date", 'item': u"echo '= 
> as on  date of ==='; date", u'stderr': u'', u'rc': 0, u
> 'invocation': {u'module_args': {u'warn': True, u'executable': None, u
> 

Re: [ansible-project] shell module with multiple arguments using variables

2019-08-02 Thread Veera

Now .. I am able to print the output of items using  debug module with 
items.. 
 .. but  "stdout_lines"  is  not working ...  

-
 name: List the   status of the puppet services
  ignore_errors: yes
  shell: "{{ item }}"
  with_items:
- "{{ pp_stat }}"
- "{{ pr_date }}"
  register: pupstat
- debug:
var: "{{ item.stdout_lines}}"
  with_items:
- "{{ pupstat.results }}"





the output is as below:

TASK [debug] 
*
ok: [myhost] => (item={'_ansible_parsed': True, 'stderr_lines': [], u
'changed': True, u'stdout': u'puppetd (pid  5881) is running...', 
'_ansible_item_result': True, u'delta': u'0:00:00.027518', 'stdout_lines': [
u'puppetd (pid  5881) is running...'], '_ansible_item_label': 
u'/etc/init.d/puppet 
status', u'end': u'2019-08-02 19:05:43.608320', '_ansible_no_log': False, 
'failed': False, u'cmd': u'/etc/init.d/puppet status', 'item': 
u'/etc/init.d/puppet 
status', u'stderr': u'', u'rc': 0, u'invocation': {u'module_args': {u'warn': 
True, u'executable': None, u'_uses_shell': True, u'_raw_params': 
u'/etc/init.d/puppet 
status', u'removes': None, u'argv': None, u'creates': None, u'chdir': None, 
u'stdin': None}}, u'start': u'2019-08-02 19:05:43.580802', 
'_ansible_ignore_errors': True}) => {
"": "VARIABLE IS NOT DEFINED!",
"item": {
"changed": true,
"cmd": "/etc/init.d/puppet status",
"delta": "0:00:00.027518",
"end": "2019-08-02 19:05:43.608320",
"failed": false,
"invocation": {
"module_args": {
"_raw_params": "/etc/init.d/puppet status",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"warn": true
}
},
"item": "/etc/init.d/puppet status",
"rc": 0,
"start": "2019-08-02 19:05:43.580802",
"stderr": "",
"stderr_lines": [],
"stdout": "puppetd (pid  5881) is running...",
"stdout_lines": [
"puppetd (pid  5881) is running..."
]
}
}
ok: [myhost] => (item={'_ansible_parsed': True, 'stderr_lines': [], u
'changed': True, u'stdout': u'= as on  date of ===\nFri Aug 
 2 19:05:48 +04 2019', '_ansible_item_result': True, u'delta': u
'0:00:00.005896', 'stdout_lines': [u'= as on  date of ===', 
u'Fri Aug  2 19:05:48 +04 2019'], '_ansible_item_label': u"echo '= 
as on  date of ==='; date", u'end': u'2019-08-02 19:05:48.695987', 
'_ansible_no_log': False, 'failed': False, u'cmd': u"echo '= as on 
 date of ==='; date", 'item': u"echo '= as on  date of 
==='; date", u'stderr': u'', u'rc': 0, u'invocation': {u
'module_args': {u'warn': True, u'executable': None, u'_uses_shell': True, u
'_raw_params': u"echo '= as on  date of ==='; date", u
'removes': None, u'argv': None, u'creates': None, u'chdir': None, u'stdin': 
None}}, u'start': u'2019-08-02 19:05:48.690091', '_ansible_ignore_errors': 
True}) => {
"": "VARIABLE IS NOT DEFINED!",
"item": {
"changed": true,
"cmd": "echo '= as on  date of ==='; date",
"delta": "0:00:00.005896",
"end": "2019-08-02 19:05:48.695987",
"failed": false,
"invocation": {
"module_args": {
"_raw_pa

Re: [ansible-project] shell module with multiple arguments using variables

2019-08-02 Thread Veera

Now .. I am able to print the output of items using  debug module with 
items.. 
 .. but  "stdout_lines"  is  not working ...  

-
 name: List the   status of the puppet services
  ignore_errors: yes
  shell: "{{ item }}"
  with_items:
- "{{ pp_stat }}"
- "{{ pr_date }}"
  register: pupstat
- debug:
var: "{{ item.stdout_lines}}"
  with_items:
- "{{ pupstat.results }}"





the output is as below:

TASK [debug] 
*
ok: [myhost] => (item={'_ansible_parsed': True, 'stderr_lines': [], u
'changed': True, u'stdout': u'puppetd (pid  5881) is running...', 
'_ansible_item_result': True, u'delta': u'0:00:00.027518', 'stdout_lines': [
u'puppetd (pid  5881) is running...'], '_ansible_item_label': 
u'/etc/init.d/puppet 
status', u'end': u'2019-08-02 19:05:43.608320', '_ansible_no_log': False, 
'failed': False, u'cmd': u'/etc/init.d/puppet status', 'item': 
u'/etc/init.d/puppet 
status', u'stderr': u'', u'rc': 0, u'invocation': {u'module_args': {u'warn': 
True, u'executable': None, u'_uses_shell': True, u'_raw_params': 
u'/etc/init.d/puppet 
status', u'removes': None, u'argv': None, u'creates': None, u'chdir': None, 
u'stdin': None}}, u'start': u'2019-08-02 19:05:43.580802', 
'_ansible_ignore_errors': True}) => {
"": "VARIABLE IS NOT DEFINED!",
"item": {
"changed": true,
"cmd": "/etc/init.d/puppet status",
"delta": "0:00:00.027518",
"end": "2019-08-02 19:05:43.608320",
"failed": false,
"invocation": {
"module_args": {
"_raw_params": "/etc/init.d/puppet status",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"warn": true
}
},
"item": "/etc/init.d/puppet status",
"rc": 0,
"start": "2019-08-02 19:05:43.580802",
"stderr": "",
"stderr_lines": [],
"stdout": "puppetd (pid  5881) is running...",
"stdout_lines": [
"puppetd (pid  5881) is running..."
]
}
}
ok: [myhost] => (item={'_ansible_parsed': True, 'stderr_lines': [], u
'changed': True, u'stdout': u'= as on  date of ===\nFri Aug 
 2 19:05:48 +04 2019', '_ansible_item_result': True, u'delta': u
'0:00:00.005896', 'stdout_lines': [u'= as on  date of ===', 
u'Fri Aug  2 19:05:48 +04 2019'], '_ansible_item_label': u"echo '= 
as on  date of ==='; date", u'end': u'2019-08-02 19:05:48.695987', 
'_ansible_no_log': False, 'failed': False, u'cmd': u"echo '= as on 
 date of ==='; date", 'item': u"echo '= as on  date of 
==='; date", u'stderr': u'', u'rc': 0, u'invocation': {u
'module_args': {u'warn': True, u'executable': None, u'_uses_shell': True, u
'_raw_params': u"echo '= as on  date of ==='; date", u
'removes': None, u'argv': None, u'creates': None, u'chdir': None, u'stdin': 
None}}, u'start': u'2019-08-02 19:05:48.690091', '_ansible_ignore_errors': 
True}) => {
"": "VARIABLE IS NOT DEFINED!",
"item": {
"changed": true,
"cmd": "echo '= as on  date of ==='; date",
"delta": "0:00:00.005896",
"end": "2019-08-02 19:05:48.695987",
"failed": false,
"invocation": {
"module_args": {
"_raw_pa

Re: [ansible-project] shell module with multiple arguments using variables

2019-08-02 Thread Veera
Hi Martz,


I tried with a couple of options  as per the link you have shared including 
the  "shell:  echo "{{ item }}" .  but still I am unable to combine the 
right combination.

my current snippet:

tasks:
- name: List the   status of the puppet services
  ignore_errors: yes
  shell:  "{{ item }}"
  register: pupstat
  with_items:
- "{{ pp_stat }}"
- "{{ pr_date }}"
- debug:
var:  pupstat

and the output of  debug is  fine.  



TASK [debug] 
*
ok: [myhost] => {
"pupstat": {
"changed": true,
"msg": "All items completed",
"results": [
{
"_ansible_ignore_errors": true,
"_ansible_item_label": "/etc/init.d/puppet status",
"_ansible_item_result": true,
"_ansible_no_log": false,
"_ansible_parsed": true,
"changed": true,
"cmd": "/etc/init.d/puppet status",
"delta": "0:00:00.030987",
"end": "2019-08-02 14:35:42.933291",
"failed": false,
"invocation": {
"module_args": {
"_raw_params": "/etc/init.d/puppet status",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"warn": true
}
},
"item": "/etc/init.d/puppet status",
"rc": 0,
"start": "2019-08-02 14:35:42.902304",
"stderr": "",
"stderr_lines": [],
"stdout": "puppetd (pid  5881) is running...",
"stdout_lines": [
"puppetd (pid  5881) is running..."
]
},
{
"_ansible_ignore_errors": true,
"_ansible_item_label": "echo '= as on  date of 
==='; date",
"_ansible_item_result": true,
"_ansible_no_log": false,
"_ansible_parsed": true,
"changed": true,
"cmd": "echo '= as on  date of ==='; date",
"delta": "0:00:00.006032",
"end": "2019-08-02 14:35:47.994833",
"failed": false,
"invocation": {
"module_args": {
"_raw_params": "echo '= as on  date of 
==='; date",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"warn": true
}
},
"item": "echo '= as on  date of ==='; date",
"rc": 0,
"start": "2019-08-02 14:35:47.988801",
"stderr": "",
"stderr_lines": [],
"stdout": "= as on  date of ===\nFri Aug  2 
14:35:47 +04 2019",
"stdout_lines": [
    "= as on  date of ===",
"Fri Aug  2 14:35:47 +04 2019"
]
}
]
}
}



 But  debug with  "stdout.lines"  is  giving an error

TASK [debug] 
*
ok: [myhost] => {
"pupstat.stdout_lines": "VARIABLE IS NOT DEFINED!: 'dict object' has no 
attribute 'stdout_lines'"
}









On Friday, August 2, 2019 at 2:39:01 AM UTC+5:30, 

Re: [ansible-project] shell module with multiple arguments using variables

2019-08-01 Thread Veera Mani
When running pup_stat alone, it works.

Adding {{ }} around items did not help



On Fri, Aug 2, 2019, 2:40 AM Kai Stian Olstad <
ansible-project+l...@olstad.com> wrote:

> On 01.08.2019 23:05, Veera wrote:
> > Hi,
> >
> > I am trying to  call variables to the shell module  but failing ..
> >
> > - name: status of  services
> >hosts: myhost
> >remote_user: root
> >gather_facts: no
> >vars:
> >  - pp_stat: "/etc/init.d/puppet status"
> >  - pr_date: "echo '= as on  date of ==='; date"
> >
> >strategy: free
> >tasks:
> >  - name: List the   status of the puppet services
> >ignore_errors: yes
> >shell: "{{ item }}"
> >with_items:
> >   -  pp_stat
> >   - pr_date
> >register: pupstat
> >  - debug:
> >  var: pupstat.stdout_lines
> >
> >
> > error reads:
> >
> > TASK [List the   status of the puppet services]
> >
> **
> > failed: [wf-omsal1-01-01] (item=pp_stat) => {"changed": true, "cmd":
> > "pp_stat", "delta": "0:00:00.004792", "end": "2019-08-02
> 01:02:19.344642",
> > "item": "pp_stat", "msg": "non-zero return code", "rc": 127, "start":
> "2019-08-02
> > 01:02:19.339850", "stderr": "/bin/sh: pp_stat: command not found",
> > "stderr_lines": ["/bin/sh: pp_stat: command not found"], "stdout": "",
> > "stdout_lines": []}
> > failed: [wf-omsal1-01-01] (item=pr_date) => {"changed": true, "cmd":
> > "pr_date", "delta": "0:00:00.004765", "end": "2019-08-02
> 01:02:24.356002",
> > "item": "pr_date", "msg": "non-zero return code", "rc": 127, "start":
> "2019-08-02
> > 01:02:24.351237", "stderr": "/bin/sh: pr_date: command not found",
> > "stderr_lines": ["/bin/sh: pr_date: command not found"], "stdout": "",
> > "stdout_lines": []}
> > ...ignoring
> >
> >
> > TASK [debug]
> >
> *
> > ok: [wf-omsal1-01-01] => {
> >  "pupstat.stdout_lines": "VARIABLE IS NOT DEFINED!"
> > }
> >
> > what I am  missing in calling the  variables?
> > using {{ }}  to items  also failed..
>
> Variables in with_items need {{ }} around them.
>
> --
> Kai Stian Olstad
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ansible-project/8ad-GDtPa6E/unsubscribe.
> To unsubscribe from this group and all its topics, 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/e744297c-9e97-56fa-2459-e7b505a4dc63%40olstad.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/CALNY%2B%2BQWD8X%2B7huJTDj5W6_vVd%3DGyiaN1nuL6%3D%3DaVJb_a9%2BWbQ%40mail.gmail.com.


[ansible-project] shell module with multiple arguments using variables

2019-08-01 Thread Veera
Hi,

I am trying to  call variables to the shell module  but failing ..

- name: status of  services
  hosts: myhost
  remote_user: root
  gather_facts: no
  vars:
- pp_stat: "/etc/init.d/puppet status"
- pr_date: "echo '= as on  date of ==='; date"

  strategy: free
  tasks:
- name: List the   status of the puppet services
  ignore_errors: yes
  shell: "{{ item }}"
  with_items:
 -  pp_stat
 - pr_date
  register: pupstat
- debug:
var: pupstat.stdout_lines


error reads:

TASK [List the   status of the puppet services] 
**
failed: [wf-omsal1-01-01] (item=pp_stat) => {"changed": true, "cmd": 
"pp_stat", "delta": "0:00:00.004792", "end": "2019-08-02 01:02:19.344642", 
"item": "pp_stat", "msg": "non-zero return code", "rc": 127, "start": 
"2019-08-02 
01:02:19.339850", "stderr": "/bin/sh: pp_stat: command not found", 
"stderr_lines": ["/bin/sh: pp_stat: command not found"], "stdout": "", 
"stdout_lines": []}
failed: [wf-omsal1-01-01] (item=pr_date) => {"changed": true, "cmd": 
"pr_date", "delta": "0:00:00.004765", "end": "2019-08-02 01:02:24.356002", 
"item": "pr_date", "msg": "non-zero return code", "rc": 127, "start": 
"2019-08-02 
01:02:24.351237", "stderr": "/bin/sh: pr_date: command not found", 
"stderr_lines": ["/bin/sh: pr_date: command not found"], "stdout": "", 
"stdout_lines": []}
...ignoring


TASK [debug] 
*
ok: [wf-omsal1-01-01] => {
"pupstat.stdout_lines": "VARIABLE IS NOT DEFINED!"
}

what I am  missing in calling the  variables?
using {{ }}  to items  also failed..

-- 
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/ece5e2ff-7e5f-4d37-b7c4-64b6394be17c%40googlegroups.com.


Re: [ansible-project] How to use piping multiple shell commands

2019-08-01 Thread Veera
Thanks Vinoth.  It worked

Yes . I learnt that we can use the formatting as in python either with ' '  
or  " ".




On Thursday, August 1, 2019 at 8:59:32 AM UTC+5:30, vinoth kumar wrote:
>
>
>
> On Thu, 1 Aug 2019 at 8:57 AM, vinoth kumar  > wrote:
>
>> Error clearly says to use proper quotes 
>> This would be fine i think so 
>> “netstat -nautp |grep -iE ‘137|389|445|636’|awk '{print $5}' |cut -d: 
>> -f2 |grep -iwE ‘137|389|445|636’”
>> Save it in Regiter
>> Use set_facts to store as a variable 
>>
>>
>> On Thu, 1 Aug 2019 at 8:31 AM, Veera > 
>> wrote:
>>
>>> Hi,
>>>
>>> I am trying the below   snippet to  detect  the established ports.  but 
>>> Ansible throws an error.
>>>
>>>  - name: List the  port connections 
>>>   shell: "netstat -nautp |grep -iE "137|389|445|636" |awk '{print 
>>> $5}' |cut -d: -f2 |grep -iwE "137|389|445|636"
>>>   register: dc_stat
>>>   debug:
>>> var: dc_stat.stdout_lines
>>>
>>> this through's the error
>>>
>>> The offending line appears to be:
>>>
>>>
>>> - name: List the  port connections 
>>>   shell: netstat -nautp |grep -iE "137|389|445|636" |awk '{print 
>>> $5}' |cut -d: -f2 |grep -iwE "137|389|445|636"
>>> 
>>>  ^ here
>>> We could be wrong, but this one looks like it might be an issue with
>>> unbalanced quotes.  If starting a value with a quote, make sure the
>>> line ends with the same set of quotes.  For instance this arbitrary
>>> example:
>>>
>>>
>>> foo: "bad" "wolf"
>>>
>>>
>>> Could be written as:
>>>
>>>
>>> foo: '"bad" "wolf"'
>>>
>>>
>>>
>>> I tried  inserted  a " " for the shell commands  and using  vars/pipe 
>>> also .. 
>>> How can i direct the output of "netstat -nautp |grep -iE "137|389|445|
>>> 636" |awk '{print $5}' |cut -d: -f2 |grep -iwE "137|389|445|636"" to a 
>>> variable  ?
>>>
>>> Or  do we have to use backslash(\)  as in shell ?
>>>
>>>
>>> -- 
>>> 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...@googlegroups.com .
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/ansible-project/3e2a9fa0-7974-4455-baa6-f45b2f690aae%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/ansible-project/3e2a9fa0-7974-4455-baa6-f45b2f690aae%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>

-- 
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/b1841eaa-5c31-4a98-b975-a279a020d22c%40googlegroups.com.


[ansible-project] How to use piping multiple shell commands

2019-07-31 Thread Veera
Hi,

I am trying the below   snippet to  detect  the established ports.  but 
Ansible throws an error.

 - name: List the  port connections 
  shell: "netstat -nautp |grep -iE "137|389|445|636" |awk '{print $5}' 
|cut -d: -f2 |grep -iwE "137|389|445|636"
  register: dc_stat
  debug:
var: dc_stat.stdout_lines

this through's the error

The offending line appears to be:


- name: List the  port connections 
  shell: netstat -nautp |grep -iE "137|389|445|636" |awk '{print $5}' |cut 
-d: -f2 |grep -iwE "137|389|445|636"

 ^ here
We could be wrong, but this one looks like it might be an issue with
unbalanced quotes.  If starting a value with a quote, make sure the
line ends with the same set of quotes.  For instance this arbitrary
example:


foo: "bad" "wolf"


Could be written as:


foo: '"bad" "wolf"'



I tried  inserted  a " " for the shell commands  and using  vars/pipe also 
.. 
How can i direct the output of "netstat -nautp |grep -iE "137|389|445|636" 
|awk '{print $5}' |cut -d: -f2 |grep -iwE "137|389|445|636"" to a variable  
?

Or  do we have to use backslash(\)  as in shell ?


-- 
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/3e2a9fa0-7974-4455-baa6-f45b2f690aae%40googlegroups.com.


[ansible-project] Ansible yum module arguement equivalent for repolist.

2019-05-29 Thread Veera
Hi,

I am using the following snippet  as part of a play. 
I have to refresh the  yum repository list as I will replace the repository 
file every time I run the playbook . 
So , After  having  a successful  play  to copy my test.repo file to 
/etc/yum.repos.d/test.repo  . I am able to  successfully run the  "yum 
repolist"  with command module.

 - name: Refresh the yum repository  cache
>   #yum:
>   #  update_cache: yes
>   command: "yum repolist"
>   register: repo_list



But ansible suggest to use yum module  , but the doc have no equivalent for 
the  "repolist" of yum .
Is "update_cache"  do the same fuction like "yum repolist"?

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/01be47bc-81eb-46c3-bbfd-cd7563a0c19d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] debug module stdout print only 8 lines

2019-05-28 Thread Veera
Thanks .
I am able to print  20  lines  in stdout .. 
Sorry it is a miss from my side and I learned a debug option today . 



On Tuesday, May 28, 2019 at 2:59:46 AM UTC+5:30, Kai Stian Olstad wrote:
>
> On 27.05.2019 22:28, Veera wrote: 
> > For  any  standard "var.stdout"  only  8 lines are printing .  Any way 
> > to 
> > increase the  std.output  lines  above  8 lines 
>
> Can't confirm this behavior with Ansible 2.8.0 
>
> test.yml 
> --- 
> - hosts: localhost 
>gather_facts: no 
>become: no 
>tasks: 
>  - shell: for i in `seq 1 10`; do echo $i; done 
>register: result 
>  - debug: var=result.stdout_lines 
>
> $ ansible-playbook test.yml 
>
> PLAY [localhost]  
>
> TASK [shell]  
> changed: [localhost] 
>
> TASK [debug]  
> ok: [localhost] => { 
>  "result.stdout_lines": [ 
>  "1", 
>  "2", 
>  "3", 
>  "4", 
>  "5", 
>  "6", 
>  "7", 
>  "8", 
>  "9", 
>  "10" 
>  ] 
> } 
>
>
> -- 
> Kai Stian Olstad 
>

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/810926dc-9af7-476b-bb8e-5d85c30cf2b9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] debug module stdout print only 8 lines

2019-05-27 Thread Veera
Hi,
 
 I am trying to output of an ansible playbook , which  is an output of a 
custom service status.



 register: webstat
- debug:
var: webstat.stdout_lines
verbosity: 0


and the output is  as  follows...

ok: [server1] => {
"webstat.stdout_lines": [
"",
"Web Service running...",
"",
"",
"Web  Agent running...",
"",
"",
"Web db Agent running..."
]
}

but the  adhoc  command,  the   actual   output is  5 lines


For  any  standard "var.stdout"  only  8 lines are printing .  Any way to  
increase the  std.output  lines  above  8 lines 

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/c4624728-939d-4495-8123-7c82f781d778%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Store ssh passphrase for another session.

2019-05-21 Thread Veera


I have a set of ansible client servers accessible from ansible engine using 
ssh-key and passphrase.


When I run a ansible ad-hoc command , I have to enter passphase on each 
servers connections and this is repeating for all the tasks.

However from github search , find a way to reduce the enter the passphrase 
only one time by using the ssh-agent "eval "$(ssh-agent -s)" ; ssh-add 
~/.ssh/id_rsa" and by entering passphrase once .


When I exit the shell and re-login the I have to re-run and enter the 
commands and passphrase again .

How can I avoid this ? Is there a way to store the passphrase as like in 
ansible-vault and use it for login?

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/4afb31d3-ee5c-4682-b58c-a57161ab83f8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Looking for an ansible module which supports yum-utils package

2019-05-12 Thread Veera
Hi ,

I am looking for an ansible module which supports  yum-utils package 
commands.
It consists of  a command *"package-cleanup**"*  which is  pretty useful in 
cleaning  the  old kernels.

package-cleanup --oldkernels --count=2   <= this  command will clean up all old 
kernels and keep just two(The current one and the previous one)


But on search  in the  Module  index of ansible, or under package 
management,there is  no module for this command "package-cleanup".

Do  anyone uses the ansible modules of commands from yum-utils?  Kindly  
share the details ..


-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/543094cb-3a83-4596-9f5d-ecf516103d1e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] ios_command multiple commands

2019-01-04 Thread Veera Kumar
Hi,

You can give list of commands and all the outputs will register in
mentioned variable name. And instead output.stdout[0] just give
output.stdout.

But the problem is variable I.e output.stdout will only contain outputs
only. Means issued command will not be there.

Try with blockinfile module to have command1
output of command1
Command2
Output of command2

Thanks,
Veera


On Sat, 5 Jan 2019, 01:21 Eduardo Nunes Pereira  - name: Network Getting Started First Playbook
> connection: network_cli
> gather_facts: false
> hosts: lab
> tasks:
>
> - name: run multiple commands on remote nodes
> ios_command:
> commands:
> - show run
> register: output
>
> - name: save output
> copy:
> content: "{{ output.stdout[0] }}"
> dest: "/etc/ansible/backup/{{ inventory_hostname }}.txt"
>
>
>
>
> Have you had the chance to save a set of multiple commands on file, just
> save the first one from the list, does anyone have the same scenario?
>
> --
> 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 post to this group, send email to ansible-project@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/05fc87c6-0e0d-4841-b6ed-32690a95cc86%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/05fc87c6-0e0d-4841-b6ed-32690a95cc86%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAOfyRijr8mEgoUZg6f2mGWbERPpz0iq8WQVDsEbMYh%3DSbFAhFw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Re: Rebooting a Cisco ASA device

2019-01-04 Thread Veera Kumar
Please refer below link as well,

https://gdykeman.github.io/2018/06/26/ios-upgrades/


On Fri, Jan 4, 2019 at 1:25 PM Ganesh Nalawade  wrote:

> Try adding "meta: reset_connection" after wait_for task and before check
> version task.
> Also, which Ansible version are you using?
>
> Regards,
> Ganesh
>
> On Friday, 4 January 2019 04:26:41 UTC+5:30, Sahar wrote:
>>
>> I'm trying to reboot a Cisco ASA Firewall, and run the "show version"
>> command after it. It seems that rebooting works, but when the playbook gets
>> to the show version command, it will get failed by showing the error down
>> below. Any idea about it?
>>
>>
>>
>>
>>
>> - name: Rebooting the ASA
>>   asa_command:
>> commands:
>> - "reload\n"
>>
>>
>> - wait_for: timeout=180
>>
>>
>> - name: check the version
>>   asa_command:
>> commands:
>> -  show version
>>   register: output
>>
>>
>> - name: check the version
>>   debug: var=output.stdout
>>
>>
>>
>>
>>
>> TASK [Rebooting the ASA]
>> ***
>> skipping: [Fw4Script-02.tor.bellnhs.int]
>> ok: [Fw4Script-01.tor.bellnhs.int]
>>
>> TASK [wait_for]
>> 
>> skipping: [Fw4Script-02.tor.bellnhs.int]
>> ok: [Fw4Script-01.tor.bellnhs.int]
>>
>>
>> TASK [check the version]
>> 
>> skipping: [Fw4Script-02.tor.bellnhs.int]
>> An exception occurred during task execution. To see the full traceback,
>> use -vvv. The error was: ansible.module_utils.connection.ConnectionError:
>> Socket is closed
>> fatal: [Fw4Script-01.tor.bellnhs.int]: FAILED! => {"changed": false,
>> "module_stderr": "Traceback (most recent call last):\n  File
>> \"/home/shdianat/.ansible/tmp/ansible-local-12216t0E3Bw/ansible-tmp-1546555792.58-98199446309935/AnsiballZ_asa_command.py\",
>> line 113, in \n_ansiballz_main()\n  File
>> \"/home/shdianat/.ansible/tmp/ansible-local-12216t0E3Bw/ansible-tmp-1546555792.58-98199446309935/AnsiballZ_asa_command.py\",
>> line 105, in _ansiballz_main\ninvoke_module(zipped_mod, temp_path,
>> ANSIBALLZ_PARAMS)\n  File
>> \"/home/shdianat/.ansible/tmp/ansible-local-12216t0E3Bw/ansible-tmp-1546555792.58-98199446309935/AnsiballZ_asa_command.py\",
>> line 48, in invoke_module\nimp.load_module('__main__', mod, module,
>> MOD_DESC)\n  File \"/tmp/ansible_asa_command_payload_4Z1mL_/__main__.py\",
>> line 195, in \n  File
>> \"/tmp/ansible_asa_command_payload_4Z1mL_/__main__.py\", line 165, in
>> main\n  File
>> \"/tmp/ansible_asa_command_payload_4Z1mL_/ansible_asa_command_payload.zip/ansible/module_utils/network/asa/asa.py\",
>> line 124, in run_commands\n  File
>> \"/tmp/ansible_asa_command_payload_4Z1mL_/ansible_asa_command_payload.zip/ansible/module_utils/connection.py\",
>> line 173, in __rpc__\nansible.module_utils.connection.ConnectionError:
>> Socket is closed\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee
>> stdout/stderr for the exact error", "rc": 1}
>>
>>
>>
>>
>> These are the parameters in ansible.cfg file:
>>
>> [persistent_connection]
>>
>> connect_timeout = 300
>> command_timeout = 300
>>
>> --
> 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 post to this group, send email to ansible-project@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/f31d-7e0c-4eec-a39e-96aee001f124%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAOfyRigatpTCO%3Dr1_UpG26fjYrM7%2BhSJfB1P%2BZy9-Qe-7ES4iw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Send commands to a not supported router

2018-05-16 Thread Veera Kumar
Couple of ways we have,

We can group Cisco and other vendor devices.
Then we can add condition only when hostname matches with Cisco group will
execute the command. On other devices this task will be slipped.

Still you are not familiar with group concepts, then simply add
ignore_errors: yes on this task. Means even iOS command not able to execute
on other vendor devices, it ll keep doing other tasks on this play.

Thx, Veera

On Thu, May 17, 2018, 6:55 AM Juan Manuel Fernandez 
wrote:

> Hi!
> I'm a newbie to the ansible world.
> I want to generate a .yml file that send commands to a router.
> I try with routers cisco with the ios_command module and works fine but y
> want to do the same with other router of other provider and it's failed.
> Do you know a module that permit any commands without validations? (I want
> to make the check on the yml).
> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-project+unsubscr...@googlegroups.com.
> To post to this group, send email to ansible-project@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/82556884-1917-49c8-8522-6b3013f6e8b5%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/82556884-1917-49c8-8522-6b3013f6e8b5%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAOfyRij6LbAa-2jGwtGLj4SWhZGmAZUZQbCinPHmdPpW9i4rkg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] bigip_configsync_action module in Ansible version 2.5 is not working

2018-05-11 Thread Veera Kumar
*bigip_configsync_action module is not working  in Ansible 2.5*

*ISSUE TYPE*

Since from 2.5 version, Ansible added provider to bigip_configsync_action, 
there is some confusion. 
bigip_configsync_action module not doing the config-SYNC and keep showing 
Error as ["Unable to connect to BIGIP_F52.test.com on port 22. Is 
\"validate_certs\" preventing this?"]


BIGIP_F52.test.com is my F5 Box name against which am ruining my playbook.


# COMPONENT NAME
  bigip_configsync_action

# ANSIBLE VERSION

[root@localhost F5BIGIP]# ansible --version
ansible 2.5.0
  config file = /etc/ansible/F5BIGIP/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', 
u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Aug  4 2017, 00:39:18) [GCC 4.8.5 
20150623 (Red Hat 4.8.5-16)]
[root@localhost F5BIGIP]#


# PYTHON VERSION
[root@localhost F5BIGIP]# python -V
Python 2.7.5
[root@localhost F5BIGIP]#

# BIGIP VERSION

[root@BIGIP_F52:Active:Not All Devices Synced] config # tmsh show sys 
version

Sys::Version
Main Package
  Product BIG-IP
  Version 13.0.0
  Build   2.0.1671
  Edition Hotfix HF2
  DateFri Apr 28 20:36:43 PDT 2017



# CONFIGURATION

[root@localhost F5BIGIP]# cat ansible.cfg
[defaults]
inventory=inventory
#ask_pass  = True
transport  = ssh
remote_port= 22
host_key_checking=False
[root@localhost F5BIGIP]#


# OS / ENVIRONMENT
NA

# SUMMARY

Since from 2.5 version, Ansible added provider to bigip_configsync_action, 
there is some confusion. 
bigip_configsync_action module not doing the config-SYNC and keep showing 
Error as ["Unable to connect to BIGIP_F52.test.com on port 22. Is 
\"validate_certs\" preventing this?"]


# STEPS TO REPRODUCE

---
 - name : Auto Config-SYNC on F5 HA
   hosts : BIGIP_F52.test.com
#   connection : local
   gather_facts : no

   tasks:
 - name: Sync configuration from device to group
   bigip_configsync_action:
 server: BIGIP_F52.test.com
 user: "admin"
 password: "veera@123"
 transport: "rest"
 server_port: 22
 overwrite_config: yes
 device_group: "device-group-failover-bca6a09f80d1"
 sync_device_to_group: yes
 validate_certs: no
   delegate_to: localhost


Even I have tried with server_port: 443 with transport type as rest. 
I have tried with server_port: 22 with transport type as cli.
I have tried with server_port: 443 with transport type as cli.  



# EXPECTED RESULTS
Config-SYNC will be performed.

# ACTUAL RESULTS

fatal: [BIGIP_F52.test.com -> localhost]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"device_group": "device-group-failover-bca6a09f80d1",
"overwrite_config": true,
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"provider": {
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"server": "BIGIP_F52.test.com",
"server_port": 22,
"ssh_keyfile": null,
"timeout": 10,
"transport": "rest",
"user": "admin",
"validate_certs": false
},
"server": "BIGIP_F52.test.com",
"server_port": 22,
"sync_device_to_group": true,
"sync_most_recent_to_device": null,
"transport": "rest",
"user": "admin",
"validate_certs": false
}
},
"msg": "Unable to connect to BIGIP_F52.test.com on port 22. Is 
\"validate_certs\" preventing this?"
}
to retry, use: --limit @/etc/ansible/F5BIGIP/test11.retry

PLAY RECAP 
*
BIGIP_F52.test.com : ok=0changed=0unreachable=0failed=1

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/2fe70e68-8855-405b-bdc9-9ac08ce6b776%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


  1   2   >