[ansible-project] how do we read a set_fact variable of a dynamic host into different play localhost ?

2019-11-24 Thread Shifa Shaikh


Here is my requirement:

   - 
   
   I have a playbook where I add the dynamic host to group "desthosts" in 
   [Play 1]
   - 
   
   In [Play 2] desthosts group I append a set_fact variable "storerecords".
   - 
   
   In [Play 3] I try to read set_fact "storerecords" of Play 2 however, I get 
   undefined 'storerecords' variable error.
   
Below is my playbook.

---
- name: Play 1
  hosts: localhost
  tasks:
- add_host:
  name: "{{ item }}"
  group: desthosts
  with_items:
- "{{ SourceHost.split(',') }}" 

- name: Play 2
  hosts: desthosts
  tasks: 
- set_fact:
storerec: "{{storerec | default('') + 'Hello ' + inventory_hostname + 
'\n'}}"
  with_fileglob:
- "{{ playbook_dir }}/tmpfiles/*"

- name: Play 3
  hosts: localhost
  tasks:
   - local_action: lineinfile line="{{ hostvars['dest_nodes']['storerec'] }}" 
path="{{ playbook_dir }}/files/tricky.txt" create=yes

Playbook run command:

ansible-playbook test.yml -e SourceHost="10.9.9.56,10.9.9.63,10.9.9.33" 

Error running the playbook is:
TASK [lineinfile] 

 
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an 
undefined variable. The error was: \"hostvars['desthosts']\" is 
undefined\n\nThe error appears to be in '/app/test.yml': line 28, column 7, 
but may\nbe elsewhere in the file depending on the exact syntax 
problem.\n\nThe offending line appears to be:\n\n tasks:\n - local_action: 
lineinfile line=\"{{ hostvars['desthosts']['storerec'] }}\" path=\"{{ 
playbook_dir }}/files/tricky.txt\" create=yes\n ^ here\nWe could be wrong, 
but this one looks like it might be an issue with\nmissing quotes. Always 
quote template expression brackets when they\nstart a value. For 
instance:\n\n with_items:\n - {{ foo }}\n\nShould be written as:\n\n 
with_items:\n - \"{{ foo }}\"\n"}



Can you please suggest how I can get the value of storerecords from 
desthost to Play 3?

-- 
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/147edb97-1c14-4059-bf35-3dca35861c1a%40googlegroups.com.


[ansible-project] Unable to load variable from include_vars into my playbook

2020-02-24 Thread Shifa Shaikh
I have a playbook where I load a variable file 

cat vars/BASE.yaml


EXCLUDE_front: value1
EXCLUDE_back: value2


I run my test.yml playbook using this command:

ansible-playbook test.yml -e Layer="back" -e base_folder="/tmp"


- name: Load a variable file"
  include_vars:
file: "vars/BASE.yaml"

- name: Collect data
  shell: "cd {{ base_folder }} && find . -type d \\( -name 'BACKUP' -o -name 
'vars[EXCLUDE_{{ Layer }}]' \\) -prune -o -type f -exec cksum {} + | awk 
'{$1=\"\"}1'"
  register: outputfiles

I also tried 

  shell: "cd {{ base_folder }} && find . -type d \\( -name 'BACKUP' -o 
-name 'vars[EXCLUDE_ + Layer ]' \\) -prune -o -type f -exec cksum {} + | 
awk '{$1=\"\"}1'"

and

  shell: "cd {{ base_folder }} && find . -type d \\( -name 'BACKUP' -o 
-name 'vars[EXCLUDE_ ~ Layer ]' \\) -prune -o -type f -exec cksum {} + | 
awk '{$1=\"\"}1'"

however,  instead of loading value1 or value2, I get the below nature of 
error:

"The task includes an option with an undefined variable. The error was: 
> 'EXCLUDE_' is undefined\n\nT


Can you please suggest what is wrong with my playbook? 

-- 
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/f76a6376-0ac3-4724-9bb9-6fc54bd69610%40googlegroups.com.


[ansible-project] How to escape single quotes within single quotes in Ansible

2020-02-25 Thread Shifa Shaikh
Below is my playbook:

   - set_fact:
   excludefolders: "{{ excludefolders + ' -o -name ' + item | 
default('') }}"
 with_items: "{{ lookup('vars', 'EXCLUDE_' + Layer).split(',') }}"


   - debug:
   msg: "excludedfolder is {{ excludefolders }}"


I get the below output

ok: [10.0.17.113] => { "msg": "excludedfolder is -o -name custom -o -name tree 
-o -name log"


However i want the variable to have single quotes around item like below:

Expected output:

ok: [10.0.17.113] => { "msg": "excludedfolder is -o -name 'custom' -o -name 
'tree' -o -name 'log'"


I tried to use escape charecter for single quotes but none of them worked. 
Below is what  tried.

   - set_fact:
   excludefolders: "{{ excludefolders + ' -o -name ' + \' + item + \' 
 | default('') }}"
 with_items: "{{ lookup('vars', 'EXCLUDE_' + Layer).split(',') }}"


   - set_fact:
   excludefolders: "{{ excludefolders + ' -o -name ' ~ \' + item ~ \' 
 | default('') }}"
 with_items: "{{ lookup('vars', 'EXCLUDE_' + Layer).split(',') }}"


   - set_fact:
   excludefolders: "{{ excludefolders + ' -o -name \''  + item +'\''  | 
default('') }}"
 with_items: "{{ lookup('vars', 'EXCLUDE_' + Layer).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/b857c17b-00f3-44bb-8fd8-4d08f597b6ce%40googlegroups.com.


[ansible-project] set_fact undefined variable issue when concat string to itself.

2020-02-25 Thread Shifa Shaikh
I need to set_fact variable and contact to itself a list of items as below:

- set_fact:
excludefolders: "{{ excludefolders + ' -o -name ' + item | 
default('') }}"
  with_items: "{{ lookup('vars', 'MY_' + Layer).split(',') }}"


Getting error:

FAILED! => {"msg": "The task includes an option with an undefined variable. The 
error was: 'excludefolders' is undefined\n\nThe error appears to be in 
'/app/test.yml': line 86, column 6, but may\nbe elsewhere in the file depending 
on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n   - 
set_fact:\n ^ here\n"}


Is it neccessary to defined another set_fact before like below or is there 
a better solution to the issue ?

- set_fact:
excludefolders: ""


- set_fact:
excludefolders: "{{ excludefolders + ' -o -name ' + item | 
default('') }}"
  with_items: "{{ lookup('vars', 'EXCLUDE_' + Layer).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/3c491483-c408-4176-98dd-09a3bed1b47e%40googlegroups.com.


Re: [ansible-project] How to escape single quotes within single quotes in Ansible

2020-02-25 Thread Shifa Shaikh
@Stefan i tried using quote but it does not help. Can you confirm if this 
is the right way to use quote ? See below: 


excludefolders: "{{ excludefolders + ' -o -name ' + item | quote | 
default('') }}"



On Wednesday, February 26, 2020 at 12:42:57 PM UTC+5:30, Stefan Hornburg 
(Racke) wrote:
>
> On 2/26/20 8:05 AM, Shifa Shaikh wrote: 
> > Below is my playbook: 
> > 
> > | 
> >-set_fact: 
> >excludefolders:"{{ excludefolders + ' -o -name ' + item | 
> default('') }}" 
> >  with_items:"{{ lookup('vars', 'EXCLUDE_' + Layer).split(',') }}" 
> > 
> > 
> >-debug: 
> >msg:"excludedfolder is {{ excludefolders }}" 
> > | 
> > 
> > 
> > I get the below output 
> > 
> > | 
> > ok:[10.0.17.113]=>{"msg":"excludedfolder is -o -name custom -o -name 
> tree -o -name log" 
> > | 
> > 
> > 
> > However i want the variable to have single quotes around item like 
> below: 
> > 
> > Expected output: 
> > 
> > | 
> > ok:[10.0.17.113]=>{"msg":"excludedfolder is -o -name 'custom' -o -name 
> 'tree' -o -name 'log'" 
> > | 
> > 
> > 
> > I tried to use escape charecter for single quotes but none of them 
> worked. Below is what  tried. 
> > 
> > | 
> >-set_fact: 
> >excludefolders:"{{ excludefolders + ' -o -name ' + \' + item + \' 
>  | default('') }}" 
> >  with_items:"{{ lookup('vars', 'EXCLUDE_' + Layer).split(',') }}" 
> > 
> > 
> >-set_fact: 
> >excludefolders:"{{ excludefolders + ' -o -name ' ~ \' + item ~ \' 
>  | default('') }}" 
> >  with_items:"{{ lookup('vars', 'EXCLUDE_' + Layer).split(',') }}" 
> > 
> > 
> >-set_fact: 
> >excludefolders:"{{ excludefolders + ' -o -name \''  + item +'\'' 
>  | default('') }}" 
> >  with_items:"{{ lookup('vars', 'EXCLUDE_' + Layer).split(',') }}" 
> > 
> > | 
> > 
>
> What about the quote filter? 
>
>
> https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#id8 
>
> Regards 
>  Racke 
>
> > 
> > 
> > -- 
> > 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   ansible-project+unsubscr...@googlegroups.com >. 
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/ansible-project/b857c17b-00f3-44bb-8fd8-4d08f597b6ce%40googlegroups.com
>  
> > <
> https://groups.google.com/d/msgid/ansible-project/b857c17b-00f3-44bb-8fd8-4d08f597b6ce%40googlegroups.com?utm_medium=email_source=footer>.
>  
>
>
>
> -- 
> Ecommerce and Linux consulting + Perl and web application programming. 
> Debian and Sympa administration. Provisioning with 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/006c8253-7889-4d4f-b135-ada8a6a1833b%40googlegroups.com.


Re: [ansible-project] Unable to load variable from include_vars into my playbook

2020-02-25 Thread Shifa Shaikh
It's works. Thank you Stefen

On Wed, 26 Feb, 2020, 12:13 am Stefan Hornburg (Racke), 
wrote:

> On 2/24/20 9:52 PM, Dick Visser wrote:
> > You can’t resolve variables with names that contain variables
> themselves.
> > Instead, use a lookup:
> >
> > https://docs.ansible.com/ansible/latest/plugins/lookup/vars.html
> >
> > Also try to use the args: chdir option instead of doing &&, see
> > https://docs.ansible.com/ansible/latest/modules/shell_module.html
> >
>
> "{{ vars['EXCLUDE_' + Layer] }}" should work though.
>
> Regards
>  Racke
>
> >
> >
> > On Mon, 24 Feb 2020 at 19:18, Shifa Shaikh  shifa...@gmail.com>> wrote:
> >
> > I have a playbook where I load a variable file
> >
> > |
> > cat vars/BASE.yaml
> >
> >
> > EXCLUDE_front:value1
> > EXCLUDE_back:value2
> > |
> >
> >
> > I run my test.yml playbook using this command:
> >
> > |
> > ansible-playbook test.yml -e Layer="back"-e base_folder="/tmp"
> >
> >
> > -name:Loada variable file"
> >   include_vars:
> > file: "vars/BASE.yaml"
> >
> > - name: Collect data
> >   shell: "cd {{base_folder }}& .-type d \\(-name 'BACKUP'-o
> -name 'vars[EXCLUDE_{{ Layer }}]'\\)-prune -o -type
> > f -execcksum {}+|awk '{$1=\"\"}1'"
> >   register: outputfiles
> > |
> >
> > I also tried
> >
> > |
> >   shell:"cd {{ base_folder }} && find . -type d \\( -name 'BACKUP'
> -o -name 'vars[EXCLUDE_ + Layer ]' \\) -prune -o
> > -type f -exec cksum {} + | awk '{$1=\"\"}1'"
> > |
> >
> > and
> >
> > |
> >   shell:"cd {{ base_folder }} && find . -type d \\( -name 'BACKUP'
> -o -name 'vars[EXCLUDE_ ~ Layer ]' \\) -prune -o
> > -type f -exec cksum {} + | awk '{$1=\"\"}1'"
> > |
> >
> > however,  instead of loading value1 or value2, I get the below
> nature of error:
> >
> > "The task includes an option with an undefined variable. The
> error was: 'EXCLUDE_' is undefined\n\nT
> >
> >
> > Can you please suggest what is wrong with my playbook?
> >
> > --
> > 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  ansible-project+unsubscr...@googlegroups.com>.
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/ansible-project/f76a6376-0ac3-4724-9bb9-6fc54bd69610%40googlegroups.com
> > <
> https://groups.google.com/d/msgid/ansible-project/f76a6376-0ac3-4724-9bb9-6fc54bd69610%40googlegroups.com?utm_medium=email_source=footer
> >.
> >
> > --
> > Sent from a mobile device - please excuse the brevity, spelling and
> punctuation.
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Ansible Project" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to
> > ansible-project+unsubscr...@googlegroups.com  ansible-project+unsubscr...@googlegroups.com>.
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/ansible-project/CAL8fbwOiQArWXn2N4pc1vW-YmAZ09dNn3cN2yy_ZgWVbh6ieEw%40mail.gmail.com
> > <
> https://groups.google.com/d/msgid/ansible-project/CAL8fbwOiQArWXn2N4pc1vW-YmAZ09dNn3cN2yy_ZgWVbh6ieEw%40mail.gmail.com?utm_medium=email_source=footer
> >.
>
>
> --
> Ecommerce and Linux consulting + Perl and web application programming.
> Debian and Sympa administration. Provisioning with 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/11ef6e0e-fb43-ddd0-a7e7-64ed0510e782%40linuxia.de
> .
>

-- 
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/CAJtox0npOOg5Gg2i%3DZfsYfeeqzETW9Na73zUWZ%2Bmge5LZu9q%2Bg%40mail.gmail.com.


Re: [ansible-project] set_fact undefined variable issue when concat string to itself.

2020-02-26 Thread Shifa Shaikh
It helped. Thank you @Abhijeet

On Wednesday, February 26, 2020 at 12:09:19 PM UTC+5:30, Abhijeet Kasurde 
wrote:
>
> You can try this - 
>
> - set_fact:
> excludefolders: "{{ excludefolders | default('') + ' -o -name ' + 
> item | default('') }}"
>   with_items: "{{ lookup('vars', 'EXCLUDE_' + Layer).split(',') }}"
>
> On Wed, Feb 26, 2020 at 12:00 PM Shifa Shaikh  > wrote:
>
>> I need to set_fact variable and contact to itself a list of items as 
>> below:
>>
>> - set_fact:
>> excludefolders: "{{ excludefolders + ' -o -name ' + item | 
>> default('') }}"
>>   with_items: "{{ lookup('vars', 'MY_' + Layer).split(',') }}"
>>
>>
>> Getting error:
>>
>> FAILED! => {"msg": "The task includes an option with an undefined variable. 
>> The error was: 'excludefolders' is undefined\n\nThe error appears to be in 
>> '/app/test.yml': line 86, column 6, but may\nbe elsewhere in the file 
>> depending on the exact syntax problem.\n\nThe offending line appears to 
>> be:\n\n\n   - set_fact:\n ^ here\n"}
>>
>>
>> Is it neccessary to defined another set_fact before like below or is 
>> there a better solution to the issue ?
>>
>> - set_fact:
>> excludefolders: ""
>>
>>
>> - set_fact:
>> excludefolders: "{{ excludefolders + ' -o -name ' + item | 
>> default('') }}"
>>   with_items: "{{ lookup('vars', 'EXCLUDE_' + Layer).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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/3c491483-c408-4176-98dd-09a3bed1b47e%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/3c491483-c408-4176-98dd-09a3bed1b47e%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>
>
> -- 
> Thanks,
> Abhijeet Kasurde
>

-- 
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/c1f980b4-68fc-4005-bd82-1c09717d5a62%40googlegroups.com.


[ansible-project] Need to construct complex HTML file from Jinja template

2020-03-05 Thread Shifa Shaikh
Experts Hi,

I have a variable file that has a set of flowers, colors, and countries. 

# cat vars/DASHBOARD_vars.yaml
---
myarch:
  - name: brown,white,black,green
  - name: rose,jasmine
  - name: Japan,Germany,France

  
I wish to create one HTML file each, thus 1 HTML for all colors, 1 HTML 
file for all flowers and 1 HTML for all countries. Below is what i expect 
how my colors HTML file should look like.




brown
white
black
green




DR









http://localhost/sample;> 
http://localhost/sample;> 

http://localhost/sample;> 




PROD
  
  
  
  




Likewaise flowers HTML would look like below:





rose
jasmine




DR







http://localhost/sample;> 
http://localhost/sample;> 




PROD
  
  




and similarly one HTML for countries.

I guess I need to use ansible's template feature to construct these HTML 
files.

Below is my playbook where I was able to read the variable files in order.

# cat dashboard.yml
- name: Play 1
  hosts: localhost
  tasks:
   - name: Load a variable file"
 include_vars:
   file: "vars/DASHBOARD_vars.yaml"


   - name: Declare array for IPs
 include_tasks: "{{ playbook_dir }}/dashboard_inner.yml"
 loop: "{{ myarch }}"
 loop_control:
   loop_var: myresult


# cat dashboard_inner.yml
---
- name: Declare here
  include_tasks: "{{ playbook_dir }}/dashboard_inner_inner.yml"
  loop: "{{ myresult.name.split(',') }}"
  
# cat dashboard_inner_inner.yml
---
  - block:
  - template:
  src: "templates/dashboard_body.html.j2"
  dest: "dashboard/dashboard_body_{{ item }}.html"
  - debug:
  msg: "HERE IS:{{ item }}"

  
When I run it creates HTML files for each component however, I'm not sure 
how my "templates/dashboard_body.html.j2" should be constructed to get me 
the desired output?

A couple of pointers to consider while construction the HTML is 

1. bgcolor:  bgcolor changes for each table i.e 
for flowers, colors and countries each will have three different colors.

2. 
if "white" folder has bad.txt files say /tmp/white/bad.txt returns true 
then below  should be populated 

http://localhost/sample;> 

else the below one should be




Output of my run:

# ansible-playbook -i "all" dashboard.yml


PLAY [Play 1] 
*


TASK [Gathering Facts] 

ok: [localhost]


