[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.


Re: [ansible-project] Jinja2 iterate over strings and lists

2020-03-06 Thread Vladimir Botka
On Fri, 6 Mar 2020 09:15:51 -0800 (PST)
Quentin Aveno  wrote:

> - name: test
>   vars:
> test1: "test1"
> test2:
>   - "test21"
>   - "test22"
> test3:
>  - "{{ test1 }}"
>  - "{{ test2 }}" 
>   
>   debug:
> msg: "{% for tt in test3 %} {{ tt }} {% endfor %}"
> 
> Is there a way to flatten the list into à list of strings with a filter ? 

Use filter "flatten". For example

- debug:
msg: "{{ test3|flatten }}"

should give

"msg": [
"test1", 
"test21", 
"test22"
]

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/20200306235028.1f45034f%40gmail.com.


pgpBNY9KT_45i.pgp
Description: OpenPGP digital signature


[ansible-project] Re: Need win_shell to run with elevated privileges

2020-03-06 Thread Jordan Borean
As I mentioned in that issue the processes run from Ansible with the 
highest privileges available to the user you can verify this by running

- win_command: whoami.exe /all

Here is what you should roughly see back

(ansible-py37) jborean:~/dev/ansible-tester$ ansible 2019 -m win_command -a 
'whoami.exe 
/all'
[WARNING]: You are running the development version of Ansible. You should 
only run Ansible from "devel" if you are modifying the Ansible engine, or 
trying out features under development. This is a rapidly
changing source of code and can become unstable at any point.
2019 | CHANGED | rc=0 >>

USER INFORMATION


User Name SID  
= =
domain\vagrant-domain S-1-5-21-2959096244-3298113601-420842770-1104


GROUP INFORMATION
-

Group NameType SID 
 Attributes 

=  
 
===
Everyone  Well-known group S-1-1-0 
 Mandatory group, Enabled by default, 
Enabled group 
BUILTIN\Performance Log Users AliasS-1-5-32-559 
Mandatory group, Enabled by default, Enabled 
group 
BUILTIN\Users AliasS-1-5-32-545 
Mandatory group, Enabled by default, Enabled 
group 
BUILTIN\AdministratorsAliasS-1-5-32-544 
Mandatory group, Enabled by default, Enabled 
group, Group owner
NT AUTHORITY\NETWORK  Well-known group S-1-5-2 
 Mandatory group, Enabled by default, 
Enabled group 
NT AUTHORITY\Authenticated Users  Well-known group S-1-5-11 
Mandatory group, Enabled by default, Enabled 
group 
NT AUTHORITY\This OrganizationWell-known group S-1-5-15 
Mandatory group, Enabled by default, Enabled 
group 
DOMAIN\Domain Admins  GroupS-1-5-21-
2959096244-3298113601-420842770-512 Mandatory group, Enabled by default, 
Enabled group 
Authentication authority asserted identityWell-known group S-1-18-1 
Mandatory group, Enabled by default, Enabled 
group 
DOMAIN\Denied RODC Password Replication Group AliasS-1-5-21-
2959096244-3298113601-420842770-572 Mandatory group, Enabled by default, 
Enabled group, Local Group
Mandatory Label\High Mandatory Level  LabelS-1-16-12288 

   


PRIVILEGES INFORMATION
--

Privilege NameDescription   
 State  
= 
== ===
SeAssignPrimaryTokenPrivilege Replace a process level token 
 Enabled
SeIncreaseQuotaPrivilege  Adjust memory quotas for a 
process Enabled
SeSecurityPrivilege   Manage auditing and security log 
  Enabled
SeTakeOwnershipPrivilege  Take ownership of files or other 
objects   Enabled
SeLoadDriverPrivilege Load and unload device drivers   
  Enabled
SeSystemProfilePrivilege  Profile system performance   
  Enabled
SeSystemtimePrivilege Change the system time   
  Enabled
SeProfileSingleProcessPrivilege   Profile single process   
  Enabled
SeIncreaseBasePriorityPrivilege   Increase scheduling priority 
  Enabled
SeCreatePagefilePrivilege Create a pagefile 
 Enabled
SeBackupPrivilege Back up files and directories 
 Enabled
SeRestorePrivilegeRestore files and directories 
 Enabled
SeShutdownPrivilege   Shut down the system 
  Enabled
SeDebugPrivilege

[ansible-project] Need win_shell to run with elevated privileges

2020-03-06 Thread Arielle Adams
Hi,
I'm unable to get win_shell to run with elevated "run as admin" privileges. 
I have the details posted below in this issue:

https://github.com/ansible/ansible/issues/68086

As stated, I tried to see if it could be a double hop issue by adding the 
become logic but this did not work. The script runs perfectly locally, just 
need to automate this using ansible.
If anyone has any idea as to why this isn't working properly I'd greatly 
appreciate it.

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


Re: [ansible-project] Retrieving a document to a unique name?

2020-03-06 Thread Mike Eggleston
Thank you. That’s what I needed. 

Mike

> On Mar 2, 2020, at 19:07, Vladimir Botka  wrote:
> 
> On Mon, 2 Mar 2020 14:41:28 -0600
> Mike Eggleston  wrote:
> 
>> I will write a program that looks for network devices on its local network
>> and created a report of the findings. That’s easy. Using Ansible to push
>> out the program and execute the program is easy. But how do I pull the
>> report back to a unique name? For example the report is created
>> as /tmp/report. I want to pull that file back to a file
>> named /tmp/report-network.txt. What module do I use to pullback the file?
>> The fetch module?
> 
> "fetch" module is a good choice to pull the report back to a unique name. The
> unique name will be automatically created by the module. Quoting:
> 
>  "...default behavior of appending hostname/path/to/file to the
>  destination ... retrieving files that are uniquely named per host."
> 
> This behaviour can be switched off by "flat: true".
> https://docs.ansible.com/ansible/latest/modules/fetch_module.html#parameters
> 
> 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/01FAE291-7473-4130-9ACD-0EA80294DDFE%40gmail.com.


[ansible-project] Jinja2 iterate over strings and lists

2020-03-06 Thread Quentin Aveno
Hi guys,
I got a question concerning list of lists and strings. 

I have something like :
- name: test
  vars:
test1: "test1"
test2:
  - "test21"
  - "test22"
test3:
 - "{{ test1 }}"
 - "{{ test2 }}" 
  
  debug:
msg: "{% for tt in test3 %} {{ tt }} {% endfor %}"

Is there a way to flatten the list into à list of strings with a filter ? 

-- 
You received this message because you are 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/0644c01e-f33e-4736-baaa-640f9b63b017%40googlegroups.com.


[ansible-project] Re: Unable to access variables from host_vars dir however can access the same variables when specified in roles/defaults/mail.yml

2020-03-06 Thread klingac
Are you using `--limit` param for ansible-playbook?

Dne středa 4. března 2020 14:49:44 UTC+1 Vishal Bobade napsal(a):
>
>
> TASK [ansible-manage-lvm : manage_lvm | creating new LVM volume group(s)] 
> **
>  [0;31mfatal: [grafana]: FAILED! => {"msg": "'config_lv_name' is undefined"} 
> [0m
>  [0;31m [0m
>
>
>
>
>
> I am gettin the above error when I am trying to create and procure lvm 
> stuff on my new environment. I want to mention all the variables as a part 
> of host_vars like below:
>
> # lvm variablesvg_name: "VolGroup01"config_lv_name: "LogVol10"data_lv_name: 
> "LogVol11"lvm_disk_name: "/dev/nvme2n1"config_mntp: "/opt/tools"data_mntp: 
> "/data"config_lv_size: "50G"data_lv_size: "100G"
>
>
>
> I am trying to use them as below :
>
>
> lvm_groups:  - vgname: "{{ vg_name }}"disks:   - "{{ 
> lvm_disk_name }}"create: truelvnames:  - lvname: "{{ 
> config_lv_name }}"size: "{{ config_lv_size }}"create: 
> true  ## Mention "false" in case of lvm removalfilesystem: xfs
> mount: truemntp: "{{ config_mntp }}"  
> - lvname: "LogVol11"size: "{{ data_lv_size }}"create: 
> true  ## Mention "false" in case of lvm removalfilesystem: xfs
> mount: truemntp: "{{ data_mntp }}"manage_lvm: true
>
>
>
>
>
>
>
>
>
>
>
>
>
> On Wednesday, March 4, 2020 at 7:10:36 PM UTC+5:30, Sagar Mujumale wrote:
>>
>> Whats the problem? where do you stuck. Please post more information.
>>
>> On Wednesday, 4 March 2020 18:54:29 UTC+5:30, Vishal Bobade wrote:
>>>
>>> I have created multiple inventory files specific to dev , qa etc env. 
>>> under inventory dir.
>>>
>>> inventory/dev.domain.net.yml 
>>>
>>> Any suggestions, would help as I am stucked here..
>>>
>>>
>>>

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


[ansible-project] Re: Calling powershell function via Ansible

2020-03-06 Thread Jesse Lyon
Thanks for the note on the "Become" double hop snafu's, found another post 
from a year or so ago where you helped someone else with resolving their 
become issues and used that to muddle through it myself.

solution 

  - name: Create DFS links
win_shell: |
  . C:\scripts\USERNAME\dfsadd_func.ps1


  dfsadd -junction "{{ vol_junction }}" -obj_name "{{ obj_name }}" 
-prd_vserver 
"{{ prd_vserver }}" -dr_vserver "{{ dr_vserver }}" -prd_state "{{ prd_state 
}}" -dr_state "{{ dr_state }}"
become: yes
become_method: runas
become_user: "userna...@domain.net"

I really appreciate the assist.

On Thursday, March 5, 2020 at 5:05:13 PM UTC-5, Jesse Lyon wrote:
>
> Jordan,
>
> The methodology I was following was "if it worked through ise, why's this 
> not pass it properly?", I knew I was doing something wrong, I just didn't 
> know what yet.
>
> I'll give this a shot in the morning and report back.
>
> After 12 punches on the card of "Jordan saves the day" do you earn a 
> prize? 
>
>

-- 
You received this message because you are 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/d2bca78b-f3bc-4c90-8645-113438df0b43%40googlegroups.com.


[ansible-project] Help on Ansible gcp_compute_snapshot module

2020-03-06 Thread FRANK L
Hi Ansible helpers,

Could someone help on how to use the Ansible gcp_compute_snapshot module?

I created an Ansible playbook as bollow but ran into one error during the 
snapshot on SUSE 12.3.  The error was "fatal: [patchtest03]: FAILED! => 
{"changed": false, "msg": "argument source_disk is of type  
and we were unable to convert to dict:  cannot be converted to 
a dict"}
"

The more detailed Ansible gcp_compute_snapshot module can be found: 

https://docs.ansible.com/ansible/latest/modules/gcp_compute_snapshot_module.html

Thanks a lot in advance.

Frank

---
- hosts: snapshots_test
  become: yes
  vars:
disks:
  - patchtest03

  tasks:

- name: create a snapshot
  gcp_compute_snapshot:
 name: Testing snapshots for patchtest03
 source_disk: "{{ disks }}"
 zone: us-central1-a
 labels:
   my_label: value
 project: np-sapcar
 auth_kind: serviceaccount
 service_account_file: 
"/home/ansible/managed_files/np-sap-json/np-sapcar-483f5968b671.json"
 state: present

-

PLAY [snapshots_test] 
*

TASK [Gathering Facts] 

[WARNING]: Platform linux on host patchtest03 is using the discovered 
Python interpreter at /usr/bin/python, but future installation
of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html
 
for more information.

ok: [patchtest03]

TASK [create a snapshot] 
**
skipping: [patchtest03]

PLAY RECAP 

patchtest03: ok=1changed=0unreachable=0
failed=0skipped=1rescued=0ignored=0

[ansible@npcaradmin01 playbooks]$ ansible-playbook snapshot_backups.yml

PLAY [snapshots_test] 
*

TASK [Gathering Facts] 

[WARNING]: Platform linux on host patchtest03 is using the discovered 
Python interpreter at /usr/bin/python, but future installation
of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html
 
for more information.

ok: [patchtest03]

TASK [create a snapshot] 
**
fatal: [patchtest03]: FAILED! => {"changed": false, "msg": "argument 
source_disk is of type  and we were unable to convert to dict: 
 cannot be converted to a dict"}

PLAY RECAP 

patchtest03: ok=1changed=0unreachable=0
failed=1skipped=0rescued=0ignored=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/fbc6d9df-11d2-46af-b216-07d4243aa7dc%40googlegroups.com.


[ansible-project] Re: Using vars_files

2020-03-06 Thread 'Brandon Daly' via Ansible Project
I have this working.

I've a role that configs the L3VPN, so I created two tasks within that 
role. One loads the vars, and the other produces the router configuration.

roles/config_l3vpn/tasks/load.yml
---
- name: include vars
  include_vars: ./host_vars/{{ inventory_hostname }}/engendered_l3vpn.yaml


roles/config_l3vpn/tasks/build.yml
---
- name: Building VPN configuration
  template: >
src=config_l3vpn.conf.j2
dest={{ build_dir }}/junos-l3vpn.conf.part

roles/config_l3vpn/tasks/main.yaml
---
- include: load.yml
- include: build.yml



On Friday, 6 March 2020 14:05:16 UTC, Brandon Daly wrote:
>
> I have a play that is creating yaml for each of my hosts and this is 
> stored in './host_vars/{{ inventory_hostname }}/l3vpn.yml
>
> I then have a second play in which I wish to use this yaml.   
>
> both are called from another playbook;
>
>
> [ansible@ansi001 juniper]$ more live.all.pb.yam
> ---
> - import_playbook: make_clean.p.yaml
> - import_playbook: l3vpnconf.p.yaml  < this one creates the per 
> host yaml
> - import_playbook: createconfig.p.yaml< this one 
> attempt to use them
> - import_playbook: assemble_and_commit.p.yaml
>
>
>
>
> In createconfigp.p.yaml I've attempted to access the l3vpn yaml using;
>
>   vars_files:
> - ./host_vars/{{ inventory_hostname }}/engendered_l3vpn.yml
>
> but this produces the error 'ERROR! vars file ./host_vars/{{ 
> inventory_hostname }}/l3vpn.yml was not found'
>
> Is it possible to create yaml per host in one play and have the second 
> play use the yaml?
>
>
>
>

-- 
You received this message because you are 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/3c76ef5b-e606-401c-a73e-fa5e07876448%40googlegroups.com.


Re: [ansible-project] Using vars_files

2020-03-06 Thread Stefan Hornburg (Racke)
On 3/6/20 3:05 PM, 'Brandon Daly' via Ansible Project wrote:
> I have a play that is creating yaml for each of my hosts and this is stored 
> in './host_vars/{{ inventory_hostname
> }}/l3vpn.yml
> 
> I then have a second play in which I wish to use this yaml.   
> 
> both are called from another playbook;
> 
> 
> [ansible@ansi001 juniper]$ more live.all.pb.yam
> ---
> - import_playbook: make_clean.p.yaml
> - import_playbook: l3vpnconf.p.yaml          < this one creates the per host 
> yaml
> - import_playbook: createconfig.p.yaml                        < this one 
> attempt to use them
> - import_playbook: assemble_and_commit.p.yaml
> 
> 
> 
> 
> In createconfigp.p.yaml I've attempted to access the l3vpn yaml using;
> 
>   vars_files:
>     - ./host_vars/{{ inventory_hostname }}/engendered_l3vpn.yml
> 
> but this produces the error 'ERROR! vars file ./host_vars/{{ 
> inventory_hostname }}/l3vpn.yml was not found'
> 
> Is it possible to create yaml per host in one play and have the second play 
> use the yaml?

