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

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 %}" >

[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

[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

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

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

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

[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

[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

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

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

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

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;

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

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),

[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

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

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

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:

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

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

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]

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

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

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

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

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

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

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

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]

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.

[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 %} {{

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

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

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 >        

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

[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