TASK [Load a variable file"] 
**
ok: [localhost]


TASK [Declare array for IPs] 
**
included: /root/test/dashboard_inner.yml for localhost
included: /root/test/dashboard_inner.yml for localhost


TASK [Declare here] 
***
included: /root/test/dashboard_inner_inner.yml for localhost
included: /root/test/dashboard_inner_inner.yml for localhost
included: /root/test/dashboard_inner_inner.yml for localhost
included: /root/test/dashboard_inner_inner.yml for localhost


TASK [template] 
***
changed: [localhost]


TASK [debug] 
**
ok: [localhost] => {
"msg": "HERE IS:brown"
}


TASK [template] 
***
changed: [localhost]


TASK [debug] 
**
ok: [localhost] => {
"msg": "HERE IS:white"
}


TASK [template] 
***
changed: [localhost]


TASK [debug] 
**
ok: [localhost] => {
"msg": "HERE IS:black"
}


TASK [template] 
***
changed: [localhost]



[ansible-project] Need help construct a complex HTML using Jinja template.

2020-03-05 Thread Shifa Shaikh
Experts Hi,

I have a variable file that has a set of flowers, colors, and countries. 

# cat vars/DASHBOARD_vars.yaml
---
myarch:
  - COLOR:
name: blue,white,black,green
  - FLOWER:
name: rose,jasmine
  - COUNTRY:
name: Japan,Germany,France


  
I wish to create one HTML file each, thus 1 HTML for all colors, 1 HTML 
file for all flowers and 1 HTML for all countries. Below is what i expect 
how my colors HTML file should look like.




blue
white
black
green






DR











http://localhost/sample;> 
http://localhost/sample;> 

http://localhost/sample;> 






PROD
  
  
  
  





Likewaise flowers HTML would look like below:





rose
jasmine






DR









http://localhost/sample;> 
http://localhost/sample;> 






PROD
  
  





and similarly one HTML for countries.

I guess I need to use ansible's template feature to construct these HTML 
files.

Below is my playbook where I FLOWER able to read the variable files in 
order.

# cat dashboard.yml
- name: Play 1
  hosts: localhost
  tasks:
   - name: Load a variable file"
 include_vars:
   file: "vars/DASHBOARD_vars.yaml"




   - name: Declare array for IPs
 include_tasks: "{{ playbook_dir }}/dashboard_inner.yml"
 loop: "{{ myarch }}"
 loop_control:
   loop_var: myresult


# cat dashboard_inner.yml
---
- name: Declare here
  include_tasks: "{{ playbook_dir }}/dashboard_inner_inner.yml"
  loop: "{{ myresult.name.split(',') }}"
  
# cat dashboard_inner_inner.yml
---
  - block:
  - template:
  src: "templates/dashboard_body.html.j2"
  dest: "dashboard/dashboard_body_{{ item }}.html"
  - debug:
  msg: "HERE IS:{{ item }}"



  
When I run it creates HTML files for each component however, I'm not sure 
how my "templates/dashboard_body.html.j2" should be constructed to get me 
the desired output?

A couple of pointers to consider while construction the HTML is 

1. bgcolor: 


bgcolor changes for each table i.e for flowers, colors and countries each 
will have three different colors.

2. 
if "white" folder has bad.txt files say /tmp/white/bad.txt returns true 
then below  should be populated 

http://localhost/sample;> 


else the below one should be





Output of my run:

# ansible-playbook -i "all" dashboard.yml




PLAY [Play 1] 
*


TASK [Gathering Facts] 

ok: [localhost]


TASK [Load a variable file"] 
**
ok: [localhost]


TASK [Declare array for IPs] 
**
included: /root/test/dashboard_inner.yml for localhost
included: /root/test/dashboard_inner.yml for localhost


TASK [Declare here] 
***
included: /root/test/dashboard_inner_inner.yml for localhost
included: /root/test/dashboard_inner_inner.yml for localhost
included: /root/test/dashboard_inner_inner.yml for localhost
included: /root/test/dashboard_inner_inner.yml for localhost


TASK [template] 
***
changed: [localhost]


TASK [debug] 
**
ok: [localhost] => {
"msg": "HERE IS:blue"
}


TASK [template] 
***
changed: [localhost]


TASK [debug] 
**
ok: [localhost] => {
"msg": "HERE IS:white"
}


TASK [template] 
***
changed: [localhost]


TASK [debug] 
**
ok: [localhost] => {
"msg": "HERE IS:black"
}


TASK [template] 

[ansible-project] Convert list to string in rendered Jinja template

2020-03-06 Thread Shifa Shaikh
I have a variable files like below:

  layers:
- name: APP
  things:
- cactus
- lotus
- jasmine
- rose
  bgcolor:
- sky blue


- name: WAS
  things:
- mango
- apple
  bgcolor:
- yellow


Below is my jinja template file:
{% for layer in layers %}


 
{% for item in layer.things %}
{{ item }}
{% endfor %}


{% endfor %}

I run this with the below playbook:

---
  - name: Demonstrating variables in Jinja2 Loops
hosts: localhost
connection: local
vars_files:
  - vars.yml
gather_facts: no
tasks:
  - name: Create the Jinja2 based templateone

template: src=./varloop_new.j2 dest=./output.txt



The output recieved has a problem. 

Output.txt:

-bash-4.2$ cat output.txt


 
cactus
lotus
jasmine
rose




 
mango
apple




It displays bgcolor="[u'sky blue']" instead of bgcolor="sky blue"

How can I convert the list to a string in the jinja template.

-- 
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/10765862-e99b-44bf-bdb8-0db36c1fc49b%40googlegroups.com.


Re: [ansible-project] Convert list to string in rendered Jinja template

2020-03-06 Thread Shifa Shaikh
Thank you @Stefan, 

That solves the issue !!

On Friday, March 6, 2020 at 2:32:07 PM UTC+5:30, Stefan Hornburg (Racke) 
wrote:
>
> On 3/6/20 9:04 AM, Shifa Shaikh wrote: 
> > I have a variable files like below: 
> > 
> > | 
> >   layers: 
> > -name:APP 
> >   things: 
> > -cactus 
> > -lotus 
> > -jasmine 
> > -rose 
> >   bgcolor: 
> > -sky blue 
> > 
> > 
> > -name:WAS 
> >   things: 
> > -mango 
> > -apple 
> >   bgcolor: 
> > -yellow 
> > | 
> > 
> > 
> > Below is my jinja template file: 
> > | 
> > {%forlayer inlayers %} 
> >  
> >  
> >  
> > {% for item in layer.things %} 
> > {{ item }} 
> > {%endfor %} 
> >  
> >  
> > {%endfor %} 
> > | 
> > 
>
> Try the join filter {{ layer.bgcolor | join(' ') }}. It is fruitless to 
> apply the list 
> filter to a list :-). 
>
> Regards 
> Racke 
>
> > I run this with the below playbook: 
> > 
> > | 
> > --- 
> >   -name:Demonstratingvariables inJinja2Loops 
> > hosts:localhost 
> > connection:local 
> > vars_files: 
> >   -vars.yml 
> > gather_facts:no 
> > tasks: 
> >   -name:Createthe Jinja2based templateone 
> > 
> > template:src=./varloop_new.j2 dest=./output.txt 
> > | 
> > 
> > 
> > 
> > The output recieved has a problem.  
> > 
> > Output.txt: 
> > 
> > | 
> > -bash-4.2$ cat output.txt 
> >  
> >  
> >  
> > cactus 
> > lotus 
> > jasmine 
> > rose 
> >  
> >  
> >  
> >  
> >   
> > mango 
> > apple 
> >  
> >  
> > | 
> > 
> > 
> > It displays bgcolor="[u'sky blue']" instead of bgcolor="sky blue" 
> > 
> > How can I convert the list to a string in the jinja template. 
> > 
> > -- 
> > 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   ansible-project+unsubscr...@googlegroups.com >. 
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/ansible-project/10765862-e99b-44bf-bdb8-0db36c1fc49b%40googlegroups.com
>  
> > <
> https://groups.google.com/d/msgid/ansible-project/10765862-e99b-44bf-bdb8-0db36c1fc49b%40googlegroups.com?utm_medium=email_source=footer>.
>  
>
>
>
> -- 
> Ecommerce and Linux consulting + Perl and web application programming. 
> Debian and Sympa administration. Provisioning with 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/59bb4061-7544-4846-9855-fb291065a0e1%40googlegroups.com.


[ansible-project] How to incorporate if else statement in Jinja template.

2020-03-06 Thread Shifa Shaikh
Here is my variable file

  layers:
- name: APP
  things:
- cactus
- lotus
- jasmine
- rose


- name: WAS
  things:
- mango
- apple



Below is my jinja template file:
{% for layer in layers %}


 
{% for item in layer.things %}

{{ item }}

{% endfor %}


{% endfor %}


My requirement is to put an if else condition where if any file err*txt is 
present under {{ item }} folder like below 

if `ls {{ playbook_dir }}/{{ item }}/err*.txt | head -1` returns true / 
records then the template evaluates to
{{ item }}
else
{{ item }}

How do i  put the if /else condition in the jinja template ?

-- 
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/09aeda5f-5e30-4b6c-b047-eda3c4c5de8b%40googlegroups.com.


Re: [ansible-project] How to incorporate if else statement in Jinja template.

2020-03-06 Thread Shifa Shaikh
Jean hi,

I incorporated the if statement from my previous post in my original Jinja
template after the second 'for loop' in my original post.

Once the if condition is removed the error does not show anymore.

On Fri, 6 Mar, 2020, 4:33 pm Jean-Yves LENHOF, 
wrote:

> Hi,
>
> Your error is about a for loop, but your template included in your email
> doesn't have this loop.
>
> Looks like you didn't give us the good one
>
> Regards,
>
> JYL
>
>
> Le 06/03/2020 à 11:52, Shifa Shaikh a écrit :
>
> Vladimir Hi,
>
> I tried
>
> {% if {{ playbook_dir }}/{{ item }}/bad*.txt | exists %}
>
>
> {{ item }}
>
>
>
> {% else %}
>
>
> {{ item }}
>
>
>
> {% endif %}
>
>
> But I get this error:
>
> TASK [Create the Jinja2 based template]
> *
> fatal: [localhost]: FAILED! => {"changed": false, "msg": "AnsibleError:
> template error while templating string: expected token ':', got '}'.
> String: {% for layer in layers %}\n
>
>
>
>
> On Friday, March 6, 2020 at 3:36:04 PM UTC+5:30, Vladimir Botka wrote:
>>
>> On Fri, 6 Mar 2020 01:59:00 -0800 (PST)
>> Shifa Shaikh  wrote:
>>
>> > How do i  put the if /else condition in the jinja template ?
>>
>> See "if"
>> https://jinja.palletsprojects.com/en/2.11.x/templates/#if
>>
>
>> --
> 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/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com?utm_medium=email_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/44bc6389-53a2-31d9-62a4-25897191e902%40lenhof.eu.org
> <https://groups.google.com/d/msgid/ansible-project/44bc6389-53a2-31d9-62a4-25897191e902%40lenhof.eu.org?utm_medium=email_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/CAJtox0%3D1A%3DFE%3DbDc2Rpdf8bSevF8d3hOWBkebCmNfWx8EzV1Og%40mail.gmail.com.


Re: [ansible-project] How to incorporate if else statement in Jinja template.

2020-03-06 Thread Shifa Shaikh
@Stefan I wish to check if the file bad*.txt exists on the path. Based on
the if condition I wish to template different  output.

On Fri, 6 Mar, 2020, 5:34 pm Stefan Hornburg (Racke), 
wrote:

> On 3/6/20 12:52 PM, Shifa Shaikh wrote:
> > @Stefan I tried you suggestion of not using the curly braces and it
> helped resolve the error. But now i get a new error.
> >
> > |
> > {%ifplaybook_dir +'/'+item +'/'+'bad*.txt'|exists %}
> > |
>
>
> There is no filter named 'exists'. Please explain what you want to achieve
> with this template.
>
> Regards
>  Racke
>
> >
> > TASK [Create the Jinja2 based template]
> >
> *
> > fatal: [localhost]: FAILED! => {"changed": false, "msg": "AnsibleError:
> template error while templating string: no
> > filter named 'exists'.
> >
> > Looks like the issue is with "exists" filter.
> >
> > On Friday, March 6, 2020 at 5:13:26 PM UTC+5:30, Stefan Hornburg (Racke)
> wrote:
> >
> > On 3/6/20 11:52 AM, Shifa Shaikh wrote:
> > > Vladimir Hi,
> > >
> > > I tried
> > >
> > > |
> > > {%if{{playbook_dir }}/{{item }}/bad*.txt |exists %}
> > >
> >
> > Don't use the curly braces inside the {%if ... } condition:
> >
> > {% if playbook_dir + '/' + item + '/' + 'bad*.txt' | exists %}
> >
> > Regards
> >   Racke
> >
> > >
> > > {{item }}
> > >
> > >
> > >
> > > {%else%}
> > >
> > >
> > > {{item }}
> > >
> > >
> > >
> > > {%endif %}
> > >
> > > |
> > >
> > > But I get this error:
> > >
> > > |
> > > TASK [Createthe Jinja2based
> > >
> >
>  
> template]*********
> >
> > > fatal:[localhost]:FAILED!=>{"changed":false,"msg":"AnsibleError:
> template error while templating string: expected
> > token
> > > ':', got '}'. String: {% for layer in layers %}\n
> > > |
> > >
> > >
> > >
> > >
> > > On Friday, March 6, 2020 at 3:36:04 PM UTC+5:30, Vladimir Botka
> wrote:
> > >
> > > On Fri, 6 Mar 2020 01:59:00 -0800 (PST)
> > > Shifa Shaikh > wrote:
> > >
> > > > How do i  put the if /else condition in the jinja template ?
> > >
> > > See "if"
> > > https://jinja.palletsprojects.com/en/2.11.x/templates/#if
> > <https://jinja.palletsprojects.com/en/2.11.x/templates/#if>
> > <https://jinja.palletsprojects.com/en/2.11.x/templates/#if <
> https://jinja.palletsprojects.com/en/2.11.x/templates/#if>>
> > >
> > >
> > > --
> > > 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   ansible-project+unsubscr...@googlegroups.com >.
> > > To view this discussion on the web visit
> > >
> https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com
> > <
> https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com
> >
> > >
> > <
> https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com?utm_medium=email_source=footer
> > <
> https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com?utm_medium=email_source=footer
> >>.
> >
> >
> >
> > --
> > Ecommerce and Linux consulting + Perl and web application
> programming.
> > Debian and Sympa administration. Provisioning with 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+u

Re: [ansible-project] How to incorporate if else statement in Jinja template.

2020-03-06 Thread Shifa Shaikh
Vladimir Hi, 

I tried 

{% if {{ playbook_dir }}/{{ item }}/bad*.txt | exists %}


{{ item }}



{% else %}


{{ item }}



{% endif %}


But I get this error:

TASK [Create the Jinja2 based template] 
*
fatal: [localhost]: FAILED! => {"changed": false, "msg": "AnsibleError: 
template error while templating string: expected token ':', got '}'. 
String: {% for layer in layers %}\n




On Friday, March 6, 2020 at 3:36:04 PM UTC+5:30, Vladimir Botka wrote:
>
> On Fri, 6 Mar 2020 01:59:00 -0800 (PST) 
> Shifa Shaikh > wrote: 
>
> > How do i  put the if /else condition in the jinja template ? 
>
> See "if" 
> https://jinja.palletsprojects.com/en/2.11.x/templates/#if 
>

>

-- 
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/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com.


Re: [ansible-project] How to incorporate if else statement in Jinja template.

2020-03-06 Thread Shifa Shaikh
@Stefan sorry but I could not understand your statement. 

Are you asking me to move the if statement out of the jinja template ?

Below is the complete jinja template with the if statement that errors. I'm 
able to populate all the values correctly and the playbook works fine when 
the if statement is removed from the jinja template. 

{% for layer in layers %}


 
{% for item in layer.things %}

{% if {{ playbook_dir }}/{{ item }}/bad*.txt | exists %}
{{ item }}

{% else %}
{{ item }}

{% endif %}

{% endfor %}


{% endfor %}

On Friday, March 6, 2020 at 5:08:37 PM UTC+5:30, Stefan Hornburg (Racke) 
wrote:
>
> On 3/6/20 12:02 PM, Jean-Yves LENHOF wrote: 
> > Hi, 
> > 
> > Your error is about a for loop, but your template included in your email 
> doesn't have this loop. 
>
> The loop could be applied to the task, in that case you can use {{ item }} 
> in the template on its own. 
>
> Regards 
>  Racke 
>
> > 
> > Looks like you didn't give us the good one 
> > 
> > Regards, 
> > 
> > JYL 
> > 
> > 
> > Le 06/03/2020 à 11:52, Shifa Shaikh a écrit : 
> >> Vladimir Hi,  
> >> 
> >> I tried  
> >> 
> >> | 
> >> {%if{{playbook_dir }}/{{item }}/bad*.txt |exists %} 
> >> 
> >> 
> >> {{item }} 
> >> 
> >> 
> >> 
> >> {%else%} 
> >> 
> >> 
> >> {{item }} 
> >> 
> >> 
> >> 
> >> {%endif %} 
> >> 
> >> | 
> >> 
> >> But I get this error: 
> >> 
> >> | 
> >> TASK [Createthe Jinja2based 
> >> 
> template]*
>  
>
> >> fatal:[localhost]:FAILED!=>{"changed":false,"msg":"AnsibleError: 
> template error while templating string: expected 
> >> token ':', got '}'. String: {% for layer in layers %}\n 
> >> | 
> >> 
> >> 
> >> 
> >> 
> >> On Friday, March 6, 2020 at 3:36:04 PM UTC+5:30, Vladimir Botka wrote: 
> >> 
> >> On Fri, 6 Mar 2020 01:59:00 -0800 (PST) 
> >> Shifa Shaikh > wrote: 
> >> 
> >> > How do i  put the if /else condition in the jinja template ? 
> >> 
> >> See "if" 
> >> https://jinja.palletsprojects.com/en/2.11.x/templates/#if <
> https://jinja.palletsprojects.com/en/2.11.x/templates/#if> 
> >> 
> >> 
> >> -- 
> >> 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   ansible-project+unsubscr...@googlegroups.com >. 
> >> To view this discussion on the web visit 
> >> 
> https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com
>  
> >> <
> https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com?utm_medium=email_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...@googlegroups.com   ansible-project+unsubscr...@googlegroups.com >. 
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/ansible-project/44bc6389-53a2-31d9-62a4-25897191e902%40lenhof.eu.org
>  
> > <
> https://groups.google.com/d/msgid/ansible-project/44bc6389-53a2-31d9-62a4-25897191e902%40lenhof.eu.org?utm_medium=email_source=footer>.
>  
>
>
>
> -- 
> Ecommerce and Linux consulting + Perl and web application programming. 
> Debian and Sympa administration. Provisioning with 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/fc1f3a81-c882-4b57-9644-8341ac95500c%40googlegroups.com.


Re: [ansible-project] How to incorporate if else statement in Jinja template.

2020-03-06 Thread Shifa Shaikh
If I remove the of statement the error goes away.

I can confirm i'm using the same Jinja template as the output error shared.

On Fri, 6 Mar, 2020, 4:33 pm Jean-Yves LENHOF, 
wrote:

> Hi,
>
> Your error is about a for loop, but your template included in your email
> doesn't have this loop.
>
> Looks like you didn't give us the good one
>
> Regards,
>
> JYL
>
>
> Le 06/03/2020 à 11:52, Shifa Shaikh a écrit :
>
> Vladimir Hi,
>
> I tried
>
> {% if {{ playbook_dir }}/{{ item }}/bad*.txt | exists %}
>
>
> {{ item }}
>
>
>
> {% else %}
>
>
> {{ item }}
>
>
>
> {% endif %}
>
>
> But I get this error:
>
> TASK [Create the Jinja2 based template]
> *
> fatal: [localhost]: FAILED! => {"changed": false, "msg": "AnsibleError:
> template error while templating string: expected token ':', got '}'.
> String: {% for layer in layers %}\n
>
>
>
>
> On Friday, March 6, 2020 at 3:36:04 PM UTC+5:30, Vladimir Botka wrote:
>>
>> On Fri, 6 Mar 2020 01:59:00 -0800 (PST)
>> Shifa Shaikh  wrote:
>>
>> > How do i  put the if /else condition in the jinja template ?
>>
>> See "if"
>> https://jinja.palletsprojects.com/en/2.11.x/templates/#if
>>
>
>> --
> 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/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com?utm_medium=email_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/44bc6389-53a2-31d9-62a4-25897191e902%40lenhof.eu.org
> <https://groups.google.com/d/msgid/ansible-project/44bc6389-53a2-31d9-62a4-25897191e902%40lenhof.eu.org?utm_medium=email_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/CAJtox0mLEi3K%3DA%3DP6J8B8EUnm8iz%2B%3DPYUBkJ-5R5tJF%2ByNheeg%40mail.gmail.com.


Re: [ansible-project] How to incorporate if else statement in Jinja template.

2020-03-06 Thread Shifa Shaikh
@Stefan I tried you suggestion of not using the curly braces and it helped 
resolve the error. But now i get a new error.

{% if playbook_dir + '/' + item + '/' + 'bad*.txt' | exists %}


TASK [Create the Jinja2 based template] 
*
fatal: [localhost]: FAILED! => {"changed": false, "msg": "AnsibleError: 
template error while templating string: no filter named 'exists'. 

Looks like the issue is with "exists" filter.

On Friday, March 6, 2020 at 5:13:26 PM UTC+5:30, Stefan Hornburg (Racke) 
wrote:
>
> On 3/6/20 11:52 AM, Shifa Shaikh wrote: 
> > Vladimir Hi,  
> > 
> > I tried  
> > 
> > | 
> > {%if{{playbook_dir }}/{{item }}/bad*.txt |exists %} 
> > 
>
> Don't use the curly braces inside the {%if ... } condition: 
>
> {% if playbook_dir + '/' + item + '/' + 'bad*.txt' | exists %} 
>
> Regards 
>   Racke 
>
> > 
> > {{item }} 
> > 
> > 
> > 
> > {%else%} 
> > 
> > 
> > {{item }} 
> > 
> > 
> > 
> > {%endif %} 
> > 
> > | 
> > 
> > But I get this error: 
> > 
> > | 
> > TASK [Createthe Jinja2based 
> > 
> template]*
>  
>
> > fatal:[localhost]:FAILED!=>{"changed":false,"msg":"AnsibleError: 
> template error while templating string: expected token 
> > ':', got '}'. String: {% for layer in layers %}\n 
> > | 
> > 
> > 
> > 
> > 
> > On Friday, March 6, 2020 at 3:36:04 PM UTC+5:30, Vladimir Botka wrote: 
> > 
> > On Fri, 6 Mar 2020 01:59:00 -0800 (PST) 
> > Shifa Shaikh > wrote: 
> > 
> > > How do i  put the if /else condition in the jinja template ? 
> > 
> > See "if" 
> > https://jinja.palletsprojects.com/en/2.11.x/templates/#if <
> https://jinja.palletsprojects.com/en/2.11.x/templates/#if> 
> > 
> > 
> > -- 
> > 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   ansible-project+unsubscr...@googlegroups.com >. 
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com
>  
> > <
> https://groups.google.com/d/msgid/ansible-project/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com?utm_medium=email_source=footer>.
>  
>
>
>
> -- 
> Ecommerce and Linux consulting + Perl and web application programming. 
> Debian and Sympa administration. Provisioning with 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/d22c2c58-3d3c-4cb6-8119-662a1a2e52ea%40googlegroups.com.


Re: [ansible-project] How to incorporate if else statement in Jinja template.

2020-03-06 Thread Shifa Shaikh
I know how to lookup a file using fileglob in Ansible but not sure how to
inside a Jinja template.

On Fri, 6 Mar, 2020, 5:55 pm Stefan Hornburg (Racke), 
wrote:

> On 3/6/20 1:12 PM, Shifa Shaikh wrote:
> > @Stefan I wish to check if the file bad*.txt exists on the path. Based
> on the if condition I wish to template different
> >  output.
>
> I assume that you are checking for file names matching bad*.txt. In that
> case you can use the fileglob lookup:
>
> https://docs.ansible.com/ansible/latest/plugins/lookup/fileglob.html
>
> Regards
>   Racke
>
> >
> > On Fri, 6 Mar, 2020, 5:34 pm Stefan Hornburg (Racke),  <mailto:ra...@linuxia.de>> wrote:
> >
> > On 3/6/20 12:52 PM, Shifa Shaikh wrote:
> > > @Stefan I tried you suggestion of not using the curly braces and
> it helped resolve the error. But now i get a new
> > error.
> > >
> > > |
> > > {%ifplaybook_dir +'/'+item +'/'+'bad*.txt'|exists %}
> > > |
> >
> >
> > There is no filter named 'exists'. Please explain what you want to
> achieve with this template.
> >
> > Regards
> >  Racke
> >
> > >
> > > TASK [Create the Jinja2 based template]
> > >
> *
> > > fatal: [localhost]: FAILED! => {"changed": false, "msg":
> "AnsibleError: template error while templating string: no
> > > filter named 'exists'.
> > >
> > > Looks like the issue is with "exists" filter.
> > >
> > > On Friday, March 6, 2020 at 5:13:26 PM UTC+5:30, Stefan Hornburg
> (Racke) wrote:
> > >
> > > On 3/6/20 11:52 AM, Shifa Shaikh wrote:
> > > > Vladimir Hi,
> > > >
> > > > I tried
> > > >
> > > > |
> > > > {%if{{playbook_dir }}/{{item }}/bad*.txt |exists %}
> > > >
> > >
> > > Don't use the curly braces inside the {%if ... } condition:
> > >
> > > {% if playbook_dir + '/' + item + '/' + 'bad*.txt' | exists %}
> > >
> > > Regards
> > >   Racke
> > >
> > > >
> > > > {{item }}
> > > >
> > > >
> > > >
> > > > {%else%}
> > > >
> > > >
> > > > {{item }}
> > > >
> > > >
> > > >
> > > > {%endif %}
> > > >
> > > > |
> > > >
> > > > But I get this error:
> > > >
> > > > |
> > >     > TASK [Createthe Jinja2based
> > > >
> > >
> >
>   
> template]*
> > >
> > > >
> fatal:[localhost]:FAILED!=>{"changed":false,"msg":"AnsibleError: template
> error while templating string:
> > expected
> > > token
> > > > ':', got '}'. String: {% for layer in layers %}\n
> > > > |
> > > >
> > > >
> > > >
> > > >
> > > > On Friday, March 6, 2020 at 3:36:04 PM UTC+5:30, Vladimir
> Botka wrote:
> > > >
> > > > On Fri, 6 Mar 2020 01:59:00 -0800 (PST)
> > > > Shifa Shaikh  shif...@gmail.com> > wrote:
> > > >
> > > > > How do i  put the if /else condition in the jinja
> template ?
> > > >
> > > > See "if"
> > > >
> https://jinja.palletsprojects.com/en/2.11.x/templates/#if
> > > <https://jinja.palletsprojects.com/en/2.11.x/templates/#if>
> > > <https://jinja.palletsprojects.com/en/2.11.x/templates/#if
> > <https://jinja.palletsprojects.com/en/2.11.x/templates/#if>>
> > > >
> > > >
> > > > --
> > > > You received this message because you are subscribed to the
> Google Groups "Ansible Project" g

[ansible-project] Unable to read variable in a loop using include_vars.

2020-03-02 Thread Shifa Shaikh
Below is my playbook which loads variables and passes it to ls command on 
remote hosts.

   - name: Load repository 
 include_vars:
   file="{{ playbook_dir }}/vars/listing.yml"
   name=user1


   - set_fact:
   allinonecmd: "{{ allinonecmd | default('') + 'ls -ltr ' + item.path 
+ ' '}}"   
 loop: "{{ user1[inventory_hostname] }}"  

   - name: Get stat
 shell: "ssh {{ USER }}@{{ inventory_hostname }} '{{ allinonecmd }}' 
>/web/htdocs/{{ item.ccode }}{{ item.ipseg }}.html"
 delegate_to: localhost
 loop: "{{ user1[inventory_hostname] }}"

 
below is my listing.yml
10.0.0.15:
  - name: SCRIPT
path: /tmp/scripts
ccode: GRM-APP-
ipseg: "0.15"
  - name: MOC
path: /tmp/moc
  - name: EXE
path: /tmp/exe
  - name: MTR
path: /tmp/mtr


This worked fine without ccode and ipseg entries in the listing.yml. I have 
multiple entries for path which i loop over and construct the allinonecmd 
string but the ccode is just needed once.

I get this error with a single entry of ccode in listing.yml 

fatal: [10.0.0.15]: FAILED! => {
"msg": "The task includes an option with an undefined variable. The 
error was: 'dict object' has no attribute 'ccode'


For my existing playbook to work i have to specify ccode and ipseg under 
each entry like below which works but looks ugly. It should be specified 
just one time and the playbook should work.

10.0.0.15:
  - name: SCRIPT
path: /tmp/scripts
ccode: GRM-APP-
ipseg: "0.15"
  - name: MOC
path: /tmp/moc
ccode: GRM-APP-
ipseg: "0.15"
  - name: EXE
path: /tmp/exe
ccode: GRM-APP-
ipseg: "0.15"
  - name: MTR
path: /tmp/mtr
ccode: GRM-APP-
ipseg: "0.15"


Can you please suggest a clean way to get this to work  ?

-- 
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/2d8d2651-2ffc-4f36-b565-0df941508cbb%40googlegroups.com.


Re: [ansible-project] Unable to read variable in a loop using include_vars.

2020-03-03 Thread Shifa Shaikh
I need to get the output of ls command from list of remote ips and under
each ip there is are different directories. The output of ls command needs
to be saved in a file and the name of the file should be the value of ccode
variable under the variable.

Thus my variable file has ip listed. Under each ip is the list of
directories with name and path variables and finally the entire output of
all the ls commands on all the directories for that ip is stored in a file
with ccode variable.

Hope the requirement is clear now.

On Tue, 3 Mar, 2020, 2:55 pm Dick Visser,  wrote:

> I meant HIGH level.
> You are using ansible to achieve something - what is that?
>
> On Tue, 3 Mar 2020 at 09:20, Shifa Shaikh  wrote:
> >
> > Under an ip I want a variable ccode which will be global variable for
> that ip.
> >
> > I also want variable name & path which will have multiple entries.
> >
> > How can I read both single global and multiple variables name and path
> under a given IP ?
> >
> > On Tue, 3 Mar, 2020, 1:26 pm Dick Visser,  wrote:
> >>
> >> Can you tell what is the big picture? What task is this intended for?
> >>
> >> On Tue, 3 Mar 2020 at 05:43, Shifa Shaikh  wrote:
> >>>
> >>> Below is my playbook which loads variables and passes it to ls command
> on remote hosts.
> >>>
> >>>- name: Load repository
> >>>  include_vars:
> >>>file="{{ playbook_dir }}/vars/listing.yml"
> >>>name=user1
> >>>
> >>>
> >>>- set_fact:
> >>>allinonecmd: "{{ allinonecmd | default('') + 'ls -ltr ' +
> item.path + ' '}}"
> >>>  loop: "{{ user1[inventory_hostname] }}"
> >>>
> >>>- name: Get stat
> >>>  shell: "ssh {{ USER }}@{{ inventory_hostname }} '{{ allinonecmd
> }}' >/web/htdocs/{{ item.ccode }}{{ item.ipseg }}.html"
> >>>  delegate_to: localhost
> >>>  loop: "{{ user1[inventory_hostname] }}"
> >>>
> >>>
> >>> below is my listing.yml
> >>> 10.0.0.15:
> >>>   - name: SCRIPT
> >>> path: /tmp/scripts
> >>> ccode: GRM-APP-
> >>> ipseg: "0.15"
> >>>   - name: MOC
> >>> path: /tmp/moc
> >>>   - name: EXE
> >>> path: /tmp/exe
> >>>   - name: MTR
> >>> path: /tmp/mtr
> >>>
> >>>
> >>> This worked fine without ccode and ipseg entries in the listing.yml. I
> have multiple entries for path which i loop over and construct the
> allinonecmd string but the ccode is just needed once.
> >>>
> >>> I get this error with a single entry of ccode in listing.yml
> >>>
> >>> fatal: [10.0.0.15]: FAILED! => {
> >>> "msg": "The task includes an option with an undefined variable.
> The error was: 'dict object' has no attribute 'ccode'
> >>>
> >>>
> >>> For my existing playbook to work i have to specify ccode and ipseg
> under each entry like below which works but looks ugly. It should be
> specified just one time and the playbook should work.
> >>>
> >>> 10.0.0.15:
> >>>   - name: SCRIPT
> >>> path: /tmp/scripts
> >>> ccode: GRM-APP-
> >>> ipseg: "0.15"
> >>>   - name: MOC
> >>> path: /tmp/moc
> >>> ccode: GRM-APP-
> >>> ipseg: "0.15"
> >>>   - name: EXE
> >>> path: /tmp/exe
> >>> ccode: GRM-APP-
> >>> ipseg: "0.15"
> >>>   - name: MTR
> >>> path: /tmp/mtr
> >>> ccode: GRM-APP-
> >>> ipseg: "0.15"
> >>>
> >>>
> >>> Can you please suggest a clean way to get this to work  ?
> >>>
> >>> --
> >>> 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/2d8d2651-2ffc-4f36-b565-0df941508cbb%40googlegroups.com
> .
> >>
> >> --
> >> Sent from a mobile device - please excuse the brevity, spelling and
> punctuation.
> >>
> >> --
> >> You rec

Re: [ansible-project] Unable to read variable in a loop using include_vars.

2020-03-03 Thread Shifa Shaikh
The reason for grabbing the ls output across servers is for audit purpose.
The audit team randomly checks for this output with the server.



On Tue, 3 Mar, 2020, 3:29 pm Stefan Hornburg (Racke), 
wrote:

> On 3/3/20 10:53 AM, Shifa Shaikh wrote:
> > I need to get the output of ls command from list of remote ips and under
> each ip there is are different directories. The
> > output of ls command needs to be saved in a file and the name of the
> file should be the value of ccode variable under
> > the variable.
> >
> > Thus my variable file has ip listed. Under each ip is the list of
> directories with name and path variables and finally
> > the entire output of all the ls commands on all the directories for that
> ip is stored in a file with ccode variable.
> >
> > Hope the requirement is clear now.
>
> It is still unclear what you are going to do with the ls output. Also I
> would recommend to use the find module instead
> of ls on the target.
>
> Regards
>Racke
>
> >
> > On Tue, 3 Mar, 2020, 2:55 pm Dick Visser,  <mailto:dick.vis...@geant.org>> wrote:
> >
> > I meant HIGH level.
> > You are using ansible to achieve something - what is that?
> >
> > On Tue, 3 Mar 2020 at 09:20, Shifa Shaikh  <mailto:shifa...@gmail.com>> wrote:
> > >
> > > Under an ip I want a variable ccode which will be global variable
> for that ip.
> > >
> > > I also want variable name & path which will have multiple entries.
> > >
> > > How can I read both single global and multiple variables name and
> path under a given IP ?
> > >
> > > On Tue, 3 Mar, 2020, 1:26 pm Dick Visser,  <mailto:dick.vis...@geant.org>> wrote:
> > >>
> > >> Can you tell what is the big picture? What task is this intended
> for?
> > >>
> > >> On Tue, 3 Mar 2020 at 05:43, Shifa Shaikh  <mailto:shifa...@gmail.com>> wrote:
> > >>>
> > >>> Below is my playbook which loads variables and passes it to ls
> command on remote hosts.
> > >>>
> > >>>- name: Load repository
> > >>>  include_vars:
> > >>>file="{{ playbook_dir }}/vars/listing.yml"
> > >>>name=user1
> > >>>
> > >>>
> > >>>- set_fact:
> > >>>allinonecmd: "{{ allinonecmd | default('') + 'ls -ltr ' +
> item.path + ' '}}"
> > >>>  loop: "{{ user1[inventory_hostname] }}"
> > >>>
> > >>>- name: Get stat
> > >>>  shell: "ssh {{ USER }}@{{ inventory_hostname }} '{{
> allinonecmd }}' >/web/htdocs/{{ item.ccode }}{{
> > item.ipseg }}.html"
> > >>>  delegate_to: localhost
> > >>>  loop: "{{ user1[inventory_hostname] }}"
> > >>>
> > >>>
> > >>> below is my listing.yml
> > >>> 10.0.0.15 <http://10.0.0.15>:
> > >>>   - name: SCRIPT
> > >>> path: /tmp/scripts
> > >>> ccode: GRM-APP-
> > >>> ipseg: "0.15"
> > >>>   - name: MOC
> > >>> path: /tmp/moc
> > >>>   - name: EXE
> > >>> path: /tmp/exe
> > >>>   - name: MTR
> > >>> path: /tmp/mtr
> > >>>
> > >>>
> > >>> This worked fine without ccode and ipseg entries in the
> listing.yml. I have multiple entries for path which i
> > loop over and construct the allinonecmd string but the ccode is just
> needed once.
> > >>>
> > >>> I get this error with a single entry of ccode in listing.yml
> > >>>
> > >>> fatal: [10.0.0.15]: FAILED! => {
> > >>> "msg": "The task includes an option with an undefined
> variable. The error was: 'dict object' has no
> > attribute 'ccode'
> > >>>
> > >>>
> > >>> For my existing playbook to work i have to specify ccode and
> ipseg under each entry like below which works but
> > looks ugly. It should be specified just one time and the playbook
> should work.
> > >>>
> > >>> 10.0.0.15 <http://10.0.0.15>:
> > >>> 

Re: [ansible-project] Unable to read variable in a loop using include_vars.

2020-03-03 Thread Shifa Shaikh
The reason for grabbing the ls output across servers is for audit purpose. 
The output of ls is send as reports and audit team uses the ls output 
reports to do random checks on the server.

On Tuesday, March 3, 2020 at 3:29:01 PM UTC+5:30, Stefan Hornburg (Racke) 
wrote:
>
> On 3/3/20 10:53 AM, Shifa Shaikh wrote: 
> > I need to get the output of ls command from list of remote ips and under 
> each ip there is are different directories. The 
> > output of ls command needs to be saved in a file and the name of the 
> file should be the value of ccode variable under 
> > the variable. 
> > 
> > Thus my variable file has ip listed. Under each ip is the list of 
> directories with name and path variables and finally 
> > the entire output of all the ls commands on all the directories for that 
> ip is stored in a file with ccode variable. 
> > 
> > Hope the requirement is clear now. 
>
> It is still unclear what you are going to do with the ls output. Also I 
> would recommend to use the find module instead 
> of ls on the target. 
>
> Regards 
>Racke 
>
> > 
> > On Tue, 3 Mar, 2020, 2:55 pm Dick Visser,   <mailto:dick@geant.org >> wrote: 
> > 
> > I meant HIGH level. 
> > You are using ansible to achieve something - what is that? 
> > 
> > On Tue, 3 Mar 2020 at 09:20, Shifa Shaikh   <mailto:shif...@gmail.com >> wrote: 
> > > 
> > > Under an ip I want a variable ccode which will be global variable 
> for that ip. 
> > > 
> > > I also want variable name & path which will have multiple entries. 
> > > 
> > > How can I read both single global and multiple variables name and 
> path under a given IP ? 
> > > 
> > > On Tue, 3 Mar, 2020, 1:26 pm Dick Visser,   <mailto:dick@geant.org >> wrote: 
> > >> 
> > >> Can you tell what is the big picture? What task is this intended 
> for? 
> > >> 
> > >> On Tue, 3 Mar 2020 at 05:43, Shifa Shaikh   <mailto:shif...@gmail.com >> wrote: 
> > >>> 
> > >>> Below is my playbook which loads variables and passes it to ls 
> command on remote hosts. 
> > >>> 
> > >>>- name: Load repository 
> > >>>  include_vars: 
> > >>>file="{{ playbook_dir }}/vars/listing.yml" 
> > >>>name=user1 
> > >>> 
> > >>> 
> > >>>- set_fact: 
> > >>>allinonecmd: "{{ allinonecmd | default('') + 'ls -ltr ' + 
> item.path + ' '}}" 
> > >>>  loop: "{{ user1[inventory_hostname] }}" 
> > >>> 
> > >>>- name: Get stat 
> > >>>  shell: "ssh {{ USER }}@{{ inventory_hostname }} '{{ 
> allinonecmd }}' >/web/htdocs/{{ item.ccode }}{{ 
> > item.ipseg }}.html" 
> > >>>  delegate_to: localhost 
> > >>>  loop: "{{ user1[inventory_hostname] }}" 
> > >>> 
> > >>> 
> > >>> below is my listing.yml 
> > >>> 10.0.0.15 <http://10.0.0.15>: 
> > >>>   - name: SCRIPT 
> > >>> path: /tmp/scripts 
> > >>> ccode: GRM-APP- 
> > >>> ipseg: "0.15" 
> > >>>   - name: MOC 
> > >>> path: /tmp/moc 
> > >>>   - name: EXE 
> > >>> path: /tmp/exe 
> > >>>   - name: MTR 
> > >>> path: /tmp/mtr 
> > >>> 
> > >>> 
> > >>> This worked fine without ccode and ipseg entries in the 
> listing.yml. I have multiple entries for path which i 
> > loop over and construct the allinonecmd string but the ccode is just 
> needed once. 
> > >>> 
> > >>> I get this error with a single entry of ccode in listing.yml 
> > >>> 
> > >>> fatal: [10.0.0.15]: FAILED! => { 
> > >>> "msg": "The task includes an option with an undefined 
> variable. The error was: 'dict object' has no 
> > attribute 'ccode' 
> > >>> 
> > >>> 
> > >>> For my existing playbook to work i have to specify ccode and 
> ipseg under each entry like below which works but 
> > looks ugly. It should be specified just

Re: [ansible-project] Unable to read variable in a loop using include_vars.

2020-03-03 Thread Shifa Shaikh
Under an ip I want a variable ccode which will be global variable for that
ip.

I also want variable name & path which will have multiple entries.

How can I read both single global and multiple variables name and path
under a given IP ?

On Tue, 3 Mar, 2020, 1:26 pm Dick Visser,  wrote:

> Can you tell what is the big picture? What task is this intended for?
>
> On Tue, 3 Mar 2020 at 05:43, Shifa Shaikh  wrote:
>
>> Below is my playbook which loads variables and passes it to ls command on
>> remote hosts.
>>
>>- name: Load repository
>>  include_vars:
>>file="{{ playbook_dir }}/vars/listing.yml"
>>name=user1
>>
>>
>>- set_fact:
>>allinonecmd: "{{ allinonecmd | default('') + 'ls -ltr ' +
>> item.path + ' '}}"
>>  loop: "{{ user1[inventory_hostname] }}"
>>
>>- name: Get stat
>>  shell: "ssh {{ USER }}@{{ inventory_hostname }} '{{ allinonecmd }}'
>> >/web/htdocs/{{ item.ccode }}{{ item.ipseg }}.html"
>>  delegate_to: localhost
>>  loop: "{{ user1[inventory_hostname] }}"
>>
>>
>> below is my listing.yml
>> 10.0.0.15:
>>   - name: SCRIPT
>> path: /tmp/scripts
>> ccode: GRM-APP-
>> ipseg: "0.15"
>>   - name: MOC
>> path: /tmp/moc
>>   - name: EXE
>> path: /tmp/exe
>>   - name: MTR
>> path: /tmp/mtr
>>
>>
>> This worked fine without ccode and ipseg entries in the listing.yml. I
>> have multiple entries for path which i loop over and construct the
>> allinonecmd string but the ccode is just needed once.
>>
>> I get this error with a single entry of ccode in listing.yml
>>
>> fatal: [10.0.0.15]: FAILED! => {
>> "msg": "The task includes an option with an undefined variable. The
>> error was: 'dict object' has no attribute 'ccode'
>>
>>
>> For my existing playbook to work i have to specify ccode and ipseg under
>> each entry like below which works but looks ugly. It should be specified
>> just one time and the playbook should work.
>>
>> 10.0.0.15:
>>   - name: SCRIPT
>> path: /tmp/scripts
>> ccode: GRM-APP-
>> ipseg: "0.15"
>>   - name: MOC
>> path: /tmp/moc
>> ccode: GRM-APP-
>> ipseg: "0.15"
>>   - name: EXE
>> path: /tmp/exe
>> ccode: GRM-APP-
>> ipseg: "0.15"
>>   - name: MTR
>> path: /tmp/mtr
>> ccode: GRM-APP-
>> ipseg: "0.15"
>>
>>
>> Can you please suggest a clean way to get this to work  ?
>>
>> --
>> 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/2d8d2651-2ffc-4f36-b565-0df941508cbb%40googlegroups.com
>> <https://groups.google.com/d/msgid/ansible-project/2d8d2651-2ffc-4f36-b565-0df941508cbb%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
> --
> Sent from a mobile device - please excuse the brevity, spelling and
> punctuation.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAL8fbwPTUGXsFP0HV6pUvUJB_ssvOq_-V-8P9JALJ3urWMq46g%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CAL8fbwPTUGXsFP0HV6pUvUJB_ssvOq_-V-8P9JALJ3urWMq46g%40mail.gmail.com?utm_medium=email_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/CAJtox0kJy%3D1Cow5XFC10CSUwvF6Jfdn34Xm5sAnnNjDLh%2B5mgw%40mail.gmail.com.


[ansible-project] How do i loop over include_vars objects under a dictionary ?

2020-03-01 Thread Shifa Shaikh
I have a include_vars file with the below entries in listings.yml

---
10.9.9.42:
  - name: myapp
path: /app/myapp_war.ear/myapp.war
  - name: myapp JS
path: /app/myapp_war.ear/myapp.war/javascripts
10.9.9.43:
  - name: CVS
path: /app/CVS.ear/CVS.war/ui/js
  - name: CHK
path: /app/logs/tmp
  - name: SSO
path: /app/CVS.ear/CVS.war/WEB-INF


Output:

TASK [Load entire repository inventory] 
*
task path: /app/test.yml:57
ok: [10.9.9.42] => {
"ansible_facts": {
"10.9.9.42": [
{
"name": "myapp",
"path": "/app/myapp_war.ear/myapp.war"
},
{
"name": "myapp JS",
"path": "/app/myapp_war.ear/myapp.war/javascripts"
}
],
"10.9.9.43": [
{
"name": "CVS",
"path": "/app/CVS.ear/CVS.war/ui/js"
},
 {
"name": "CHK",
"path": "/app/logs/tmp"
},
{
"name": "SSO",
"path": "/app/CVS.ear/CVS.war/WEB-INF"
}
]
},
"ansible_included_var_files": [
"/app/vars/listing.yml"
],
"changed": false
}


TASK [debug] 

task path: /app/test.yml:62
fatal: [10.9.9.42]: FAILED! => {
"msg": "The task includes an option with an undefined variable. The 
error was: 'unicode object' has no attribute 'name'\n\nThe error appears to 
be in '/app/test.yml': line 62, column 6, 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"
}




Below is my playbook where i wish to read all the name and path under the 
inventory_hostname so if the inventory_hostname remote host is "10.9.9.42" 
all the names and path under it should be displayed.

  tasks:


   - name: Load entire repository inventory
 include_vars:
   file="{{ playbook_dir }}/vars/listing.yml"
name: user1


   - debug:
   msg: "Name {{ item.0.name }} on path{{ item.0.path }}"
 loop:
   - "{{ inventory_hostname }}"

   
Can you please suggest whats wrong with my playbook ?

-- 
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/3d0e239c-c74a-4753-a81b-df2601b82731%40googlegroups.com.


Re: [ansible-project] How do i loop over include_vars objects under a dictionary ?

2020-03-01 Thread Shifa Shaikh
@Vladimir this prints only the first name and path under the hostname. 

I wish to loop all name and path under the given host. 

On Monday, March 2, 2020 at 11:40:36 AM UTC+5:30, Vladimir Botka wrote:
>
> On Sun, 1 Mar 2020 21:37:42 -0800 (PST) 
> Shifa Shaikh > wrote: 
>
> > listings.yml 
> > 
> > --- 
> > 10.9.9.42: 
> >   - name: myapp 
> > path: /app/myapp_war.ear/myapp.war 
> >   - name: myapp JS 
> > path: /app/myapp_war.ear/myapp.war/javascripts 
> > 10.9.9.43: 
> >   - name: CVS 
> > path: /app/CVS.ear/CVS.war/ui/js 
> >   - name: CHK 
> > path: /app/logs/tmp 
> >   - name: SSO 
> > path: /app/CVS.ear/CVS.war/WEB-INF 
> > 
> > [...] 
> > 
> >   tasks: 
> >- name: Load entire repository inventory 
> >  include_vars: 
> >file="{{ playbook_dir }}/vars/listing.yml" 
> > name: user1 
> > 
> >- debug: 
> >msg: "Name {{ item.0.name }} on path{{ item.0.path }}" 
> >  loop: 
> >- "{{ inventory_hostname }}" 
>
> The variables from the file are assigned into the dictionary "user1". Fix 
> the 
> variables' references 
>
> - debug: 
> msg: "Name {{ user1[item].0.name }} on path {{ user1[item].0.path 
> }}" 
>   loop: 
> - "{{ inventory_hostname }}" 
>
> With single item the loop is not necessary 
>
> - debug: 
> msg: "Name {{ user1[inventory_hostname].0.name }} on 
>   path {{ user1[inventory_hostname].0.path }}" 
>
> HTH, 
> -vlado 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/2a93b4ce-6d1a-428f-8853-12555789dbfe%40googlegroups.com.