I suppose you need to wrap it in "" to evaluate it as Jinja template:

- "./host_vars/{{ inventory_hostname }}/engendered_l3vpn.yml"

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-project+unsubscr...@googlegroups.com 
> .
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/326e4b45-cf15-4c29-9e10-d194b3c4d2f3%40googlegroups.com
> .


-- 
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/65ce8821-df06-fa79-394a-45a3594c9484%40linuxia.de.


signature.asc
Description: OpenPGP digital signature


[ansible-project] Using vars_files

2020-03-06 Thread 'Brandon Daly' via Ansible Project
I have a play that is creating yaml for each of my hosts and this is stored 
in './host_vars/{{ inventory_hostname }}/l3vpn.yml

I then have a second play in which I wish to use this yaml.   

both are called from another playbook;


[ansible@ansi001 juniper]$ more live.all.pb.yam
---
- import_playbook: make_clean.p.yaml
- import_playbook: l3vpnconf.p.yaml  < this one creates the per 
host yaml
- import_playbook: createconfig.p.yaml< this one 
attempt to use them
- import_playbook: assemble_and_commit.p.yaml




In createconfigp.p.yaml I've attempted to access the l3vpn yaml using;

  vars_files:
- ./host_vars/{{ inventory_hostname }}/engendered_l3vpn.yml

