[ansible-project] Re: Debug with with_items and the Task Name.

2018-05-27 Thread Pranay Nanda
Use package_status.results

https://stackoverflow.com/questions/37925282/iteration-using-with-items-and-register

On Monday, 28 May 2018 00:32:17 UTC+5:30, Vino B wrote:
>
> Hi All
>
>   Request your help on where to put the debug statement 
>
> Requirement 1:
> If a package is missing the output should be like "Package {{ package name 
> }} missing" 
>
> When debug is used the task name does not display instead the task is 
> named as "debug" 
>
> TASK[Check the required OS Packages are installed] is not displayed when 
> using debug
> TASK [debug] Display this as a task name
>
>
> Play Book
> ---
> - hosts: all
>   become: true
>   become_method: sudo
>   gather_facts: no
>vars_files:
>   - "/home/ansible/.ansible/target.yml"
>   tasks:
>
>   - name: Check the required OS Packages are installed
> shell: /usr/bin/zypper -q search -is {{ item.pname }} warn=no
> with_items:
>   - { pname: '"bing"'}
>   - { pname: '"bonnie"' }
> register: package_status
> failed_when: package_status.rc != 0
> changed_when: false
> ignore_errors: True
> tags: package
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/ad8a2aeb-47b4-4d98-9897-82e798542bab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Ansible vars precendence

2018-05-27 Thread Pranay Nanda
I fixed the error in the main play

-  name: manage services
   hosts: all
   tasks:
 - include_vars: 
"{{playbook_dir}}/../roles/service_management/vars/s1s2grouping.yml"

But now it won't read variables




On Monday, 28 May 2018 00:03:22 UTC+5:30, Pranay Nanda wrote:
>
> I have an Ansible playbook that I want to load custom variables for. I do 
> not have access to the inventory but I wish to classify the variables by 
> their host names which can be classified in groups. The jobs would be fired 
> from Ansible Tower. Where should I put these variables such that they by 
> default override the values in tower? I've tried putting them in the vars 
> file in the role that's supposed to run but the operation occurs as per the 
> values in tower. I've tried putting them in the main play as well but it 
> returns an error "<> should be a list or None."
>
> -  name: manage services
>hosts: all
>tasks:
>include_vars:
>  - "{{playbook_dir}}/../roles/service_management/vars/s1s2grouping.yml"
>
> A little test in the role shows that the file is being loaded.
>
>
> - name: include variables
>   include_vars:
> file: s1s2grouping.yml
>   register: checking
>
> - debug: "msg={{checking.ansible_included_var_files}}"
>
> The above code results in a positive answer.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/caf6cfbd-4835-4bfe-a0a2-2f8bf9c552db%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Ansible vars precendence

2018-05-27 Thread Pranay Nanda
I have an Ansible playbook that I want to load custom variables for. I do 
not have access to the inventory but I wish to classify the variables by 
their host names which can be classified in groups. The jobs would be fired 
from Ansible Tower. Where should I put these variables such that they by 
default override the values in tower? I've tried putting them in the vars 
file in the role that's supposed to run but the operation occurs as per the 
values in tower. I've tried putting them in the main play as well but it 
returns an error "<> should be a list or None."

-  name: manage services
   hosts: all
   tasks:
   include_vars:
 - "{{playbook_dir}}/../roles/service_management/vars/s1s2grouping.yml"

A little test in the role shows that the file is being loaded.


- name: include variables
  include_vars:
file: s1s2grouping.yml
  register: checking

- debug: "msg={{checking.ansible_included_var_files}}"

The above code results in a positive answer.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/4cfcb51a-17ad-4c00-a972-9ecf4598d5eb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Multiple conditions not working

2018-05-27 Thread Pranay Nanda
You're a hero! Splitting does the job. I still wonder why previous logic 
did not work.

On Sunday, 27 May 2018 21:21:15 UTC+5:30, Pranay Nanda wrote:
>
> I want to run few tasks in shell if they satisfy a condition. Strangely 
> the task runs if the second condition is satisfied even though the first 
> one fails.
>
>   name: ods
>   shell: "/something {{state}}"
>   when: ((ods) and (not (ansible_hostname | search("demlh*"
>   register: sss_ods_out
>   notify: output ods
>   ignore_errors: yes
>
> Here sss_ods is a variable defined in a vars file. If I remove the latter 
> condition the task would run but I want both the conditions to be satisfied 
> for the task to run and I can't understand where am I going wrong.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/801d7920-39c0-40a1-a173-2c4cabf7db34%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Multiple conditions not working

2018-05-27 Thread Pranay Nanda
I want to run few tasks in shell if they satisfy a condition. Strangely the 
task runs if the second condition is satisfied even though the first one 
fails.

  name: ods
  shell: "/something {{state}}"
  when: ((ods) and (not (ansible_hostname | search("demlh*"
  register: sss_ods_out
  notify: output ods
  ignore_errors: yes

Here sss_ods is a variable defined in a vars file. If I remove the latter 
condition the task would run but I want both the conditions to be satisfied 
for the task to run and I can't understand where am I going wrong.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/2f030d29-b1fa-4c24-8ba7-7b4ab0e0562d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.