Re: [ansible-project] What is the best approach to creating a inlude_vars file for my requirement

2020-01-26 Thread Shifa Shaikh
Dick Hi, 

My requirement is not about configuring a webserver. 

It is to maintain a check on a set of files. If the file changes by 
checksum or permissions I wish to trigger an alert. 

Thus, my ansible will stat the file and then compare the checksum and mode 
that was previously stored in the include_vars file. 

If they match we are good else we will trigger an alert. 

Thus, I want to understand if my approach/format of storing mode and 
checksum information for all files on all servers good? if not please 
propose how should i design the include_vars files so I could read the 
checksum and mode of a file on a  particular IP. 

On Sunday, January 26, 2020 at 4:25:25 AM UTC+5:30, Dick Visser wrote:
>
> Hi 
>
> The information you've provided seems to contain several cases of 
> wheel reinvention. 
> Rather than helping you do that, please explain what you are REALLY 
> looking to achieve. 
> The file names in your example suggest: "configuring a web server". 
> In which case, a few template tasks and a handler might be all you need. 
>
> Dick 
>
>
> On Sat, 25 Jan 2020 at 00:10, Shifa Shaikh  > wrote: 
> > 
> > I use the stat module to read multiple files statistics from each remote 
> server. 
> > 
> > Thus, I'm able to get the file mode and checksum value of say 3 files on 
> host1 and 2 files on host2. 
> > 
> > I wish to know what is a good way to create/construct an include_vars 
> file so that I can easily read back each file's mode and checksum for any 
> given server? 
> > 
> > I thought of constructing a myvars.yaml as below: 
> > 
> > --- 
> > host1: 
> >name: /tmp/conf/httpd.conf 
> >checksum: 79783482382789273 
> >mode: 0744 
> >name: /tmp/conf/extra/httpd.conf 
> >checksum: 112312382789273 
> >mode: 0754 
> > 
> > 
> > 
> > host2: 
> > 
> >name: /tmp/conf/httpd.conf 
> >checksum: 89662ff9273 
> >mode: 0774 
> >name: /tmp/conf/extra/httpd.conf 
> >checksum: 82094810498 
> >mode: 0754 
> > 
> > 
> > I can construct the myvars.yaml as I like but the challenge is how can I 
> read the values of the individual file name on a given hots? 
> > 
> > Any suggestions for construct myvars.yaml differently and reading 
> individual file details in a playbook will be of great help. 
> > 
> > Thank you !! 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups "Ansible Project" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an email to ansible...@googlegroups.com . 
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/fd96dabf-6ed9-4924-84b5-d855d15f05ff%40googlegroups.com.
>  
>
>
>
>
> -- 
> Dick Visser 
> Trust & Identity Service Operations Manager 
> GÉANT 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/41899b75-4a2a-486d-a30c-5ddc798a7880%40googlegroups.com.