but this produces the error 'ERROR! vars file ./host_vars/{{ 
inventory_hostname }}/l3vpn.yml was not found'

Is it possible to create yaml per host in one play and have the second play 
use the yaml?



-- 
You received this message because you are 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/326e4b45-cf15-4c29-9e10-d194b3c4d2f3%40googlegroups.com.


Re: [ansible-project] Ansible Split JSON Return

2020-03-06 Thread David Foley


On Thursday, March 5, 2020 at 8:48:12 PM UTC, Kai Stian Olstad wrote:
>
> On 05.03.2020 15:52, David Foley wrote: 
> > Have the Following Playbook Which Returns the following 
> > 
> > ok: [localhost] => { 
> > "mdb.json": [ 
>
> The [ is telling us that mdb.json is a list, the fist element in a list 
> i 0. 
>
> > { 
> > "mac-address": "xx:xx:xx:xx:xx" 
> > } 
> > ] 
> > } 
>
>  
>
> >   - debug: 
> >   msg: "{{ mdb.json.split(':') }}" 
> > 
> > What i would like to Return is just 
> > 
> >  "msg":  "xx:xx:xx:xx:xx" 
>
> That would be {{ mdb.json.0['mac-address'] }} 
>
> because of the dash in mac-address you need to use [] notation and not 
> the dot notation on that one. 
>
>
> -- 
> Kai Stian Olstad 
>

Thanks Kai,

that worked i was also able to Split('-')[0] and that only outputted the 
xxx:xxx:xxx:xx just what i was looking for.  

-- 
You received this message because you are 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/6ada225d-044c-41d8-9def-a2add77d7b48%40googlegroups.com.


Re: [ansible-project] Ansible "failed_when" not working as desired

2020-03-06 Thread Dick Visser
Why not use the uri module instead of fragile shell + curl ?

On Fri, 6 Mar 2020 at 13:47, Rakesh Parida 
wrote:

> Hi,
>
> I have a task as follows:
>
> - hosts: nodes
>   gather_facts: true
>   tasks:
> - name: CurlCP Status
>   shell: "curl -Is -m 1 http://localhost:9113/cp/healthcheck;
>   register: cp_status
>   failed_when: "'200 OK' not in cp_status.stdout_lines"
>
> It fails even if 200 Ok is in o/p. I want to fail the job only when 200 OK
> is not in o/p
> Pls help here
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/6589d432-2ae7-4fcb-a7ba-926cfb3f2a17%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/CAL8fbwPg1U9ZKz3YiDf%3Dra1ArqOYgnhFym7HxzXW2h2pYRYU0g%40mail.gmail.com.


Re: [ansible-project] Ansible "failed_when" not working as desired

2020-03-06 Thread Vladimir Botka
On Fri, 6 Mar 2020 04:46:58 -0800 (PST)
Rakesh Parida  wrote:

>   failed_when: "'200 OK' not in cp_status.stdout_lines"

Try

 failed_when: cp_status.stdout_lines|
  select('search', '200 OK')|
  list|
  length == 0

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/20200306142546.1469fcfc%40gmail.com.


pgpo_Gtp9BOB1.pgp
Description: OpenPGP digital signature


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

2020-03-06 Thread Stefan Hornburg (Racke)
On 3/6/20 1:35 PM, Shifa Shaikh wrote:
> I know how to lookup a file using fileglob in Ansible but not sure how to 
> inside a Jinja template.
> 

Very simple:

{% if lookup('fileglob', '/home/racke/tmp/*.txt') %}

Regards
Racke

> 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),  
> >> 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
> >     >     
> >     >      >     >
> >     >     >
> >     >     >
> >     >     > --
> >     >     > You received this message because you are 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] Ansible "failed_when" not working as desired

2020-03-06 Thread Rakesh Parida
Hi,

I have a task as follows:

- hosts: nodes
  gather_facts: true
  tasks:
- name: CurlCP Status
  shell: "curl -Is -m 1 http://localhost:9113/cp/healthcheck;
  register: cp_status
  failed_when: "'200 OK' not in cp_status.stdout_lines"

It fails even if 200 Ok is in o/p. I want to fail the job only when 200 OK 
is not in o/p
Pls help here

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/6589d432-2ae7-4fcb-a7ba-926cfb3f2a17%40googlegroups.com.


Re: [ansible-project] Ansible 2.8 hanging with bash command

2020-03-06 Thread Stefan Hornburg (Racke)
On 3/5/20 6:31 PM, John wrote:
> I have a task that searches logs for specific errors in various logs (up to 7 
> days worth of logs).  When searching
> through just one log I never had an issue, but when searching through the 7 
> logs (used a wildcard to accomplish this),
> sometimes Ansible goes to lunch and doesn't recover.  It just sits there like 
> it is still executing.  We have let it run
> for many hours in that state just to make sure.  I think it has a lot to do 
> with timing and/or the size of the files
> (and the number of errors found int he files).  Wondering if there is a more 
> robust way to address this so that it will
> either not hang, continue on after a certain point (maybe a 5 minute timeout) 
> or be more efficient (such as searching
> logs and writing to a file with an ansible module I don't know of)?  
> 
> |
> - name: Gather error reports
>   shell: |
>           while read line; do
>             grep -i "$line" "{{ log_source }}"* | uniq  > "{{ dest_dir }}/{{ 
> ansible_hostname }}-$line.txt"
>           done < "{{ error_log }}"
>   failed_when: false
>   args:
>     executable: /bin/bash
> |
> 