[ansible-project] What is the best approach to creating a inlude_vars file for my requirement

2020-01-24 Thread Shifa Shaikh
I use the stat module to read multiple files statistics from each remote 
server. 

Thus, I'm able to get the file mode and checksum value of say 3 files on 
host1 and 2 files on host2.

I wish to know what is a good way to create/construct an include_vars file 
so that I can easily read back each file's mode and checksum for any given 
server?

I thought of constructing a myvars.yaml as below:

---
host1:
   name: /tmp/conf/httpd.conf
   checksum: 79783482382789273
   mode: 0744
   name: /tmp/conf/extra/httpd.conf
   checksum: 112312382789273
   mode: 0754



host2:

   name: /tmp/conf/httpd.conf
   checksum: 89662ff9273
   mode: 0774
   name: /tmp/conf/extra/httpd.conf
   checksum: 82094810498
   mode: 0754


I can construct the myvars.yaml as I like but the challenge is how can I 
read the values of the individual file name on a given hots?

Any suggestions for construct myvars.yaml differently and reading 
individual file details in a playbook will be of great help. 

Thank you !!

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/fd96dabf-6ed9-4924-84b5-d855d15f05ff%40googlegroups.com.


[ansible-project] How to fix warning message conditional statements should not include jinja2 templating delimiters

2020-02-11 Thread Shifa Shaikh
How do I make changes to the below complex when condition without breaking 
the code in order to address the warning. 

 - debug: msg: "Hi"
 when: entrycurrdb.stdout.find("{{ 
hostvars['localhost']['BASEPATH_FINAL'] }}/{{ vars[(item | 
splitext)[1].split('.')[1] | default('exe')] }}/{{ item | basename }}") == -
1 and actualfile.stat.exists == True

Getting warning

Output:


TASK [shell] 
> ***
> [WARNING]: conditional statements should not include jinja2 templating
> delimiters such as {{ }} or {% %}. Found: entrycurrdb.stdout.find("{{
> hostvars['localhost']['BASEPATH_FINAL'] }}/{{ vars[(item |
> splitext)[1].split('.')[1] | default('exe')] }}/{{ item | basename }}") == 
> -1
> and actualfile.stat.exists == True
> changed: [10.0.0.16]


Kindly suggests. 

-- 
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/344ea14e-1b5a-4e37-874b-9de23fc4e90a%40googlegroups.com.


[ansible-project] How to fix warning message conditional statements should not include jinja2 templating delimiters

2020-02-11 Thread Shifa Shaikh
How do I make changes to the below complex when condition without breaking 
the code in order to address the warning. 

 - debug: msg: "Hi"
 when: entrycurrdb.stdout.find("{{ 
hostvars['localhost']['BASEPATH_FINAL'] }}/{{ vars[(item | 
splitext)[1].split('.')[1] | default('exe')] }}/{{ item | basename }}") == -
1 and actualfile.stat.exists == True

Getting warning

Output:


TASK [debug] 
> ***
> [WARNING]: conditional statements should not include jinja2 templating
> delimiters such as {{ }} or {% %}. Found: entrycurrdb.stdout.find("{{
> hostvars['localhost']['BASEPATH_FINAL'] }}/{{ vars[(item |
> splitext)[1].split('.')[1] | default('exe')] }}/{{ item | basename }}") == 
> -1
> and actualfile.stat.exists == True
> changed: [10.0.0.16]


Kindly suggests. 

-- 
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/40f2ed22-985b-4fe3-8fd1-b509f497551f%40googlegroups.com.


Re: [ansible-project] Unable to print regex registered variable in Ansible

2020-01-15 Thread Shifa Shaikh
Reading the contents of the file is not the challenge. I used both sllurp 
as well as cat and I can see the file contents in the debug. The error 
occurs when I regex for the desired string. 

- name: Slurp certificate entries
  slurp:
src: "{{ httpd_home }}/conf/httpd.conf"
  register: filecontent

- name: Find certificate entries
  set_fact:
input: "{{ filecontent['content'] | b64decode }}"

- debug:
msg: "{{ input }}"

- name: Regex String
  set_fact:
target: "{{ input | regex_replace('\\sSSLFile.*, '\\1') }}"


The regex task fails where we are assigning the set_fact "target" with the 
below error:

TASK [Regex String] ***
>
> *task path: /app/test.yml:908*The full traceback is:
> Traceback (most recent call last):
> File "/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py", 
> line 144, in run
> res = self._execute()
> File "/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py", 
> line 576, in _execute
> self._task.post_validate(templar=templar)
> File "/usr/lib/python2.7/site-packages/ansible/playbook/task.py", line 
> 268, in post_validate
> super(Task, self).post_validate(templar)
> File "/usr/lib/python2.7/site-packages/ansible/playbook/base.py", line 
> 384, in post_validate
> value = templar.template(getattr(self, name))
> File "/usr/lib/python2.7/site-packages/ansible/template/__init__.py", line 
> 584, in template
> disable_lookups=disable_lookups,
> File "/usr/lib/python2.7/site-packages/ansible/template/__init__.py", line 
> 539, in template
> disable_lookups=disable_lookups,
> File "/usr/lib/python2.7/site-packages/ansible/template/__init__.py", line 
> 773, in do_template
> data = _escape_backslashes(data, myenv)
> File "/usr/lib/python2.7/site-packages/ansible/template/__init__.py", line 
> 145, in _escape_backslashes
> for token in jinja_env.lex(d2):
> File "/usr/lib/python2.7/site-packages/jinja2/lexer.py", line 733, in 
> tokeniter
> name, filename)
> TemplateSyntaxError: unexpected char u'\\' at 51
> line 1 fatal: [10.9.9.11]: FAILED! => {
> "msg": "Unexpected failure during module execution.", 
> "stdout": ""
> }


On Wednesday, January 15, 2020 at 12:04:52 PM UTC+5:30, Jean-Yves LENHOF 
wrote:
>
> Hi,
>
> Perhaps you should better use slurp module to register the content of the 
> file and do some regexp to print what you want on it...
>
>
> https://docs.ansible.com/ansible/latest/modules/slurp_module.html#slurp-module
>
> Regards,
>
>
> Le 15/01/2020 à 06:34, Shifa Shaikh a écrit :
>
> I wish to search for all entries of string starting with "SSLFile" or 
> starting with "SSLFile" in a file(httpd.conf) and register 
> it to a variable and print all the matches found.  
>
> The string is found as evident from the output and the file is not 
> modified which is good; but I'm unable to print (debug) it. I get error as 
> I try to print. Below is my playbook: 
>
> - name: Find entries
>   lineinfile:
> path: "/tmp/httpd.conf"
> regexp: "\\sSSLFile.*"
> state: absent
>   check_mode: yes
>   changed_when: false
>   register: filedet
>
> - debug:
> msg: "{{ filedet }}"
>
> - debug:
> msg: "{{ item.split()[1] }}"
>   with_items:
> - "{{ filedet.stdout_lines }}"
>
> I get the below error when i run the playbook:
>
>
> ok: [10.9.9.11] => {
>> "backup": "", 
>> "changed": false, 
>> "diff": [
>> {
>> "after": "", 
>> "after_header": "/tmp/httpd.conf (content)", 
>> "before": "", 
>> "before_header": "/tmp/httpd.conf (content)"
>> }, 
>> {
>> "after_header": "/tmp/httpd.conf (file attributes)", 
>> "before_header": "/tmp/httpd.conf (file attributes)"
>> }
>> ], 
>> "found": 1, 
>> "invocation": {
>> "module_args": {
>> "attributes": null, 
>> "backrefs": false, 
>> "backup": false, 
>> "content": null, 
>> "create": false, 
>> "delimiter": null, 
>> "directory_mode": null, 
>> "firstmatch": false, 
>> "follow": false, 
>> "force": null, 
>> "group&

[ansible-project] How to print all matched strings using Ansible regex

2020-01-14 Thread Shifa Shaikh
I wish to match all lines that begin with SSLFile or SSLFile in 
a file httpd.conf on a remote server and store the matched found strings in 
a variable for use later in the playbook.

Below is what i did.

- name: Find entries 
  shell: "cat /tmp/httpd.conf"
  register: filecontent

- name: Debug filecontentvar
  debug:
msg: "{{ filecontent  }}"

- name: Find certificate entries
  set_fact:
target: "{{ filecontent.stdout | regex_replace('\\sSSLFile.*, 
'\\1') }}"

Using debug verbose I was able to confirm that the filecontent variable 
gets the contents of the httpd.conf file of the remote host.

However, the variable called "target" does not get matched lines for 
searched string despite it being present and errors as below:

TASK [Find certificate entries] ***
>
> *task path: /app/test.yml:906*The full traceback is:
> Traceback (most recent call last):
> File "/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py", 
> line 144, in run
> res = self._execute()
> File "/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py", 
> line 576, in _execute
> self._task.post_validate(templar=templar)
> File "/usr/lib/python2.7/site-packages/ansible/playbook/task.py", line 
> 268, in post_validate
> super(Task, self).post_validate(templar)
> File "/usr/lib/python2.7/site-packages/ansible/playbook/base.py", line 
> 384, in post_validate
> value = templar.template(getattr(self, name))
> File "/usr/lib/python2.7/site-packages/ansible/template/__init__.py", line 
> 584, in template
> disable_lookups=disable_lookups,
> File "/usr/lib/python2.7/site-packages/ansible/template/__init__.py", line 
> 539, in template
> disable_lookups=disable_lookups,
> File "/usr/lib/python2.7/site-packages/ansible/template/__init__.py", line 
> 773, in do_template
> data = _escape_backslashes(data, myenv)
> File "/usr/lib/python2.7/site-packages/ansible/template/__init__.py", line 
> 145, in _escape_backslashes
> for token in jinja_env.lex(d2):
> File "/usr/lib/python2.7/site-packages/jinja2/lexer.py", line 733, in 
> tokeniter
> name, filename)
> TemplateSyntaxError: unexpected char u'\\' at 64
> line 1 fatal: [10.9.9.11]: FAILED! => {
> "msg": "Unexpected failure during module execution.", 
> "stdout": ""
> }


I used https://regex101.com to confirm that my \sSSLFile.* condition is 
good and returns matches on my httpd.conf file.

Can you please suggest ?

-- 
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/34cd7e11-6830-4b19-81c3-7a2d4731a0db%40googlegroups.com.


[ansible-project] Unable to print regex registered variable in Ansible

2020-01-14 Thread Shifa Shaikh
I wish to search for all entries of string starting with "SSLFile" or 
starting with "SSLFile" in a file(httpd.conf) and register it 
to a variable and print all the matches found. 

The string is found as evident from the output and the file is not modified 
which is good; but I'm unable to print (debug) it. I get error as I try to 
print. Below is my playbook:

- name: Find entries
  lineinfile:
path: "/tmp/httpd.conf"
regexp: "\\sSSLFile.*"
state: absent
  check_mode: yes
  changed_when: false
  register: filedet

- debug:
msg: "{{ filedet }}"

- debug:
msg: "{{ item.split()[1] }}"
  with_items:
- "{{ filedet.stdout_lines }}"

I get the below error when i run the playbook:


ok: [10.9.9.11] => {
> "backup": "", 
> "changed": false, 
> "diff": [
> {
> "after": "", 
> "after_header": "/tmp/httpd.conf (content)", 
> "before": "", 
> "before_header": "/tmp/httpd.conf (content)"
> }, 
> {
> "after_header": "/tmp/httpd.conf (file attributes)", 
> "before_header": "/tmp/httpd.conf (file attributes)"
> }
> ], 
> "found": 1, 
> "invocation": {
> "module_args": {
> "attributes": null, 
> "backrefs": false, 
> "backup": false, 
> "content": null, 
> "create": false, 
> "delimiter": null, 
> "directory_mode": null, 
> "firstmatch": false, 
> "follow": false, 
> "force": null, 
> "group": null, 
> "insertafter": null, 
> "insertbefore": null, 
> "line": null, 
> "mode": null, 
> "owner": null, 
> "path": "/tmp/httpd.conf", 
> "regexp": "\\sSSLFile.*", 
> "remote_src": null, 
> "selevel": null, 
> "serole": null, 
> "setype": null, 
> "seuser": null, 
> "src": null, 
> "state": "absent", 
> "unsafe_writes": null, 
> "validate": null
> }
> }, 
> "msg": "1 line(s) removed"
> } TASK [debug] 
> ***
>
> *task path: /app/test.yml:924*ok: [10.9.9.11] => {
> "msg": {
> "backup": "", 
> "changed": false, 
> "diff": [
> {
> "after": "", 
> "after_header": "/tmp/httpd.conf (content)", 
> "before": "", 
> "before_header": "/tmp/httpd.conf (content)"
> }, 
> {
> "after_header": "/tmp/httpd.conf (file attributes)", 
> "before_header": "/tmp/httpd.conf (file attributes)"
> }
> ], 
> "failed": false, 
> "found": 1, 
> "msg": "1 line(s) removed"
> }
> } TASK [debug] 
> ***
>
> *task path: /app/test.yml:928*fatal: [10.9.9.11]: FAILED! => {
> "msg": "'dict object' has no attribute 'stdout_lines'"
> }


Can you please suggest what is the correct way to print all the searched 
matched strings without modifying the file ? I wish to use the the 
registered variable to perform other actions later in the playbook.

-- 
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/47deda2a-1a8c-4387-9a5b-d2ea548ad752%40googlegroups.com.


[ansible-project] How to specify foldername with wildcard inside a jinja template

2020-03-06 Thread Shifa Shaikh
I wish to check using if condition inside a jinja template where any of the 
folders starting with the name "dump_" has any file starting with the name 
bad

For for single folder the below jinja template works as suggested by an 
expert on this forum. 

 {% if lookup('fileglob', playbook_dir + '/' + 'dump_' + item + '/' + 
'bad*.txt') %}


I understand that fileglob supports wildcards only on files and not on 
folders.

The below fails when wildcard is applied to a folder.

{% if lookup('fileglob', playbook_dir + '/' + 'dump_*' + '/' + 'bad*.txt') 
%}



Any solution to this problem please inside a jinja template?

-- 
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/da0c72f2-1fb2-45cc-88e3-540de05015ca%40googlegroups.com.


[ansible-project] How to get include_vars variable inside Jinja template ?

2020-03-09 Thread Shifa Shaikh
Experts Hi, 

I have couple of variable files like below:

$ cat vars_ip.yml
---
12.1.1.25: TAP1
12.1.1.26: TAP2
11.0.0.26: TAP3
11.0.0.27: TAP4
9.2.2.211: SAT1
9.2.2.212: SAT2
10.7.7.28: SAT3
10.7.7.29: SAT4
9.2.2.213: SAT5
10.7.7.30: SAT6


$ cat vars.yml

---
  layers:
- name: MY_LAYER
  things_prod:
- 12.1.1.25
- 12.1.1.26
  things_dr:
- 11.0.0.26
- 11.0.0.27
  bgcolor:
- '#AED6F1'


- name: YR_LAYER
  things_prod:
- 9.2.2.211
- 9.2.2.212
- 9.2.2.213
  things_dr:
- 10.7.7.28
- 10.7.7.29
- 10.7.7.30
  bgcolor:
- '#F9E79F'


Here is my playbook:

$ cat varloop.yml

---
  - name: Demonstrating variables in Jinja2 Loops
hosts: localhost
vars_files:
  - vars.yml
  - vars_ip.yml
gather_facts: no
tasks:
  - name: Create the Jinja2 based templateone
template: src=./varloop.j2 dest=./sync/sync.html


Here is my Jinja template file:

$ cat varloop.j2


{% for layer in layers %}
{% for item in layer.things_prod %}
{{ item }} {{ layer.things_dr[loop.index-1] }} var[{{ item }}] var[layer.
things_dr[loop.index-1]]
{% endfor %}
{% endfor %}


$ cat ./sync/sync.html
Output:

Current Output:
$ cat ./sync/sync.html


12.1.1.25 11.0.0.26 var[12.1.1.25] var[layer.things_dr[loop.index-1]]
12.1.1.26 11.0.0.27 var[12.1.1.26] var[layer.things_dr[loop.index-1]]
9.2.2.211 10.7.7.28 var[9.2.2.211] var[layer.things_dr[loop.index-1]]
9.2.2.212 10.7.7.29 var[9.2.2.212] var[layer.things_dr[loop.index-1]]
9.2.2.213 10.7.7.30 var[9.2.2.213] var[layer.things_dr[loop.index-1]]


I need the values from the vars_ip.yml variable file to be populated in the 
jinja template like below:

Expected output:
12.1.1.25 11.0.0.26 TAP1 TAP3
12.1.1.26 11.0.0.27 TAP2 TAP4
9.2.2.211 10.7.7.28 WAS1 WAS3
9.2.2.212 10.7.7.29 WAS2 TAP4
9.2.2.213 10.7.7.30 WAS3 WAS6

 Kindly suggests.





-- 
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/6fd3c5d7-2460-4afa-b9ad-22e5dfb19a57%40googlegroups.com.


[ansible-project] How to use same loop index for two list from variable file in Jinja template

2020-03-09 Thread Shifa Shaikh
I have a variable file like below:

12.1.1.25: TAP1
12.1.1.26: TAP2
11.0.0.26: TAP3
11.0.0.27: TAP4
9.2.2.211: SAT1
9.2.2.212: SAT2
10.7.7.28: SAT3
10.7.7.29: SAT4


  layers:
- name: MY_LAYER
  things_prod:
- 12.1.1.25
- 12.1.1.26
  things_dr:
- 11.0.0.26
- 11.0.0.27
  bgcolor:
- '#AED6F1'


- name: YR_LAYER
  things_prod:
- 9.2.2.211
- 9.2.2.212
- 9.2.2.213
  things_dr:
- 10.7.7.28
- 10.7.7.29
- 10.7.7.30
  bgcolor:
- '#F9E79F'


I need help with jinja template that give me the below output:


MY_LAYER
TAP1TAP3
file_12.1.1.25_11.0.0.26.txt
TAP2TAP4
file_12.1.1.26_11.0.0.27.txt


YR_LAYER
SAT1SAT3
file_9.2.2.211_10.7.7.28.txt
SAT2SAT4
file_9.2.2.212_10.7.7.29.txt
SAT3SAT6
file_9.2.2.213_10.7.7.30.txt

How can i have loop.index loop over both lists things_prod & things_dr 
simultaneaously for us to get say "file_12.1.1.25_11.0.0.26.txt" ?

Below is the approach I took so far:

{% for layer in layers %}



{% for item in layer.things_prod %}
vars[item] <-- dont know how to get corresponding 
variable for things_dr 
file_{{ item }}_{{ item }}.txt  <-- dont know how to get corresponding 
variable for things_dr


{% endfor %}

{% endfor %}

-- 
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/fa9de9eb-e7db-4f64-872c-6c0a127a9483%40googlegroups.com.


[ansible-project] rescue block does not print message despite being invoked

2020-03-12 Thread Shifa Shaikh
Hi, 

I have a playbook with a task that greps for a string in a file. If the 
string is found the block should fail which is the case. However, in the 
fail module it fails to print the message. 

Here is my playbook:

Here is my playbook:

---
- name: "Play 1"
  hosts: localhost
  tasks:
   - block:
  - name: "Search for IP"
command: "grep -w {{ source_host }} {{ playbook_dir 
}}/allhost.hosts"
register: command_result
failed_when: command_result.rc == 0 and action == "onboard"


 rescue:
  - name: Print custom conditional debug message
fail:
  msg: >-
{{
  command_result.rc == 0 |
  ternary(
"This IP is already On-Boarded.",
"The Database is not reachable."
  )
}}



Considering command_result.rc = 0; I was expecting "This IP is already 
On-Boarded." to be printed however it does not. Can you please tell me why.

Output:

TASK [Search for IP] *
[1;30mtask path: /tmp/filegaurd.yml:20[0m
[0;34mUsing module file /usr/lib/python2.7/site-packages/ansible/modules/
commands/command.py[0m
[0;34mPipelining is enabled.[0m
[0;34m<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: user1[0m
[0;34m<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python2 && sleep 0'[0m
[0;31mfatal: [localhost]: FAILED! => {[0m
[0;31m"changed": true, [0m
[0;31m"cmd": [[0m
[0;31m"grep", [0m
[0;31m"-w", [0m
[0;31m"10.9.9.91", [0m
[0;31m"/tmp/allhost.hosts"[0m
[0;31m], [0m
[0;31m"delta": "0:00:00.096103", [0m
[0;31m"end": "2020-03-13 07:25:43.705938", [0m
[0;31m"failed_when_result": true, [0m
[0;31m"invocation": {[0m
[0;31m"module_args": {[0m
[0;31m"_raw_params": "grep -w 10.9.9.91 /tmp/allhost.hosts", [0m
[0;31m"_uses_shell": false, [0m
[0;31m"argv": null, [0m
[0;31m"chdir": null, [0m
[0;31m"creates": null, [0m
[0;31m"executable": null, [0m
[0;31m"removes": null, [0m
[0;31m"stdin": null, [0m
[0;31m"stdin_add_newline": true, [0m
[0;31m"strip_empty_ends": true, [0m
[0;31m"warn": true[0m
[0;31m}[0m
[0;31m}, [0m
[0;31m"rc": 0, [0m
[0;31m"start": "2020-03-13 07:25:43.609835", [0m
[0;31m"stderr": "", [0m
[0;31m"stderr_lines": [], [0m
[0;31m"stdout": "10.9.9.91 USERID=user1 
files_list=/tmp/winstone4603745991442278706.jar,/tmp/winstone5835113081224811756.jar"
, [0m
[0;31m"stdout_lines": [[0m
[0;31m"10.9.9.91 USERID=user1 
files_list=/tmp/winstone4603745991442278706.jar,/tmp/winstone5835113081224811756.jar"
[0m
[0;31m][0m
[0;31m}[0m


TASK [Print custom conditional debug message] 
**
[1;30mtask path: /tmp/filegaurd.yml:28[0m
[0;31mfatal: [localhost]: FAILED! => {[0m
[0;31m"changed": false, [0m
[0;31m"msg": "False "[0m
[0;31m}[0m


PLAY RECAP 
*
[0;31mlocalhost[0m  : [0;32mok=1   [0m changed=0   
 unreachable=0[0;31mfailed=1   [0m skipped=0[0;32mrescued=1   [0m 
ignored=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/7fe0646e-8f35-4d7f-be5b-10aa6e85a56c%40googlegroups.com.


Re: [ansible-project] rescue block does not print message despite being invoked

2020-03-12 Thread Shifa Shaikh
Missing parentheses where?

My code is very similar to a working sample here:

  fail:
msg: >-
  {{
command_result.stdout is search('775') |
ternary(
  "This REQ is already Deployed. ,
  "Database is not reachable."
)
  }}

On Fri, 13 Mar, 2020, 8:06 am James Cassell, 
wrote:

>
> On Thu, Mar 12, 2020, at 10:12 PM, Shifa Shaikh wrote:
> > Hi,
> >
> > I have a playbook with a task that greps for a string in a file. If the
> > string is found the block should fail which is the case. However, in
> > the fail module it fails to print the message.
> >
> > Here is my playbook:
> >
> > Here is my playbook:
> >
> > `
> > ---
> > - name: "Play 1"
> >  hosts: localhost
> >  tasks:
> > - block:
> > - name: "Search for IP"
> >  command: "grep -w {{ source_host }} {{ playbook_dir }}/allhost.hosts"
> > register: command_result
> >  failed_when: command_result.rc == 0 and action == "onboard"
> >
> >
> > rescue:
> > - name: Print custom conditional debug message
> >  fail:
> >  msg: >-
> > {{
> >  command_result.rc == 0 |
>
> You're missing parenthesis around the condition.
>
> V/r,
> James Cassell
>
> >  ternary(
> > "This IP is already On-Boarded.",
> > "The Database is not reachable."
> > )
> > }}
> >
> > `
> >
> >
> > Considering command_result.rc = 0; I was expecting "This IP is already
> > On-Boarded." to be printed however it does not. Can you please tell me
> > why.
> >
> > Output:
> >
> > `
> > TASK [Search for IP] *
> > [1;30mtask path: /tmp/filegaurd.yml:20[0m
> > [0;34mUsing module file
> > /usr/lib/python2.7/site-packages/ansible/modules/commands/command.py[0m
> > [0;34mPipelining is enabled.[0m
> > [0;34m<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: user1[0m
> > [0;34m<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python2 && sleep 0'[0m
> > [0;31mfatal: [localhost]: FAILED! => {[0m
> > [0;31m "changed": true, [0m
> > [0;31m "cmd": [[0m
> > [0;31m "grep", [0m
> > [0;31m "-w", [0m
> > [0;31m "10.9.9.91", [0m
> > [0;31m "/tmp/allhost.hosts"[0m
> > [0;31m ], [0m
> > [0;31m "delta": "0:00:00.096103", [0m
> > [0;31m "end": "2020-03-13 07:25:43.705938", [0m
> > [0;31m "failed_when_result": true, [0m
> > [0;31m "invocation": {[0m
> > [0;31m "module_args": {[0m
> > [0;31m "_raw_params": "grep -w 10.9.9.91 /tmp/allhost.hosts", [0m
> > [0;31m "_uses_shell": false, [0m
> > [0;31m "argv": null, [0m
> > [0;31m "chdir": null, [0m
> > [0;31m "creates": null, [0m
> > [0;31m "executable": null, [0m
> > [0;31m "removes": null, [0m
> > [0;31m "stdin": null, [0m
> > [0;31m "stdin_add_newline": true, [0m
> > [0;31m "strip_empty_ends": true, [0m
> > [0;31m "warn": true[0m
> > [0;31m }[0m
> > [0;31m }, [0m
> > [0;31m "rc": 0, [0m
> > [0;31m "start": "2020-03-13 07:25:43.609835", [0m
> > [0;31m "stderr": "", [0m
> > [0;31m "stderr_lines": [], [0m
> > [0;31m "stdout": "10.9.9.91 USERID=user1
> >
> files_list=/tmp/winstone4603745991442278706.jar,/tmp/winstone5835113081224811756.jar",
> [0m
> > [0;31m "stdout_lines": [[0m
> > [0;31m "10.9.9.91 USERID=user1
> >
> files_list=/tmp/winstone4603745991442278706.jar,/tmp/winstone5835113081224811756.jar"[0m
> > [0;31m ][0m
> > [0;31m}[0m
> >
> >
> > TASK [Print custom conditional debug message]
> **
> > [1;30mtask path: /tmp/filegaurd.yml:28[0m
> > [0;31mfatal: [localhost]: FAILED! => {[0m
> > [0;31m "changed": false, [0m
> > [0;31m "msg": "False "[0m
> > [0;31m}[0m
> >
> >
> > PLAY RECAP
> > *
> > [0;31mlocalhost[0m : [0;32mok=1 [0m changed=0 unreachable=0
> > [0;31mfailed=1 [0m skipped=0 [0;32mrescued=1 [0m ignored=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/53303de2-c158-4f30-b968-44d4b9be9d36%40www.fastmail.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/CAJtox0mm%2B0ei8p5uLsts4O9Nw1kj%2BAgUPxYFUap_eAnsNcnCdA%40mail.gmail.com.


Re: [ansible-project] unable to create directory using ansible file module

2020-03-16 Thread Shifa Shaikh
@Dick your suggestion helped !! it works. 

On Monday, March 16, 2020 at 1:27:14 PM UTC+5:30, Dick Visser wrote:
>
> Ah OK yes, i see, you're right. 
> The issue is your quoting, as indicated by the error message. 
> Instead of: 
>
>- file: path="{{ playbook_dir }}/dashboard/{{ my_result.name }} 
> state=directory recurse=yes" 
>
> Do this: 
>
>- file: path="{{ playbook_dir }}/dashboard/{{ my_result.name }}" 
> state=directory recurse=yes 
>
>
> On Mon, 16 Mar 2020 at 08:41, Shifa Shaikh  > wrote: 
> > 
> > Dick Hi, The issue is not with the loop as I can see the correct value 
> populated using debug. 
> > 
> > Aslo, the correct value shows up in the error output from the loop ... 
> see below: 
> > 
> > fatal: [localhost]: FAILED! => {"changed": false, "msg": "file 
> (/tmp/dashboard/APP state=directory recurse=yes) is absent, cannot 
> continue", "path": "/tmp/dashboard/APP state=directory recurse=yes"} 
> > 
> > /tmp/dashboard/APP is indeed the correct desired directory that should 
> be created. 
> > 
> > Please suggest. 
> > 
> > 
> > On Monday, March 16, 2020 at 1:00:24 PM UTC+5:30, Dick Visser wrote: 
> >> 
> >> Hi 
> >> 
> >> you've missed a few basic things. The vars file contains a duplicate 
> >> variable layers - that won't work. 
> >> Also, you appear to want to loop over the variable layers, but you 
> >> don't actually use it. 
> >> Have a look at this URL, it has some nice examples of how loops work: 
> >> 
> >> 
> https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html#iterating-over-a-simple-list
>  
> >> 
> >> 
> >> 
> >> On Mon, 16 Mar 2020 at 08:21, Shifa Shaikh  wrote: 
> >> > 
> >> > Here is my variable file: 
> >> > 
> >> > cat vars.yml 
> >> > --- 
> >> > 
> >> >   layers: 
> >> > - name: APP 
> >> >   layers: 
> >> > - name: WLS 
> >> > 
> >> > 
> >> > Here is my playbook 
> >> > 
> >> > cat varloop.yml 
> >> > --- 
> >> > 
> >> > hosts: localhost 
> >> > vars_files: 
> >> >   - vars.yml 
> >> > 
> >> > 
> >> > 
> >> > tasks: 
> >> >   - name: Create sublinks based of bad.txt files 
> >> > include_tasks: "{{ playbook_dir }}/inner.yml" 
> >> > loop: "{{ layers }}" 
> >> > loop_control: 
> >> >   loop_var: my_result 
> >> > 
> >> > inner.yml 
> >> > - name: Generate JSON data 
> >> >   block: 
> >> > - file: path="{{ playbook_dir }}/dashboard/{{ my_result.name }} 
> state=directory recurse=yes" 
> >> > 
> >> > 
> >> > However, I'm getting the following error running the code: 
> >> > 
> >> > TASK [file] 
> *
>  
>
> >> > fatal: [localhost]: FAILED! => {"changed": false, "msg": "file 
> (/tmp/dashboard/APP state=directory recurse=yes) is absent, cannot 
> continue", "path": "/tmp/dashboard/APP state=directory recurse=yes"} 
> >> > 
> >> > I was expecting the play to create the directory 
> "/tmp/dashboard/APP", however it errors and fails.  Can you please suggest 
> ? 
> >> > 
> >> > -- 
> >> > 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/0fe8246b-1d71-44c4-baa0-6185815366a1%40googlegroups.com.
>  
>
> >> 
> >> 
> >> 
> >> -- 
> >> Dick Visser 
> >> Trust & Identity Service Operations Manager 
> >> GÉANT 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups "Ansible Project" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an email to ansible...@googlegroups.com . 
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/42e9abb0-78c1-4f0e-940a-a185f1a34ba6%40googlegroups.com.
>  
>
>
>
>
> -- 
> Dick Visser 
> Trust & Identity Service Operations Manager 
> GÉANT 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/67ca1101-43f4-441e-9fad-20dd5a6ab504%40googlegroups.com.


[ansible-project] unable to create directory using ansible file module

2020-03-16 Thread Shifa Shaikh
Here is my variable file:

cat vars.yml
---

  layers:
- name: APP
  layers:
- name: WLS


Here is my playbook

cat varloop.yml
---

hosts: localhost
vars_files:
  - vars.yml



tasks:
  - name: Create sublinks based of bad.txt files
include_tasks: "{{ playbook_dir }}/inner.yml"
loop: "{{ layers }}"
loop_control:
  loop_var: my_result

inner.yml
- name: Generate JSON data
  block:
- file: path="{{ playbook_dir }}/dashboard/{{ my_result.name }} 
state=directory recurse=yes"


However, I'm getting the following error running the code:

TASK [file] 
*
fatal: [localhost]: FAILED! => {"changed": false, "msg": "file 
(/tmp/dashboard/APP state=directory recurse=yes) is absent, cannot continue"
, "path": "/tmp/dashboard/APP state=directory recurse=yes"}

I was expecting the play to create the directory "/tmp/dashboard/APP", 
however it errors and fails.  Can you please suggest ? 

-- 
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/0fe8246b-1d71-44c4-baa0-6185815366a1%40googlegroups.com.


Re: [ansible-project] unable to create directory using ansible file module

2020-03-16 Thread Shifa Shaikh
Dick Hi, The issue is not with the loop as I can see the correct value 
populated using debug. 

Aslo, the correct value shows up in the error output from the loop ... see 
below:

fatal: [localhost]: FAILED! => {"changed": false, "msg": "file 
(/tmp/dashboard/APP state=directory recurse=yes) is absent, cannot continue"
, "path": "/tmp/dashboard/APP state=directory recurse=yes"}

/tmp/dashboard/APP is indeed the correct desired directory that should be 
created.

Please suggest.


On Monday, March 16, 2020 at 1:00:24 PM UTC+5:30, Dick Visser wrote:
>
> Hi 
>
> you've missed a few basic things. The vars file contains a duplicate 
> variable layers - that won't work. 
> Also, you appear to want to loop over the variable layers, but you 
> don't actually use it. 
> Have a look at this URL, it has some nice examples of how loops work: 
>
>
> https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html#iterating-over-a-simple-list
>  
>
>
>
> On Mon, 16 Mar 2020 at 08:21, Shifa Shaikh  > wrote: 
> > 
> > Here is my variable file: 
> > 
> > cat vars.yml 
> > --- 
> > 
> >   layers: 
> > - name: APP 
> >   layers: 
> > - name: WLS 
> > 
> > 
> > Here is my playbook 
> > 
> > cat varloop.yml 
> > --- 
> > 
> > hosts: localhost 
> > vars_files: 
> >   - vars.yml 
> > 
> > 
> > 
> > tasks: 
> >   - name: Create sublinks based of bad.txt files 
> > include_tasks: "{{ playbook_dir }}/inner.yml" 
> > loop: "{{ layers }}" 
> > loop_control: 
> >   loop_var: my_result 
> > 
> > inner.yml 
> > - name: Generate JSON data 
> >   block: 
> > - file: path="{{ playbook_dir }}/dashboard/{{ my_result.name }} 
> state=directory recurse=yes" 
> > 
> > 
> > However, I'm getting the following error running the code: 
> > 
> > TASK [file] 
> *
>  
>
> > fatal: [localhost]: FAILED! => {"changed": false, "msg": "file 
> (/tmp/dashboard/APP state=directory recurse=yes) is absent, cannot 
> continue", "path": "/tmp/dashboard/APP state=directory recurse=yes"} 
> > 
> > I was expecting the play to create the directory "/tmp/dashboard/APP", 
> however it errors and fails.  Can you please suggest ? 
> > 
> > -- 
> > 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/0fe8246b-1d71-44c4-baa0-6185815366a1%40googlegroups.com.
>  
>
>
>
>
> -- 
> Dick Visser 
> Trust & Identity Service Operations Manager 
> GÉANT 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/42e9abb0-78c1-4f0e-940a-a185f1a34ba6%40googlegroups.com.


Re: [ansible-project] Unable to get correct disk space utilized percentage using Ansible API

2020-03-25 Thread Shifa Shaikh
@Kia Hi, 

As suggested I tried 

item.size_total instead of item.size_available

 "{{ ansible_host }}_{{ item.mount }}: {{ (100 * ((item.size_total - 
item.size_available) / item.size_total)) | round(1, 'common') }}" 



but it still gives me 22.2 % value instead of 19%

Can you please let me know what's wrong and why the difference?

On Wednesday, March 25, 2020 at 10:10:24 PM UTC+5:30, Kai Stian Olstad 
wrote:
>
> On Wed, Mar 25, 2020 at 07:15:51AM -0700, Shifa Shaikh wrote: 
> > 
> > "{{ ansible_host }}_{{ item.mount }}: {{ (100 * ((item.size_total - 
> item.size_available) / item.size_available)) | round(1, 'common') }}" 
>
> That is not how you calculate percentage, you need to divide on 
> item.size_total 
> and not item.size_available. 
>
> -- 
> 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/529bd7a9-69b6-4bea-a247-c0f1e9d918c9%40googlegroups.com.


[ansible-project] Integer comparision issue in jinja2 template Ansible

2020-03-26 Thread Shifa Shaikh
My jinja2 template yields correct value for the variable

{{ vars[allip.name | join("")] | default('ERR') }}

The variable has value 82.3 which gets printed by Ansible's template module.

I wish to write an if condition where I want to check if the value of the 
variable is more than 80 

{% if ( vars[allip.name | join("") | int ) > 80 %}

MORE THAN 80

{% endif %}


However, the 'if' the condition does not meet.

I tried  

{% if ( vars[allip.name | join("") | int  > 80 ) %}

I also tried

{% if vars[allip.name | join("") | int  > 80 %}

But, none of them worked. Can you please let me know what needs to be done 
to meet the if condition?


-- 
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/34ea1c10-1094-4583-aa71-24bb532ff99a%40googlegroups.com.


[ansible-project] Integer comparison if condition jinja2 template Ansible does not work

2020-03-26 Thread Shifa Shaikh
My jinja2 template yields correct value for the variable

{{ vars[allip.name | join("")] | default('ERR') }}

The variable has value 82.3 which gets printed by Ansible's template module.

I wish to write an if condition where I want to check if the value of the 
variable is more than 80 

{% if ( vars[allip.name | join("")] | int ) > 80 %}

MORE THAN 80

{% endif %}

However, the 'if' the condition does not meet.

I tried  

{% if ( vars[allip.name | join("")] | int  > 80 ) %}

I also tried

{% if vars[allip.name | join("")] | int  > 80 %}

But, none of them worked. Can you please let me know what needs to be done 
to meet the if condition?

-- 
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/45e56835-bf61-4de5-a43a-af6c8205ecfc%40googlegroups.com.


[ansible-project] Unable to get remote target hostname when using delegate_to

2020-03-25 Thread Shifa Shaikh
Below playbook gets the disk usage percentage of '/tmp' from a list of 
remote_hosts [20 remote servers] and stores it locally (delegate_to) in a 
file {{ playbook_dir }}/tmpfiles/stats.yml

---
hosts: remote_hosts
  tasks:
- name: Generate JSON data
  lineinfile:
path: "{{ playbook_dir }}/tmpfiles/stats.yml"
line: "{{ inventory_hostname }}_{{ item.mount }}: {{ (100 * 
((item.size_total - item.size_available) / item.size_total)) | round(1, 
'common') }}"
insertafter: EOF
  delegate_to: localhost
  when: item.mount == '/tmp'
  with_items: '{{ ansible_mounts }}'


I wish to get the target hostname_mountname in the stats.yml

Thus if the remote_hosts are

10.0.0.2
> 10.0.0.3
> 10.0.0.5


My stats.yml should have the below entries (Expected Output):

10.0.0.2_/tmp: 54
> 10.0.0.3_/tmp: 42
> 10.0.0.5_/tmp: 65


However, after using lineinfile and delegate_to it always prints localhost

localhost:/tmp: 54
> localhost_/tmp: 42
> localhost_/tmp: 65


I tried using {{ ansible_host }} instead of {{ inventory_hostname }} but it 
always prints localhost instead of the target from where it is fetching the 
disk usage information.

Note: if I remove delegate_to then it prints the remote IP fine but then I 
wish the file to be created locally and not on the remote host.

-- 
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/ecf07c8c-83c4-4504-ba3f-a2f7975bf1a3%40googlegroups.com.


Re: [ansible-project] Unable to get correct disk space utilized percentage using Ansible API

2020-03-26 Thread Shifa Shaikh
Thank you @Kai for the excellent explanation :)

On Thursday, March 26, 2020 at 12:41:00 AM UTC+5:30, Kai Stian Olstad wrote:
>
> On Wed, Mar 25, 2020 at 09:54:07AM -0700, Shifa Shaikh wrote: 
> > @Kia Hi, 
> > 
> > As suggested I tried 
> > 
> > item.size_total instead of item.size_available 
> > 
> >  "{{ ansible_host }}_{{ item.mount }}: {{ (100 * ((item.size_total - 
> > item.size_available) / item.size_total)) | round(1, 'common') }}" 
> > 
> > 
> > 
> > but it still gives me 22.2 % value instead of 19% 
> > 
> > Can you please let me know what's wrong and why the difference? 
>
> This is a little out of scope of this list, so I'll keep it brief. 
>
> When you create a filesystem mkfs reserve some block on the device. 
> df output available block but this value doesn't count the reserved 
> blocks. 
>
> Filesystem1K-blocks Used Available Use% Mounted on 
> /dev/mapper/ihs_vg_yt 51466720 8790352 40038956 19% /ihs 
>
> Just to illustrate on your df output of /ihs by doing Total - Used - 
> Available should equal 0 if no blocks was reserved. 
>
> 51466720 - 8790352 - 40038956 = 82715324 
> So you have about 82.7 million 1K blocks reserved. 
>
> df uses the "Used" / ( "Used" + "Available") to calculate used 
> 8790352 / (8790352 + 40038956) = approx. 0,18002205 
>
> So a little over 18 percent which is rounded up to 19% 
>
> When you in Ansible do size_total - size_available you are including the 
> reserved blocks in used and that is why you get a higher number than df. 
>
>
> -- 
> 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/f3df456b-537f-4e6e-a234-c3e2500cea6f%40googlegroups.com.


[ansible-project] Unable to get correct disk usage percentage using Ansible API

2020-03-25 Thread Shifa Shaikh


Here is the output of df -k from the target server: 


ok: [myhostone] => (item={u'block_used': 2857014, u'uuid': 
> u'3fa1ec29-aca5-476b-8041-6a7bc6b1efc2', u'size_total': 52701921280, 
> u'block_total': 12866680, u'mount': u'/ihs', u'block_available': 10009666, 
> u'size_available': 40999591936, u'fstype': u'ext4', u'inode_total': 
> 3276800, u'inode_available': 3264353, u'device': u'/dev/mapper/ihs_vg_yt', 
> u'inode_used': 12447, u'block_size': 4096, u'options': 
> u'rw,seclabel,relatime,stripe=256,data=ordered'}) => {
> "ansible_facts": {
> "_raw_params": "myhostone_/ihs: 28.5"
> },
> "ansible_loop_var": "item",
> "changed": false,
> "item": {
> "block_available": 10009666,
> "block_size": 4096,
> "block_total": 12866680,
> "block_used": 2857014,
> "device": "/dev/mapper/ihs_vg_yt",
> "fstype": "ext4",
> "inode_available": 3264353,
> "inode_total": 3276800,
> "inode_used": 12447,
> "mount": "/ihs",
> "options": "rw,seclabel,relatime,stripe=256,data=ordered",
> "size_available": 40999591936,
> "size_total": 52701921280,
> "uuid": "3fa1ec29-aca5-476b-8041-6a7bc6b1efc2"


I wish to get Use percentage for /ihs mount which is 19%.

Here is my playbook code:

- name: Generate JSON data set_fact: "{{ ansible_host }}_{{ item.mount }}: {{ 
(100 * ((item.size_total - item.size_available) / item.size_available)) | 
round(1, 'common') }}" when: item.mount == '/ihs' with_items: '{{ 
ansible_mounts }}'

However, the output of my playbook run shows 28.5 % usage instead of 19%:

ok: [myhostone] => (item={u'block_used': 2857014, u'uuid': 
u'3fa1ec29-aca5-476b-8041-6a7bc6b1efc2', u'size_total': 52701921280, 
u'block_total': 12866680, u'mount': u'/ihs', u'block_available': 10009666, 
u'size_available': 40999591936, u'fstype': u'ext4', u'inode_total': 3276800, 
u'inode_available': 3264353, u'device': u'/dev/mapper/ihs_vg_yt', 
u'inode_used': 12447, u'block_size': 4096, u'options': 
u'rw,seclabel,relatime,stripe=256,data=ordered'}) => {
"ansible_facts": {
"_raw_params": "myhostone_/ihs: 28.5"
},
"ansible_loop_var": "item",
"changed": false,
"item": {
"block_available": 10009666,
"block_size": 4096,
"block_total": 12866680,
"block_used": 2857014,
"device": "/dev/mapper/ihs_vg_yt",
"fstype": "ext4",
"inode_available": 3264353,
"inode_total": 3276800,
"inode_used": 12447,
"mount": "/ihs",
"options": "rw,seclabel,relatime,stripe=256,data=ordered",
"size_available": 40999591936,
"size_total": 52701921280,
"uuid": "3fa1ec29-aca5-476b-8041-6a7bc6b1efc2"

Can you please tell me why is the percentage of used disk shows 28.5% with 
ansible while the df -k shows only 19% used? How can I get the correct 
usage i.e 19% to s

-- 
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/3b69b2c9-4f77-4c25-af9b-61547d05a688%40googlegroups.com.


[ansible-project] Unable to get correct disk space utilized percentage using Ansible API

2020-03-25 Thread Shifa Shaikh


Here is the output of df -k from the target server: 


# df -k
> Filesystem 1K-blocks Used Available Use% Mounted on
> devtmpfs 1905280 0 1905280 0% /dev
> tmpfs 1922024 0 1922024 0% /dev/shm
> /dev/sda1 1942528 295616 1646912 16% /boot
> /dev/mapper/OMT-home 15718400 832120 14886280 6% /home
> /dev/mapper/OMT-tmp 6133760 33160 6100600 1% /tmp
> /dev/mapper/OMT-opt 10475520 4658356 5817164 45% /opt
> /dev/mapper/OMT-var 16734208 8803440 7930768 53% /var
> /dev/loop0 3704296 3704296 0 100% /mnt/media
> /dev/mapper/ihs_vg_yt 51466720 8790352 40038956 19% /ihs
> tmpfs 384408 0 384408 0% /run/user/0


I wish to get Use percentage for /ihs mount which is 19%.

Here is my playbook code:

- name: Generate JSON data
  set_fact:
"{{ ansible_host }}_{{ item.mount }}: {{ (100 * ((item.size_total - 
item.size_available) / item.size_available)) | round(1, 'common') }}"
  when: item.mount == '/ihs'
  with_items: '{{ ansible_mounts }}'


However, the output of my playbook run shows 28.5 % usage instead of 19%:

ok: [myhostone] => (item={u'block_used': 2857014, u'uuid': 
u'3fa1ec29-aca5-476b-8041-6a7bc6b1efc2', u'size_total': 52701921280, 
u'block_total': 12866680, u'mount': u'/ihs', u'block_available': 10009666, 
u'size_available': 40999591936, u'fstype': u'ext4', u'inode_total': 3276800, 
u'inode_available': 3264353, u'device': u'/dev/mapper/ihs_vg_yt', 
u'inode_used': 12447, u'block_size': 4096, u'options': 
u'rw,seclabel,relatime,stripe=256,data=ordered'}) => {
"ansible_facts": {
"_raw_params": "myhostone_/ihs: 28.5"
},
"ansible_loop_var": "item",
"changed": false,
"item": {
"block_available": 10009666,
"block_size": 4096,
"block_total": 12866680,
"block_used": 2857014,
"device": "/dev/mapper/ihs_vg_yt",
"fstype": "ext4",
"inode_available": 3264353,
"inode_total": 3276800,
"inode_used": 12447,
"mount": "/ihs",
"options": "rw,seclabel,relatime,stripe=256,data=ordered",
"size_available": 40999591936,
"size_total": 52701921280,
"uuid": "3fa1ec29-aca5-476b-8041-6a7bc6b1efc2"

Can you please tell me why is the percentage of the used disk shows 28.5% 
with ansible while the df -k shows only 19% used? How can I get the correct 
usage i.e 19% to s

-- 
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/55b43008-ae60-4c23-8199-299ab6f04528%40googlegroups.com.


[ansible-project] How to execute Play 2 only if Play 1 succeeds

2020-03-29 Thread Shifa Shaikh


I have two Plays having one task each.


The first Play 1 checks if the/var/test.datexists on each target host. 


Only if the Play 1 is successful do I want the second play Play 2 to run 
which executes scripts in parallel.


If Play 1 fails i.e if the test.dat does not exist I wish to terminate the 
entire playbook without the Play 2 getting executed. 


For this purpose, I have set any_errors_fatal set to true


I need to have an ansible Play strategy set to free as each of the scripts 
takes 30 minutes to complete hence running them in parallel is the 
requirement.


My understanding of ansible is limited.


I understand that if I have both the tasks under a single Play and set the 
strategy to free both the tasks will run in parallel which is something I 
do not want.


---

- name: Play 1- check for login and script
  hosts: all_hosts
  any_errors_fatal: true
  strategy: free
  tasks:

   - name: Check script existence
 shell: "ls /var/test.dat"
 register: checkscript

   - name:
 fail:
   msg: "script {{ scriptdet }} missing on {{ inventory_hostname }}"
 when: checkscript.rc != 0

- name: Play 2- Run scripts
  hosts: all_hosts
  user: "{{ USER }}"
  strategy: free

  tasks:
   - name: Execute backup script
 shell: "{{ scriptdet }}"
 args:
   chdir: ~/..


I tried the above playbook but I see the second play executes despite the 
first play's task failed.


Can you please suggest how can I get this to work?

-- 
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/1b0ccbc8-6dac-4d90-acd4-c4a852b38f5b%40googlegroups.com.


[ansible-project] Unable to run java code with classpath on a remote server

2020-05-15 Thread Shifa Shaikh
In order to run java code I need to first set the classpath of dependent 
libraries by running a script setWLSEnv.sh as below:

$ . /app/wlserv*/server/bin/setWLSEnv.sh
$ java weblogic.version


The output gives me the version of the product which I need. 
I wrote the below playbook but it does not run the java code. 

---
  - hosts: dest_nodes


tasks:
  - name: Get weblogic version
shell: "/app/wlserv*/server/bin/setWLSEnv.sh;java weblogic.version"
register: wlsversion


  - debug:
  msg: "{{ wlsversion }}"


However, I get this error:

fatal: [10.0.0.91]: FAILED! => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"cmd": "/app/wlserv*/server/bin/setWLSEnv.sh;java weblogic.version",
"delta": "0:00:00.271434",
"end": "2020-05-15 16:31:44.209506",
"invocation": {
"module_args": {
"_raw_params": "/app/wlserv*/server/bin/setWLSEnv.sh;java 
weblogic.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
}
},
"msg": "non-zero return code",
"rc": 1,
"start": "2020-05-15 16:31:43.938072",
"stderr": "Error: Could not find or load main class weblogic.version",
"stderr_lines": [
"Error: Could not find or load main class weblogic.version"
],
"stdout": 
"CLASSPATH=/usr/java/jdk1.8.0_192-amd64/lib/tools.jar:/app/wlserver/modules/features/wlst.wls.classpath.jar:\n\nPATH=/app/wlserver/server/bin:/app/wlserver/../oracle_common/modules/thirdparty/org.apache.ant/1.9.8.0.0/apache-ant-1.9.8/bin:/usr/java/jdk1.8.0_192-amd64/jre/bin:/usr/java/jdk1.8.0_192-amd64/bin:/usr/lib64/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/app/wlserver/../oracle_common/modules/org.apache.maven_3.2.5/bin\n\nYour
 
environment has been set.",
"stdout_lines": [

"CLASSPATH=/usr/java/jdk1.8.0_192-amd64/lib/tools.jar:/app/wlserver/modules/features/wlst.wls.classpath.jar:"
,
"",

"PATH=/app/wlserver/server/bin:/app/wlserver/../oracle_common/modules/thirdparty/org.apache.ant/1.9.8.0.0/apache-ant-1.9.8/bin:/usr/java/jdk1.8.0_192-amd64/jre/bin:/usr/java/jdk1.8.0_192-amd64/bin:/usr/lib64/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/app/wlserver/../oracle_common/modules/org.apache.maven_3.2.5/bin"
,
"",
"Your environment has been set."
]
}


>From the output, I see that the classpath did get set but java 
weblogic.version command failed on the remote host.

Can you please suggest how can I get the Weblogic version registered to 
wlsversion 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/f9e6d0f2-75a4-48ee-b086-ffb11a4e3336%40googlegroups.com.


[ansible-project] Re: Unable to run java code with classpath on a remote server

2020-05-16 Thread Shifa Shaikh
I found the solution myself. Here it is:

---
  - hosts: dest_nodes

tasks:
  - name: Get weblogic CLASSPATH
shell: "/app/wlserv*/server/bin/setWLSEnv.sh"
register: wlsenv

  - name: Get weblogic Version
shell: "java weblogic.version"
environment:
  CLASSPATH: "{{ wlsenv.stdout }}"
register: wlsversion

  - debug:
  msg: "{{ wlsversion }}


On Saturday, May 16, 2020 at 12:47:26 AM UTC+5:30, Shifa Shaikh wrote:
>
> In order to run java code I need to first set the classpath of dependent 
> libraries by running a script setWLSEnv.sh as below:
>
> $ . /app/wlserv*/server/bin/setWLSEnv.sh
> $ java weblogic.version
>
>
> The output gives me the version of the product which I need. 
> I wrote the below playbook but it does not run the java code. 
>
> ---
>   - hosts: dest_nodes
>
>
> tasks:
>   - name: Get weblogic version
> shell: "/app/wlserv*/server/bin/setWLSEnv.sh;java 
> weblogic.version"
> register: wlsversion
>
>
>   - debug:
>   msg: "{{ wlsversion }}"
>
>
> However, I get this error:
>
> fatal: [10.0.0.91]: FAILED! => {
> "ansible_facts": {
> "discovered_interpreter_python": "/usr/bin/python"
> },
> "changed": true,
> "cmd": "/app/wlserv*/server/bin/setWLSEnv.sh;java weblogic.version",
> "delta": "0:00:00.271434",
> "end": "2020-05-15 16:31:44.209506",
> "invocation": {
> "module_args": {
> "_raw_params": "/app/wlserv*/server/bin/setWLSEnv.sh;java 
> weblogic.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
> }
> },
> "msg": "non-zero return code",
> "rc": 1,
> "start": "2020-05-15 16:31:43.938072",
> "stderr": "Error: Could not find or load main class weblogic.version",
> "stderr_lines": [
> "Error: Could not find or load main class weblogic.version"
> ],
> "stdout": 
> "CLASSPATH=/usr/java/jdk1.8.0_192-amd64/lib/tools.jar:/app/wlserver/modules/features/wlst.wls.classpath.jar:\n\nPATH=/app/wlserver/server/bin:/app/wlserver/../oracle_common/modules/thirdparty/org.apache.ant/1.9.8.0.0/apache-ant-1.9.8/bin:/usr/java/jdk1.8.0_192-amd64/jre/bin:/usr/java/jdk1.8.0_192-amd64/bin:/usr/lib64/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/app/wlserver/../oracle_common/modules/org.apache.maven_3.2.5/bin\n\nYour
>  
> environment has been set.",
> "stdout_lines": [
> 
> "CLASSPATH=/usr/java/jdk1.8.0_192-amd64/lib/tools.jar:/app/wlserver/modules/features/wlst.wls.classpath.jar:"
> ,
> "",
> 
> "PATH=/app/wlserver/server/bin:/app/wlserver/../oracle_common/modules/thirdparty/org.apache.ant/1.9.8.0.0/apache-ant-1.9.8/bin:/usr/java/jdk1.8.0_192-amd64/jre/bin:/usr/java/jdk1.8.0_192-amd64/bin:/usr/lib64/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/app/wlserver/../oracle_common/modules/org.apache.maven_3.2.5/bin"
> ,
> "",
> "Your environment has been set."
> ]
> }
>
>
> From the output, I see that the classpath did get set but java 
> weblogic.version command failed on the remote host.
>
> Can you please suggest how can I get the Weblogic version registered to 
> wlsversion 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/dfe12980-de1f-4806-8548-421b49b09e9c%40googlegroups.com.


[ansible-project] Unable to print include_vars dictionary & list variables

2020-03-24 Thread Shifa Shaikh
Below is my playbook that loads and prints the variables

---
  - name: Demonstrating variables in Jinja2 Loops
hosts: localhost


  - name: Load variable files
include_vars:
  file="{{ playbook_dir }}/vars/vars.yml"


  - debug:
  msg: "COUNTRY {{ item.countries | join('') }} has IP ADDRESS {{ 
item.1 | join('') }} which has DISKs {{ item.1.disks | join('') }}"
with_subelements:
  - "{{ regions }}"
  - countries.ALL_IPS



I wish to print like below for all the entries in the vars.yml

COUNTRY CORE DUBAI has IP ADDRESS 10.0.0.1 which has DISKS /fins and /tmp
COUNTRY CORE DUBAI has IP ADDRESS 10.0.0.4 has DISKS /was
COUNTRY CORE SINGAPORE has IP ADDRESS 10.0.1.5 which has DISKS /fins and /
tmp


Below is my vars/vars.yml which is designed and works fine with my jinja2 
template where i am able to fetch all value i need from vars.yml

---
  regions:


- name: PROD
  countries:
- CORE DUBAI:
  name: CORE DUBAI
  ALL_IPS:
- 10.0.0.1:
  name: 10.0.0.1
  disks:
- /fins
- /tmp
- 10.0.0.4:
  name: 10.0.0.4
  disks:
- /was


- CORE SINGAPORE:
  name: CORE SINGAPORE
  ALL_IPS:
- 10.0.1.5:
  name: 10.0.1.5
  disks:
- /fins
- /tmp


I get the below error while running my playbook:

TASK [debug] 

fatal: [localhost]: FAILED! => {"msg": "the key countries should point to a 
dictionary, got '[{u'ALL_IPS': [{u'disks': [u'/fins', u'/tmp'], 
u'10.0.0.1': None, u'name': u'10.0.0.1'}, {u'10.0.0.4': None, u'disks': 
[u'/was'], u'name': u'10.0.0.4'}], u'name': u'fins CORE DUBAI', u'fins CORE 
DUBAI': None}, {u'ALL_IPS': [{u'disks': [u'/fins', u'/tmp'], u'name': 
u'10.0.1.5', u'10.0.1.5': None}, {u'10.0.0.4': None, u'disks': [u'/was'], 
u'name': u'10.0.0.4'}], u'fins CORE SINGAPORE': None, u'name': u'fins CORE 
SINGAPORE'}]'"}


PLAY RECAP 
**
localhost  : ok=2changed=0unreachable=0failed=1 
   skipped=0rescued=0ignored=0


Can you please suggest how can i get the desired 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/483757b2-967b-435d-a24f-afd97c8ecc47%40googlegroups.com.


[ansible-project] Getting command not found when executing using shell module

2020-03-17 Thread Shifa Shaikh
Here is my playbook:

cat test.yml

- name: Play 2
  hosts: targetserver
  tasks:

- copy: src=./centosscript.sh dest=~ mode=775
- shell: ~/centosscript.sh


Here is my shell script:

cat centosscript.sh
#/bin/ksh
grabip=`ip r | grep kernel`

I also tried 

grabip=`ifconfig | grep inet`


cat myhosts
[targetserver]
10.9.9.26

I get the following error when i run the playbook:

TASK [copy] 
*
changed: [10.9.9.26]


TASK [shell] 

fatal: [10.9.9.26]: FAILED! => {"changed": true, "cmd": "~/centosscript.sh", 
"delta": "0:00:00.122291", "end": "2020-03-17 12:18:49.485014", "msg": 
"non-zero 
return code", "rc": 1, "start": "2020-03-17 12:18:49.362723", "stderr": 
"/home/user1/centosscript.sh: 
line 2: ip: command not found", "stderr_lines": ["/home/user1/centosscript.sh: 
line 2: ip: command not found"], "stdout": "", "stdout_lines": []}


PLAY RECAP 
**
10.9.9.26 : ok=1changed=1unreachable=0failed=1 
   skipped=0rescued=0ignored=0

When i run ip r or ifconfig commands they work fine on the target server. 

Can you please help overcome this issue ?

-- 
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/0022ac55-f5e6-429c-a446-b2193939e655%40googlegroups.com.


[ansible-project] getting command not found error when using ansible shell module to execute shell script.

2020-03-17 Thread Shifa Shaikh
Here is my playbook:

cat test.yml

- name: Play 2
  hosts: targetserver
  tasks:

- copy: src=./centosscript.sh dest=~ mode=775
- shell: ~/centosscript.sh


Here is my shell script:

cat centosscript.sh
#/bin/ksh
grabip=`ip r | grep kernel`

I also tried 

grabip=`ifconfig | grep inet`


cat myhosts
[targetserver]
10.9.9.26

I get the following error when i run the playbook: 

$ ansible-playbook -i myhosts test.yml
TASK [copy] 
*
changed: [10.9.9.26]


TASK [shell] 

fatal: [10.9.9.26]: FAILED! => {"changed": true, "cmd": "~/centosscript.sh",
 "delta": "0:00:00.122291", "end": "2020-03-17 12:18:49.485014", "msg": 
"non-zero 
return code", "rc": 1, "start": "2020-03-17 12:18:49.362723", "stderr": 
"/home/user1/centosscript.sh: 
line 2: ip: command not found", "stderr_lines": ["/home/user1/centosscript.sh: 
line 2: ip: command not found"], "stdout": "", "stdout_lines": []}


PLAY RECAP 
**
10.9.9.26 : ok=1changed=1unreachable=0failed=1   
 skipped=0rescued=0ignored=0

When i run ip r or ifconfig commands they work fine on the target server. 

I need to use ksh shell. However, i get the same error even if i try 
#/bin/bash in my shell script. Below is the output of the same commands 
working fine with the ksh shell on the target server.

bash-4.2$ ksh
$ ip r | grep kernel
10.9.9.0/24 dev eth0 proto kernel scope link src 10.9.9.26 metric 100
$ ifconfig | grep inet
inet 10.9.9.26  netmask 255.255.255.0  broadcast 10.9.9.255

Can you please help overcome this issue ?

-- 
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/70ce714f-b4ba-4889-8ecc-29f60344d150%40googlegroups.com.


[ansible-project] ERROR! 'retries' is not a valid attribute for a TaskInclude

2020-05-20 Thread Shifa Shaikh
My requirement is to run the script stop-all as many times (5 retries) 
until the output of ps -fu user1 |wc -l becomes less than 2.

I wrote the below ansible playbook for the same:

cat stop.yml

  - hosts: dest_nodes
tasks:
  - name: Start service
include_tasks: "{{ playbook-dir }}/inner.yml"
retries: 5
delay: 4
until: stopprocesscount.stdout is version('2', '<')

cat inner.yml

- name: Start service
  shell: ~/stop-all
  register: stopprocess


- name: Start service
  shell: ps -fu user1 |wc -l
  register: stopprocesscount


However, I get the below error running the playbook.

ERROR! 'retries' is not a valid attribute for a TaskInclude


The error appears to be in '/app/playbook/stop.yml': line 19, column 9, but 
may
be elsewhere in the file depending on the exact syntax problem.


The offending line appears to be:


- name: Start service
  ^ here

Can you please suggest?

-- 
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/8a89923a-eebf-433a-92d7-4098c7af2b03%40googlegroups.com.


[ansible-project] Re: ERROR! 'retries' is not a valid attribute for a TaskInclude

2020-05-21 Thread Shifa Shaikh
@Stefan Our service involves a set of processes thus, the start script 
invokes those several processes and hence the need to count the number of 
processes using `wc -l` to determine if the service (not the process) is 
running or not. 

On Thursday, May 21, 2020 at 8:18:56 AM UTC+5:30, Shifa Shaikh wrote:
>
> My requirement is to run the script stop-all as many times (5 retries) 
> until the output of ps -fu user1 |wc -l becomes less than 2.
>
> I wrote the below ansible playbook for the same:
>
> cat stop.yml
>
>   - hosts: dest_nodes
> tasks:
>   - name: Start service
> include_tasks: "{{ playbook-dir }}/inner.yml"
> retries: 5
> delay: 4
> until: stopprocesscount.stdout is version('2', '<')
>
> cat inner.yml
>
> - name: Start service
>   shell: ~/stop-all
>   register: stopprocess
>
>
> - name: Start service
>   shell: ps -fu user1 |wc -l
>   register: stopprocesscount
>
>
> However, I get the below error running the playbook.
>
> ERROR! 'retries' is not a valid attribute for a TaskInclude
>
>
> The error appears to be in '/app/playbook/stop.yml': line 19, column 9, 
> but may
> be elsewhere in the file depending on the exact syntax problem.
>
>
> The offending line appears to be:
>
>
> - name: Start service
>   ^ here
>
> Can you please suggest?
>

-- 
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/4a53d56d-3e8a-4929-9cbd-b4b3d67b8237%40googlegroups.com.


[ansible-project] How to print only the failed telnet connections from my localhost

2020-06-29 Thread Shifa Shaikh
Below is my playbook that helps check telnet connections from my localhost 
to all remote hosts.

   - wait_for:

   host: "{{ item }}"

   port: 22

   state: started # Port should be open

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

   timeout: 2 # Stop checking after timeout (sec)

 ignore_errors: yes

 register: netstatoutput

 delegate_to: localhost

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


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

   - debug:

   msg: "{{ netstatoutput }}"

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

  "msg": "Timeout when waiting for 10.9.172.62:22 
"
  "msg": "Timeout when waiting for 10.9.72.66:22 
"
  "msg": "Timeout when waiting for 10.9.172.42:22 
"



Can you please suggest how can I? 

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/0c3bfb5c-333f-47dc-93a9-de1eba18bfe9o%40googlegroups.com.


[ansible-project] Add new line “\n” character to Ansible set_fact variable

2020-06-03 Thread Shifa Shaikh


How can I add new line characters to Ansible variable mailbody. This 
mailbody variable is used for mail module's body attribute.


I tried the below from suggestions but none of them works. 


1. 

  - set_fact:
   mailbody: "{{ mailbody | default('') + 'PROFILE_NAME:' +  PROFILE_NAME ~ 
'\n\nSERVER_NAME:' + SERVER_NAME ~ '\n\nNODE_NAME:' +  NODE_NAME ~ '\n\n\n\n' 
}}"

2.

  mailbody: "{{ mailbody | default('') + 'PROFILE_NAME:' +  PROFILE_NAME 
~}} {{ 'SERVER_NAME:' + SERVER_NAME ~ }}\n\n{{'NODE_NAME:' +  NODE_NAME ~ 
}}\n\n\n\n"

3.

 mailbody: | 
 "{{ mailbody | default('') + 'PROFILE_NAME:' +  PROFILE_NAME ~}}"
 "{{ 'SERVER_NAME:' + SERVER_NAME ~ }}"
 "{{'NODE_NAME:' +  NODE_NAME ~ }}"

In the mail body i see '\n' instead of the new line charecter. 

Can you please suggest ?



-- 
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/c9a4818e-dab2-4ad8-8d6c-c477e8915193%40googlegroups.com.


Re: [ansible-project] Add new line “\n” character to Ansible set_fact variable

2020-06-03 Thread Shifa Shaikh
@Dick VIsser Hi, 

Upon your suggestion, I tried something like this but it too does not work.

   - set_fact:

   mailbody: "{{ mailbody | default('') + 'PROFILE_NAME:' + 
 PROFILE_NAME ~ \"\n\n\"'SERVER_NAME:' + SERVER_NAME ~ \"\n\n\"'NODE_NAME:' 
+  NODE_NAME ~ \"\n\n\n\n\" }}"

Can someone please suggest?

On Wednesday, June 3, 2020 at 11:49:10 PM UTC+5:30, Dick Visser wrote:
>
> I won't comment on whatever it is you're trying to do, but in any case you 
> need to use double quotes around the newlines 
>
> On Wed, 3 Jun 2020 at 20:12, Shifa Shaikh > 
> wrote:
>
>> How can I add new line characters to Ansible variable mailbody. This 
>> mailbody variable is used for mail module's body attribute.
>>
>>
>> I tried the below from suggestions but none of them works. 
>>
>>
>> 1. 
>>
>>   - set_fact:
>>mailbody: "{{ mailbody | default('') + 'PROFILE_NAME:' +  
>> PROFILE_NAME ~ '\n\nSERVER_NAME:' + SERVER_NAME ~ '\n\nNODE_NAME:' +  
>> NODE_NAME ~ '\n\n\n\n' }}"
>>
>> 2.
>>
>>   mailbody: "{{ mailbody | default('') + 'PROFILE_NAME:' +  PROFILE_NAME 
>> ~}} {{ 'SERVER_NAME:' + SERVER_NAME ~ }}\n\n{{'NODE_NAME:' +  NODE_NAME ~ 
>> }}\n\n\n\n"
>>
>> 3.
>>
>>  mailbody: | 
>>  "{{ mailbody | default('') + 'PROFILE_NAME:' +  PROFILE_NAME ~}}"
>>  "{{ 'SERVER_NAME:' + SERVER_NAME ~ }}"
>>  "{{'NODE_NAME:' +  NODE_NAME ~ }}"
>>
>> In the mail body i see '\n' instead of the new line charecter. 
>>
>> Can you please suggest ?
>>
>>
>>
>> -- 
>> 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/c9a4818e-dab2-4ad8-8d6c-c477e8915193%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/c9a4818e-dab2-4ad8-8d6c-c477e8915193%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
> -- 
> Sent from a mobile device - please excuse the brevity, spelling and 
> punctuation.
>

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


Re: [ansible-project] Add new line “\n” character to Ansible set_fact variable

2020-06-03 Thread Shifa Shaikh
I tried all of these but have no clue to a solution. 

mailbody: "{{ mailbody | default('') + 'PROFILE_NAME:' +  PROFILE_NAME + 
"\n" + 'SERVER_NAME:' + SERVER_NAME + "\n" + 'NODE_NAME:' +  NODE_NAME + 
"\n\n\n\n\" }}"

mailbody: "{{ mailbody | default('') + 'PROFILE_NAME:' +  PROFILE_NAME + 
'\n' + 'SERVER_NAME:' + SERVER_NAME + '\n' + 'NODE_NAME:' +  NODE_NAME + 
'\n\n\n\n\' }}"

mailbody: "{{ mailbody | default('') + 'PROFILE_NAME:' +  PROFILE_NAME ~ }} 
\n + {{ 'SERVER_NAME:' + SERVER_NAME ~ }} + \n + {{ 'NODE_NAME:' + 
 NODE_NAME ~ }} \n\n\n\n\"


On Thursday, June 4, 2020 at 2:27:48 AM UTC+5:30, Shifa Shaikh wrote:
>
> @Dick VIsser Hi, 
>
> Upon your suggestion, I tried something like this but it too does not work.
>
>- set_fact:
>
>mailbody: "{{ mailbody | default('') + 'PROFILE_NAME:' + 
>  PROFILE_NAME ~ \"\n\n\"'SERVER_NAME:' + SERVER_NAME ~ \"\n\n\"'NODE_NAME:' 
> +  NODE_NAME ~ \"\n\n\n\n\" }}"
>
> Can someone please suggest?
>
> On Wednesday, June 3, 2020 at 11:49:10 PM UTC+5:30, Dick Visser wrote:
>>
>> I won't comment on whatever it is you're trying to do, but in any case 
>> you need to use double quotes around the newlines 
>>
>> On Wed, 3 Jun 2020 at 20:12, Shifa Shaikh  wrote:
>>
>>> How can I add new line characters to Ansible variable mailbody. This 
>>> mailbody variable is used for mail module's body attribute.
>>>
>>>
>>> I tried the below from suggestions but none of them works. 
>>>
>>>
>>> 1. 
>>>
>>>   - set_fact:
>>>mailbody: "{{ mailbody | default('') + 'PROFILE_NAME:' +  
>>> PROFILE_NAME ~ '\n\nSERVER_NAME:' + SERVER_NAME ~ '\n\nNODE_NAME:' +  
>>> NODE_NAME ~ '\n\n\n\n' }}"
>>>
>>> 2.
>>>
>>>   mailbody: "{{ mailbody | default('') + 'PROFILE_NAME:' +  
>>> PROFILE_NAME ~}} {{ 'SERVER_NAME:' + SERVER_NAME ~ }}\n\n{{'NODE_NAME:' +  
>>> NODE_NAME ~ }}\n\n\n\n"
>>>
>>> 3.
>>>
>>>  mailbody: | 
>>>  "{{ mailbody | default('') + 'PROFILE_NAME:' +  PROFILE_NAME ~}}"
>>>  "{{ 'SERVER_NAME:' + SERVER_NAME ~ }}"
>>>  "{{'NODE_NAME:' +  NODE_NAME ~ }}"
>>>
>>> In the mail body i see '\n' instead of the new line charecter. 
>>>
>>> Can you please suggest ?
>>>
>>>
>>>
>>> -- 
>>> 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/c9a4818e-dab2-4ad8-8d6c-c477e8915193%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/ansible-project/c9a4818e-dab2-4ad8-8d6c-c477e8915193%40googlegroups.com?utm_medium=email_source=footer>
>>> .
>>>
>> -- 
>> Sent from a mobile device - please excuse the brevity, spelling and 
>> punctuation.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/1515dc41-ed08-4ade-b09f-455a922497c8%40googlegroups.com.


Re: [ansible-project] Add new line “\n” character to Ansible set_fact variable

2020-06-03 Thread Shifa Shaikh
Stephan Hi, 

The article does not discuss newline inside parenthesis `{{` inside a 
variable definition. That is where I have no clue.

On Thursday, June 4, 2020 at 10:31:41 AM UTC+5:30, Stefan Hornburg (Racke) 
wrote:
>
> On 6/4/20 6:41 AM, Shifa Shaikh wrote: 
> > I tried all of these but have no clue to a solution.  
> > 
> > mailbody: "{{ mailbody | default('') + 'PROFILE_NAME:' +  PROFILE_NAME + 
> "\n" + 'SERVER_NAME:' + SERVER_NAME + "\n" + 
> > 'NODE_NAME:' +  NODE_NAME + "\n\n\n\n\" }}" 
> > 
> > mailbody: "{{ mailbody | default('') + 'PROFILE_NAME:' +  PROFILE_NAME + 
> '\n' + 'SERVER_NAME:' + SERVER_NAME + '\n' + 
> > 'NODE_NAME:' +  NODE_NAME + '\n\n\n\n\' }}" 
> > 
> > mailbody: "{{ mailbody | default('') + 'PROFILE_NAME:' +  PROFILE_NAME ~ 
> }} \n + {{ 'SERVER_NAME:' + SERVER_NAME ~ }} + 
> > \n + {{ 'NODE_NAME:' +  NODE_NAME ~ }} \n\n\n\n\" 
> > 
> > 
>
> Use multiline YAML: https://yaml-multiline.info/ 
>
> Regards 
> Racke 
>
>
> > On Thursday, June 4, 2020 at 2:27:48 AM UTC+5:30, Shifa Shaikh wrote: 
> > 
> > @Dick VIsser Hi,  
> > 
> > Upon your suggestion, I tried something like this but it too does 
> not work. 
> > 
> > | 
> >-set_fact: 
> > 
> >mailbody:"{{ mailbody | default('') + 'PROFILE_NAME:' + 
>  PROFILE_NAME ~ \"\n\n\"'SERVER_NAME:' + SERVER_NAME 
> > ~ \"\n\n\"'NODE_NAME:' +  NODE_NAME ~ \"\n\n\n\n\" }}" 
> > | 
> > 
> > Can someone please suggest? 
> > 
> > On Wednesday, June 3, 2020 at 11:49:10 PM UTC+5:30, Dick Visser 
> wrote: 
> > 
> > I won't comment on whatever it is you're trying to do, but in 
> any case you need to use double quotes around the 
> > newlines  
> > 
> > On Wed, 3 Jun 2020 at 20:12, Shifa Shaikh  
> wrote: 
> > 
> > How can I add new line characters to Ansible 
> variable |mailbody. This mailbody variable is used for mail 
> > module's body attribute.| 
> > 
> > | 
> > | 
> > 
> > I tried the below from suggestions but none of them works.  
> > 
> > 
> > |1. | 
> > 
> > |- set_fact: mailbody: "{{ mailbody | default('') + 
> 'PROFILE_NAME:' + PROFILE_NAME ~ '\n\nSERVER_NAME:' + 
> > SERVER_NAME ~ '\n\nNODE_NAME:' + NODE_NAME ~ '\n\n\n\n' }}"| 
> > 
> > |2.| 
> > 
> >   mailbody: "{{ mailbody | default('') + 'PROFILE_NAME:' 
> +  PROFILE_NAME ~}} {{ 'SERVER_NAME:' + SERVER_NAME ~ }}\n\n{{'NODE_NAME:' 
> +  NODE_NAME ~ }}\n\n\n\n" 
> > 
> > 3. 
> > 
> > |mailbody: | "{{ mailbody | default('') + 'PROFILE_NAME:' + 
> PROFILE_NAME ~}}" "{{ 'SERVER_NAME:' + 
> > SERVER_NAME ~ }}" "{{'NODE_NAME:' + NODE_NAME ~ }}"| 
> > 
> > In the mail body i see '\n' instead of the new line 
> charecter. 
> > 
> > Can you please suggest ? 
> > 
> > 
> > | 
> > | 
> > 
> > -- 
> > 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/c9a4818e-dab2-4ad8-8d6c-c477e8915193%40googlegroups.com
>  
> > <
> https://groups.google.com/d/msgid/ansible-project/c9a4818e-dab2-4ad8-8d6c-c477e8915193%40googlegroups.com?utm_medium=email_source=footer>.
>  
>
> > 
> > -- 
> > Sent from a mobile device - please excuse the brevity, spelling 
> and punctuation. 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups "Ansible Project" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an email to 
> > ansible...@googlegroups.com   ansible-project+unsubscr...@googlegroups.com >. 
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/ansible-project/1515dc41-ed08-4ade-b09f-455a922497c8%40googlegroups.com
>  
> > <
> https://groups.google.com/d/msgid/ansible-project/1515dc41-ed08-4ade-b09f-455a922497c8%40googlegroups.com?utm_medium=email_source=footer>.
>  
>
>
>
> -- 
> Ecommerce and Linux consulting + Perl and web application programming. 
> Debian and Sympa administration. Provisioning with 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/ea570673-e541-4207-81c8-84d4353b8572%40googlegroups.com.


Re: [ansible-project] Add new line “\n” character to Ansible set_fact variable

2020-06-04 Thread Shifa Shaikh
I tried multiline too as below, but that too fails

   mailbody: |
 "{{ mailbody | default('') + 'PROFILE_NAME: ' + PROFILE_NAME }}" +
"\n"
 "{{ 'SERVER_NAME: ' + SERVER_NAME }}"

Output:
['"PROFILE_NAME: SPROD01" + "[file://\\n"\n]\\n"\n"SERVER_NAME:
SPROD01SRV01"\n', '"PROFILE_NAME: SPROD02" +
"[file://\\n"\n]\\n"\n"SERVER_NAME: SPROD02SRV02"\n']

Also tried:

   mailbody: |
 "{{ mailbody | default('') + 'PROFILE_NAME: ' + PROFILE_NAME }}"
 "{{ 'SERVER_NAME: ' + SERVER_NAME }}"

and

   mailbody: |
 "{{ mailbody | default('') + 'PROFILE_NAME: ' + PROFILE_NAME }}" +
"\\n"
     "{{ 'SERVER_NAME: ' + SERVER_NAME }}"

On Thu, Jun 4, 2020 at 11:38 AM Stefan Hornburg (Racke) 
wrote:

> On 6/4/20 7:21 AM, Shifa Shaikh wrote:
> > Stephan Hi,
> >
> > The article does not discuss newline inside parenthesis `{{` inside a
> variable definition. That is where I have no clue.
>
>
> Hello Shifa,
>
> parenthesis are fine inside multiline YAML.
>
> Regards
>  Racke
>
> >
> > On Thursday, June 4, 2020 at 10:31:41 AM UTC+5:30, Stefan Hornburg
> (Racke) wrote:
> >
> > On 6/4/20 6:41 AM, Shifa Shaikh wrote:
> > > I tried all of these but have no clue to a solution.
> > >
> > > mailbody: "{{ mailbody | default('') + 'PROFILE_NAME:' +
>  PROFILE_NAME + "\n" + 'SERVER_NAME:' + SERVER_NAME + "\n" +
> > > 'NODE_NAME:' +  NODE_NAME + "\n\n\n\n\" }}"
> > >
> > > mailbody: "{{ mailbody | default('') + 'PROFILE_NAME:' +
>  PROFILE_NAME + '\n' + 'SERVER_NAME:' + SERVER_NAME + '\n' +
> > > 'NODE_NAME:' +  NODE_NAME + '\n\n\n\n\' }}"
> > >
> > > mailbody: "{{ mailbody | default('') + 'PROFILE_NAME:' +
>  PROFILE_NAME ~ }} \n + {{ 'SERVER_NAME:' + SERVER_NAME ~
> > }} +
> > > \n + {{ 'NODE_NAME:' +  NODE_NAME ~ }} \n\n\n\n\"
> > >
> > >
> >
> > Use multiline YAML: https://yaml-multiline.info/
> >
> > Regards
> > Racke
> >
> >
> > > On Thursday, June 4, 2020 at 2:27:48 AM UTC+5:30, Shifa Shaikh
> wrote:
> > >
> > > @Dick VIsser Hi,
> > >
> > > Upon your suggestion, I tried something like this but it too
> does not work.
> > >
> > > |
> > >-set_fact:
> > >
> > >mailbody:"{{ mailbody | default('') + 'PROFILE_NAME:' +
>  PROFILE_NAME ~ \"\n\n\"'SERVER_NAME:' +
> > SERVER_NAME
> > > ~ \"\n\n\"'NODE_NAME:' +  NODE_NAME ~ \"\n\n\n\n\" }}"
> > > |
> > >
> > > Can someone please suggest?
> > >
> > > On Wednesday, June 3, 2020 at 11:49:10 PM UTC+5:30, Dick
> Visser wrote:
> > >
> > > I won't comment on whatever it is you're trying to do, but
> in any case you need to use double quotes
> > around the
> > > newlines
> > >
> > > On Wed, 3 Jun 2020 at 20:12, Shifa Shaikh <
> shif...@gmail.com> wrote:
> > >
> > > How can I add new line characters to Ansible
> variable |mailbody. This mailbody variable is used for mail
> > > module's body attribute.|
> > >
> > > |
> > > |
> > >
> > > I tried the below from suggestions but none of them
> works.
> > >
> > >
> > > |1. |
> > >
> > > |- set_fact: mailbody: "{{ mailbody | default('') +
> 'PROFILE_NAME:' + PROFILE_NAME ~ '\n\nSERVER_NAME:' +
> > > SERVER_NAME ~ '\n\nNODE_NAME:' + NODE_NAME ~
> '\n\n\n\n' }}"|
> > >
> > > |2.|
> > >
> > >   mailbody: "{{ mailbody | default('') +
> 'PROFILE_NAME:' +  PROFILE_NAME ~}} {{ 'SERVER_NAME:' +
> > SERVER_NAME ~ }}\n\n{{'NODE_NAME:' +  NODE_NAME ~ }}\n\n\n\n"
> > >
> > > 3.
> > >
> > > |mailbody: | "{{ mailbody | default('') +
> 'PROFILE_NAME:' + PROFILE_NAME ~}}" "{{ 'SERVER_NAME:' +
> > > SERVER_NAME ~ }}" "{{'NODE_NAME:' + NODE_NAME ~ 

Re: [ansible-project] Add new line “\n” character to Ansible set_fact variable

2020-06-04 Thread Shifa Shaikh
I see the problem is different than the direction we are debugging. 

When i write the variable to a file i see new lines but when the variable  
assigned to email body it does not interpolate the new line instead prints 
'\n'

   - copy
content: "{{ mailbody }}"
dest: /tmp/write.log

 

- name: Send mail
  mail:
  host: localhost:
  port: 25
  subject: :Hi"
  body: "{{ mailbody }}"
  from: m...@myshop.com
  to: y...@yourmail.com

Can you please suggest?

On Thursday, June 4, 2020 at 1:26:56 PM UTC+5:30, Stefan Hornburg (Racke) 
wrote:
>
> On 6/4/20 8:54 AM, Shifa Shaikh wrote: 
> > I tried multiline too as below, but that too fails 
> > 
> >mailbody: | 
> >  "{{ mailbody | default('') + 'PROFILE_NAME: ' + PROFILE_NAME 
> }}" + "\n" 
> >  "{{ 'SERVER_NAME: ' + SERVER_NAME }}" 
> > 
>
> Please try: 
>
> mailbody: | 
>   {{ mailbody | default('') }}PROFILE_NAME: {{ PROFILE_NAME }} 
>   SERVER_NAME: + {{ SERVER_NAME }} 
>
> Regards 
>  Racke 
>
> > 
>
> > Output: 
> > ['"PROFILE_NAME: SPROD01" + "[file://\\n"\n]\\n"\n"SERVER_NAME: 
> SPROD01SRV01"\n', '"PROFILE_NAME: SPROD02" + 
> > "[file://\\n"\n]\\n"\n"SERVER_NAME: SPROD02SRV02"\n'] 
> > 
> > Also tried: 
> > 
> >mailbody: | 
> >  "{{ mailbody | default('') + 'PROFILE_NAME: ' + PROFILE_NAME 
> }}" 
> >  "{{ 'SERVER_NAME: ' + SERVER_NAME }}" 
> > 
> > and 
> > 
> >mailbody: | 
> >  "{{ mailbody | default('') + 'PROFILE_NAME: ' + PROFILE_NAME 
> }}" + "\\n" 
> >  "{{ 'SERVER_NAME: ' + SERVER_NAME }}" 
> > 
> > On Thu, Jun 4, 2020 at 11:38 AM Stefan Hornburg (Racke) <
> ra...@linuxia.de  <mailto:ra...@linuxia.de >> 
> wrote: 
> > 
> > On 6/4/20 7:21 AM, Shifa Shaikh wrote: 
> > > Stephan Hi,  
> > > 
> > > The article does not discuss newline inside parenthesis `{{` 
> inside a variable definition. That is where I have no 
> > clue. 
> > 
> > 
> > Hello Shifa, 
> > 
> > parenthesis are fine inside multiline YAML. 
> > 
> > Regards 
> >  Racke 
> > 
> > > 
> > > On Thursday, June 4, 2020 at 10:31:41 AM UTC+5:30, Stefan Hornburg 
> (Racke) wrote: 
> > > 
> > > On 6/4/20 6:41 AM, Shifa Shaikh wrote: 
> > > > I tried all of these but have no clue to a solution.  
> > > > 
> > > > mailbody: "{{ mailbody | default('') + 'PROFILE_NAME:' + 
>  PROFILE_NAME + "\n" + 'SERVER_NAME:' + SERVER_NAME 
> > + "\n" + 
> > > > 'NODE_NAME:' +  NODE_NAME + "\n\n\n\n\" }}" 
> > > > 
> > > > mailbody: "{{ mailbody | default('') + 'PROFILE_NAME:' + 
>  PROFILE_NAME + '\n' + 'SERVER_NAME:' + SERVER_NAME 
> > + '\n' + 
> > > > 'NODE_NAME:' +  NODE_NAME + '\n\n\n\n\' }}" 
> > > > 
> > > > mailbody: "{{ mailbody | default('') + 'PROFILE_NAME:' + 
>  PROFILE_NAME ~ }} \n + {{ 'SERVER_NAME:' + 
> > SERVER_NAME ~ 
> > > }} + 
> > > > \n + {{ 'NODE_NAME:' +  NODE_NAME ~ }} \n\n\n\n\" 
> > > > 
> > > > 
> > > 
> > > Use multiline YAML: https://yaml-multiline.info/ 
> > > 
> > > Regards 
> > > Racke 
> > > 
> > > 
> > > > On Thursday, June 4, 2020 at 2:27:48 AM UTC+5:30, Shifa 
> Shaikh wrote: 
> > > > 
> > > > @Dick VIsser Hi,  
> > > > 
> > > >     Upon your suggestion, I tried something like this but it 
> too does not work. 
> > > > 
> > > > | 
> > > >-set_fact: 
> > > > 
> > > >mailbody:"{{ mailbody | default('') + 
> 'PROFILE_NAME:' +  PROFILE_NAME ~ \"\n\n\"'SERVER_NAME:' + 
> > > SERVER_NAME 
> > > > ~ \"\n\n\"'NODE_NAME:' +  NODE_NAME ~ \"\n\n\n\n\" }}" 
> > > > | 
> > > > 
> > > >

Re: [ansible-project] Add new line “\n” character to Ansible set_fact variable

2020-06-04 Thread Shifa Shaikh
@Dick Hi,

That was a typo the problem remains writing to a file is all good with
newlines while writing to email body does not translate "\n" as new line !!
Could this be a bug ?

On Thu, Jun 4, 2020 at 3:37 PM Dick Visser  wrote:

> On Thu, 4 Jun 2020 at 10:50, Shifa Shaikh  wrote:
> >
> > I see the problem is different than the direction we are debugging.
> >
> > When i write the variable to a file i see new lines but when the
> variable  assigned to email body it does not interpolate the new line
> instead prints '\n'
> >
> >- copy
> > content: "{{ mailbody }}"
> > dest: /tmp/write.log
> >
> >
> >
> > - name: Send mail
> >   mail:
> >   host: localhost:
>
> There is an extra ':' here?
>
> >   port: 25
> >   subject: :Hi"
>
> There is an extra ':' here?
>
> >   body: "{{ mailbody }}"
> >   from: m...@myshop.com
> >   to: y...@yourmail.com
>
>
> > Can you please suggest?
>
> You already put two errors in your task which prevent it from running
> correctly.
> So in that light, i'm wondering if your actual task does, in fact,
> contain more differences than what you've posted here.
>
> Also, "prints '\n'" indicates that you're echoing? and not mailing?
>
>
>
> >
> > On Thursday, June 4, 2020 at 1:26:56 PM UTC+5:30, Stefan Hornburg
> (Racke) wrote:
> >>
> >> On 6/4/20 8:54 AM, Shifa Shaikh wrote:
> >> > I tried multiline too as below, but that too fails
> >> >
> >> >mailbody: |
> >> >  "{{ mailbody | default('') + 'PROFILE_NAME: ' + PROFILE_NAME
> }}" + "\n"
> >> >  "{{ 'SERVER_NAME: ' + SERVER_NAME }}"
> >> >
> >>
> >> Please try:
> >>
> >> mailbody: |
> >>   {{ mailbody | default('') }}PROFILE_NAME: {{ PROFILE_NAME }}
> >>   SERVER_NAME: + {{ SERVER_NAME }}
> >>
> >> Regards
> >>  Racke
> >>
> >> >
> >>
> >> > Output:
> >> > ['"PROFILE_NAME: SPROD01" + "[file://\\n"\n]\\n"\n"SERVER_NAME:
> SPROD01SRV01"\n', '"PROFILE_NAME: SPROD02" +
> >> > "[file://\\n"\n]\\n"\n"SERVER_NAME: SPROD02SRV02"\n']
> >> >
> >> > Also tried:
> >> >
> >> >mailbody: |
> >> >  "{{ mailbody | default('') + 'PROFILE_NAME: ' + PROFILE_NAME
> }}"
> >> >  "{{ 'SERVER_NAME: ' + SERVER_NAME }}"
> >> >
> >> > and
> >> >
> >> >mailbody: |
> >> >  "{{ mailbody | default('') + 'PROFILE_NAME: ' + PROFILE_NAME
> }}" + "\\n"
> >> >  "{{ 'SERVER_NAME: ' + SERVER_NAME }}"
> >> >
> >> > On Thu, Jun 4, 2020 at 11:38 AM Stefan Hornburg (Racke) <
> ra...@linuxia.de <mailto:ra...@linuxia.de>> wrote:
> >> >
> >> > On 6/4/20 7:21 AM, Shifa Shaikh wrote:
> >> > > Stephan Hi,
> >> > >
> >> > > The article does not discuss newline inside parenthesis `{{`
> inside a variable definition. That is where I have no
> >> > clue.
> >> >
> >> >
> >> > Hello Shifa,
> >> >
> >> > parenthesis are fine inside multiline YAML.
> >> >
> >> > Regards
> >> >  Racke
> >> >
> >> > >
> >> > > On Thursday, June 4, 2020 at 10:31:41 AM UTC+5:30, Stefan
> Hornburg (Racke) wrote:
> >> > >
> >> > > On 6/4/20 6:41 AM, Shifa Shaikh wrote:
> >> > > > I tried all of these but have no clue to a solution.
> >> > > >
> >> > > > mailbody: "{{ mailbody | default('') + 'PROFILE_NAME:' +
> PROFILE_NAME + "\n" + 'SERVER_NAME:' + SERVER_NAME
> >> > + "\n" +
> >> > > > 'NODE_NAME:' +  NODE_NAME + "\n\n\n\n\" }}"
> >> > > >
> >> > > > mailbody: "{{ mailbody | default('') + 'PROFILE_NAME:' +
> PROFILE_NAME + '\n' + 'SERVER_NAME:' + SERVER_NAME
> >> > + '\n' +
> >> > > > 'NODE_NAME:' +  NODE_NAME + '\n\n\n\n\' }}&qu

Re: [ansible-project] Add new line “\n” character to Ansible set_fact variable

2020-06-04 Thread Shifa Shaikh
Dick Hi,

That was a typo; however, the problem remains!! Writing to a file is all
good with newline while writing to email body does not translate "\n" as
new line !! Could this be a bug? Kindly suggest.

On Thu, Jun 4, 2020 at 3:37 PM Dick Visser  wrote:

> On Thu, 4 Jun 2020 at 10:50, Shifa Shaikh  wrote:
> >
> > I see the problem is different than the direction we are debugging.
> >
> > When i write the variable to a file i see new lines but when the
> variable  assigned to email body it does not interpolate the new line
> instead prints '\n'
> >
> >- copy
> > content: "{{ mailbody }}"
> > dest: /tmp/write.log
> >
> >
> >
> > - name: Send mail
> >   mail:
> >   host: localhost:
>
> There is an extra ':' here?
>
> >   port: 25
> >   subject: :Hi"
>
> There is an extra ':' here?
>
> >   body: "{{ mailbody }}"
> >   from: m...@myshop.com
> >   to: y...@yourmail.com
>
>
> > Can you please suggest?
>
> You already put two errors in your task which prevent it from running
> correctly.
> So in that light, i'm wondering if your actual task does, in fact,
> contain more differences than what you've posted here.
>
> Also, "prints '\n'" indicates that you're echoing? and not mailing?
>
>
>
> >
> > On Thursday, June 4, 2020 at 1:26:56 PM UTC+5:30, Stefan Hornburg
> (Racke) wrote:
> >>
> >> On 6/4/20 8:54 AM, Shifa Shaikh wrote:
> >> > I tried multiline too as below, but that too fails
> >> >
> >> >mailbody: |
> >> >  "{{ mailbody | default('') + 'PROFILE_NAME: ' + PROFILE_NAME
> }}" + "\n"
> >> >  "{{ 'SERVER_NAME: ' + SERVER_NAME }}"
> >> >
> >>
> >> Please try:
> >>
> >> mailbody: |
> >>   {{ mailbody | default('') }}PROFILE_NAME: {{ PROFILE_NAME }}
> >>   SERVER_NAME: + {{ SERVER_NAME }}
> >>
> >> Regards
> >>  Racke
> >>
> >> >
> >>
> >> > Output:
> >> > ['"PROFILE_NAME: SPROD01" + "[file://\\n"\n]\\n"\n"SERVER_NAME:
> SPROD01SRV01"\n', '"PROFILE_NAME: SPROD02" +
> >> > "[file://\\n"\n]\\n"\n"SERVER_NAME: SPROD02SRV02"\n']
> >> >
> >> > Also tried:
> >> >
> >> >mailbody: |
> >> >  "{{ mailbody | default('') + 'PROFILE_NAME: ' + PROFILE_NAME
> }}"
> >> >  "{{ 'SERVER_NAME: ' + SERVER_NAME }}"
> >> >
> >> > and
> >> >
> >> >mailbody: |
> >> >  "{{ mailbody | default('') + 'PROFILE_NAME: ' + PROFILE_NAME
> }}" + "\\n"
> >> >  "{{ 'SERVER_NAME: ' + SERVER_NAME }}"
> >> >
> >> > On Thu, Jun 4, 2020 at 11:38 AM Stefan Hornburg (Racke) <
> ra...@linuxia.de <mailto:ra...@linuxia.de>> wrote:
> >> >
> >> > On 6/4/20 7:21 AM, Shifa Shaikh wrote:
> >> > > Stephan Hi,
> >> > >
> >> > > The article does not discuss newline inside parenthesis `{{`
> inside a variable definition. That is where I have no
> >> > clue.
> >> >
> >> >
> >> > Hello Shifa,
> >> >
> >> > parenthesis are fine inside multiline YAML.
> >> >
> >> > Regards
> >> >  Racke
> >> >
> >> > >
> >> > > On Thursday, June 4, 2020 at 10:31:41 AM UTC+5:30, Stefan
> Hornburg (Racke) wrote:
> >> > >
> >> > > On 6/4/20 6:41 AM, Shifa Shaikh wrote:
> >> > > > I tried all of these but have no clue to a solution.
> >> > > >
> >> > > > mailbody: "{{ mailbody | default('') + 'PROFILE_NAME:' +
> PROFILE_NAME + "\n" + 'SERVER_NAME:' + SERVER_NAME
> >> > + "\n" +
> >> > > > 'NODE_NAME:' +  NODE_NAME + "\n\n\n\n\" }}"
> >> > > >
> >> > > > mailbody: "{{ mailbody | default('') + 'PROFILE_NAME:' +
> PROFILE_NAME + '\n' + 'SERVER_NAME:' + SERVER_NAME
> >> > + '\n' +
> >> > > > 'NODE_NAME:' +  NODE_NAME + '\n\n\n\n\' }}&qu

[ansible-project] Check if passwordless ssh works after checking telnet from localhost

2020-07-27 Thread Shifa Shaikh
I wish to list down all the hosts where it first checks for working telnet 
on port 22. If telnet succeeds; it should check for passwordless ssh and 
list down all hosts where telnet works but passwordless ssh fails.

The below playbook helps with the first part of checking all hosts where 
telnet works. 

 - name: Play 2- check telnet nodes

  hosts: localhost
  user: axmwapp
  vars:
ansible_ssh_extra_args: -o StrictHostKeyChecking=no
ansible_ssh_private_key_file: /app/axmw_id_rsa
  tasks:


   - name: Check all port numbers are accessible from current host
 include_tasks: /app/checkssh/innertelnet.yml
 with_items: "{{ groups['all_hosts'] }}"

cat /app/checkssh/innertelnet.yml

---
   - wait_for:
   host: "{{ item }}"
   port: 22
   state: started
   delay: 0
   timeout: 2
 ignore_errors: yes
 register: netstatoutput
 delegate_to: localhost

   - set_fact:
   telnetcheck: "{% if netstatoutput.failed == 'False' %} 'OPEN' {% 
else %} 'BLOCKED' {% endif %}"
 when: "{{ netstatoutput.failed }}"

   - debug:
   msg: "Telnet works on {{ item }}"
 when: not netstatoutput.failed

>From the above successful telnet IPs, I wish to check & report hosts where 
>passwordless ssh fails. But, I'm not sure how-to ?

I tried the below but it becomes interactive and prompts for a password rather 
than checking all seccessful telnet hosts for passwordless ssh. 

   - name: Check ssh connectivity
 raw: "ssh -i {{ ansible_ssh_private_key_file }} root@{{ item }} echo 
success"
 register: sshcheck
 delegate_to: localhost
 when: not netstatoutput.failed

   - set_fact:
   sshcheck: "Telnet Works but SSH Fails"
 when: not netstatoutput.failed and sshcheck.rc != 0

   - debug:
   msg: "INNERSSH: {{ sshcheck }}"

 when: not netstatoutput.failed and sshcheck.rc != 0 

Can you please guide?


-- 
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/f5be0db5-134d-4bab-b9c0-c56b2feb2387o%40googlegroups.com.