I would recommend to use a dedicated tool such as logwatch.

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-project+unsubscr...@googlegroups.com 
> .
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/af6c88f5-5270-4c57-839e-0205547b31b7%40googlegroups.com
> .


-- 
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/088915f2-de9d-0005-93c1-19fbca19ed61%40linuxia.de.


signature.asc
Description: OpenPGP digital signature


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),  > 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
> > > 
> > >  > >
> > > >
> > > >
> > > > --
> > > > You received this message because you are 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...@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. 

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

2020-03-06 Thread Stefan Hornburg (Racke)
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),  > 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 mailto: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
> >     
> >      >
> >     >
> >     >
> >     > --
> >     > You received this message because you are 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/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com
> >     
> 
> >     >
> >   
>  
>  >   
>  
> >.
> >
> >
> >
> >     --
> >     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 
> 

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>>
> > >
> > >
> > > --
> > > You received this message because you are 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+unsubscr...@googlegroups.com  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
> > <
> https://groups.google.com/d/msgid/ansible-project/d22c2c58-3d3c-4cb6-8119-662a1a2e52ea%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/a7f0c40f-a98e-58e2-c659-c10b283bddf0%40linuxia.de
> .
>

-- 
You received this message because you 

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

2020-03-06 Thread Stefan Hornburg (Racke)
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
> 
>  >
> >
> >
> > --
> > You received this message because you are 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/e2c31593-0389-4c5d-9bbb-9f29e528a832%40googlegroups.com
> 
> 
> >
> 
>  
> >.
> 
> 
> 
> -- 
> 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
> .


-- 
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/a7f0c40f-a98e-58e2-c659-c10b283bddf0%40linuxia.de.


signature.asc
Description: OpenPGP digital signature


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
@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] Getting a message if register failed inside a task

2020-03-06 Thread דודו דודו
Thank you for your answer.  So basically I need to run 2 tasks *BUT*

If I have a list of folders that needs to be created and i will use 
with_items  - As I know, the first task will run on all folders and the MSG 
task will only verify the register of the last folder. 

Basically what I'm askingת is there a way to run 2 tasks (one by one) on 
the same item and not running each task in parallel for all items  


On Friday, March 6, 2020 at 8:55:34 AM UTC+2, Vladimir Botka wrote:
>
> On Thu, 5 Mar 2020 22:09:49 -0800 (PST) 
> דודו דודו > wrote: 
>
> > I have a task that create a folder on HDFS storage. 
> > If the folder exists I wish to show a message 
> > 
> > - hosts: gw 
> >   become: true 
> >   become_user: hdfs 
> >   tasks: 
> >- name: create folder in HDFS 
> >  shell: hadoop dfs -mkdir /tmp/dudu 
> >  ignore_errors: yes 
> >  register: result 
> >  when: result is failed 
> >  fail: 
> >msg: folder exists 
>
> It's not possible to use two modules (shell and fail) in one task. There 
> are 
> couple of scenarios how to handle this case. 
>
> 1) Show a message and fail (fatal) 
>
>tasks: 
> - name: create folder in HDFS 
>   command: hadoop dfs -mkdir /tmp/dudu 
>   ignore_errors: yes 
>   register: result 
> - fail: 
> msg: folder exists 
>   when: result is failed 
>
> 2) Show a message and continue 
>
>tasks: 
> - name: create folder in HDFS 
>   command: hadoop dfs -mkdir /tmp/dudu 
>   ignore_errors: yes 
>   register: result 
> - debug: 
> msg: folder exists 
>   when: result is failed 
>
> 3) Execute the command if the folder does not exist else skip the command, 
>show a message and continue. Optionally change "debug" to "fail". 
>
>tasks: 
> - name: create folder in HDFS 
>   command: 
> cmd: hadoop dfs -mkdir /tmp/dudu 
> creates: /tmp/dudu 
>   ignore_errors: yes 
>   register: result 
> - debug: 
> msg: "{{ result.stdout }}" 
>   when: not result.changed 
>
> Next options would be to use "block". See "Error Handling In Playbooks" 
>
> https://docs.ansible.com/ansible/latest/user_guide/playbooks_error_handling.html#error-handling-in-playbooks
>  
>
> As a sidenote, quoting from "shell – Execute shell commands on targets" 
> https://docs.ansible.com/ansible/latest/modules/shell_module.html#notes 
>
>   "If you want to execute a command securely and predictably, it may be 
>   better to use the command module instead. Best practices when writing 
>   playbooks will follow the trend of using command unless the shell module 
> is 
>   explicitly required..." 
>
> quoting from "command – Execute commands on targets" 
> https://docs.ansible.com/ansible/latest/modules/command_module.html#notes 
>
>   "If you want to run a command through the shell (say you are using <, >, 
> |, 
>   etc), you actually want the shell module instead. Parsing shell 
>   metacharacters can lead to unexpected commands being executed if quoting 
> is 
>   not done correctly so it is more secure to use the command module when 
>   possible." 
> -- 
>
> 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/7ded6e47-12f5-48fd-826f-63f7bd882a12%40googlegroups.com.


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

2020-03-06 Thread Stefan Hornburg (Racke)
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 
> 
> 
> 
> -- 
> You received this message because you are 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
> .


-- 
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/3e915c0e-3af7-5150-64a7-a41e09b94eea%40linuxia.de.


signature.asc
Description: OpenPGP digital signature


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

2020-03-06 Thread Stefan Hornburg (Racke)
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 
>> 
>>
>>
>> -- 
>> You received this message because you are 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
>> .
> 
> -- 
> You received this message because you are 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
> .


-- 
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/0a47f2df-0881-159b-8415-86a6e61110ef%40linuxia.de.


signature.asc
Description: OpenPGP digital signature


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
> 
> .
>
> --
> You received this message because you are 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
> 
> .
>

-- 
You received this message because you are 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
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
> 
> .
>
> --
> You received this message because you are 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
> 
> .
>

-- 
You received this message because you are 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 Jean-Yves LENHOF

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 [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



--
You received this message because you are 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 
.


--
You received this message because you are 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.


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 Vladimir Botka
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/20200306110546.1eaf83c6%40gmail.com.


pgp0yj5chXgX1.pgp
Description: OpenPGP digital signature


[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] Ansible output customize

2020-03-06 Thread Jean-Yves LENHOF

Hi,

Did you try a callback that satisfy you ?

https://docs.ansible.com/ansible/latest/plugins/callback.html

If not you should probably have to create yours...

Ansible is not the most obvious tool to create some reports... What did 
you want to achieve ? If you want a proper report, perhaps use a 
template to create what you want on destination nodes and after get 
files back to your controller with slurp module.


Regards,

JYL


Le 06/03/2020 à 06:51, Parveen Datt a écrit :

Hi JYL,

Here is what i mean.


TASK [debug] 
***


ok: [192.168.56.50] => (item= 00:48:30 up 2 min,1 user,load average: 
0.05, 0.06, 0.03) => {


"msg": " 00:48:30 up 2 min,1 user,load average: 0.05, 0.06, 0.03"

}

ok: [192.168.56.50] => (item=4.1.12-124.36.4.el7uek.x86_64) => {

"msg": "4.1.12-124.36.4.el7uek.x86_64"

}




Can we customize above output something like below

TASK [debug] 
***



"msg": "Server Uptime is -> [' 00:50:34 up 4 min,1 user,load average: 
0.01, 0.04, 0.03']"



"msg": "Server Kernel is --> ['4.1.12-124.36.4.el7uek.x86_64']"








On Tuesday, March 3, 2020 at 12:55:40 PM UTC-8, Jean-Yves LENHOF wrote:

Hi,

What is nicely formatted ?

Please show on an example what you want

Regards,

JYL

Le 03/03/2020 à 21:42, Parveen Datt a écrit :
> Hi Team
>
> I have written a playbook and using debug variable we are
reading the output in multiple play. Is there any way we can
customize the output of each registered variable and print it
nicely formatted . Any suggestion would be appreciated
>
> Thx
>

--
You received this message because you are 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/a2a59ad5-fcea-4d84-8f09-ec954da750cf%40googlegroups.com 
.


--
You received this message because you are subscribed to the Google Groups "Ansible 
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/93ee30e9-1a34-5e89-695c-4a77292025a6%40lenhof.eu.org.


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.


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

2020-03-06 Thread Stefan Hornburg (Racke)
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-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
> .


-- 
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/51c78d34-8549-3a2e-2f79-cf7ffeaedc1d%40linuxia.de.


signature.asc
Description: OpenPGP digital signature


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

2020-03-06 Thread Mark Whaite
Hi

You can find all about Jinja filters here
https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html

But you can convert a list to a string using

{{ list | join(" ") }}

This will add a space between each element. I am not sure if that is what
you need.



On Fri, 6 Mar 2020 at 08:04, 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:
> {% 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
> 
> .
>


-- 
Mark Whaite, Systems Administrator
Adelard LLP
Adelard LLP, Units 24 Waterside, 44-48 Wharf Road, London N1 7UX
Tel: 020 7832 5850
Web: http://www.adelard.com

This e-mail, and any attachments, is confidential and for the use of the
addressee only. If you are not the intended recipient, please telephone 020
7832 5850. We do not accept legal responsibility for this e-mail or any
viruses.

Registered office: Stourside Place, Station Road, Ashford, Kent TN12 1PP
Registered in England & Wales no. OC 304551. VAT no. 454 489808

-- 
You received this message because you are 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/CAHtMyqgUtd%2BYD1%3DKuw5p89vUW_-EFdgRr%2BUPg%3D-pA7bF7N8xxw%40mail.gmail.com.


[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.