[ansible-project] How to debug developing lookup plugins?

2015-06-16 Thread Yasir Saleem
Hi, 
  I am developing a lookup plugin to provide 'Mime Multi Part archive' data 
to 'nova_compute module as 'user_data' 

Code is doing something similar to what is shown here 
http://bazaar.launchpad.net/~cloud-utils-dev/cloud-utils/trunk/view/head:/bin/write-mime-multipart
 

return from lookup plugin has every character separated by ','. Which I am 
not sure where it is coming from 

like 


 partial ansible console output Start 
TASK: [openstack-instance | set_fact ] 

Terms: 
/var/folders/hb/x94mdg1n2qdd3n2c7zn2xdfr1gn4kj/T/cloudinit-XX.vDaFsyKs/lookup_plugin_test-jump/
ok: [lookup_plugin_test-jump] = {ansible_facts: {multi_part_msg: 
C,o,n,t,e,n,t,-,T,y,p,e,:, ,m,u,l,t,i,p,a,r,t,/,m,i,x,e,d,;, 
,b,o,u,n,d,a,r,y,=,\,=,=,=,=,=,=,=,=,=,=,=,=,=,=,=,0,2,2,1,2,6,1,9,6,0,0,4,5,3,7,6,2,5,8,=,=

 partial ansible console output End  

When I use the same code inside module I get the correct data. And it works 
fine. I am trying to debug what is going inside lookup plugin. Is there a 
way to debug lookup plugin? 

BTW: 

I am invoking lookup plugin as 

- set_fact:
multi_part_msg: {{ 
lookup('multipart_mime','/var/folders/hb/x94mdg1n2qdd3n2c7zn2xdfr1gn4kj/T/cloudinit-XX.vDaFsyKs/lookup_plugin_test-jump/')
 
}}

Where 'multipart_mime' is my lookup plugin, that converts the data in the 
given directory to  'Mime Multi Part archive' data as needed by 
nova_compute module.

Thanks,
Yasir.

-- 
You received this message because you are 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/246f87ad-8514-49a6-8dda-5cafb0a44756%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: ignore_errors does not take variable

2014-10-07 Thread Yasir Saleem
I am setting test_err to 'yes' via set_fact:

below is playbook details:

##
- hosts: jump
  remote_user: deploy
  gather_facts: yes
  tasks:
- set_fact: test_err=yes
- debug: var=test_err
- debug: var=test_err
  ignore_errors: {{ test_err }}



output of above playbook:

##
PLAY [jump] 
*** 

GATHERING FACTS 
*** 
ok: [qactld1-jump]

TASK: [set_fact test_err=yes] 
* 
ok: [qactld1-jump]

TASK: [debug var=test_err] 
 
ok: [qactld1-jump] = {
test_err: yes
}

TASK: [debug var=test_err] 
 
Traceback (most recent call last):
  File /usr/local/bin/ansible-playbook, line 309, in module
sys.exit(main(sys.argv[1:]))
  File /usr/local/bin/ansible-playbook, line 249, in main
pb.run()
  File /Library/Python/2.7/site-packages/ansible/playbook/__init__.py, 
line 339, in run
if not self._run_play(play):
  File /Library/Python/2.7/site-packages/ansible/playbook/__init__.py, 
line 695, in _run_play
if not self._run_task(play, task, False):
  File /Library/Python/2.7/site-packages/ansible/playbook/__init__.py, 
line 468, in _run_task
task.ignore_errors =  utils.check_conditional(cond , play.basedir, 
task.module_vars, fail_on_undefined=C.DEFAULT_UNDEFINED_VAR_BEHAVIOR)
  File /Library/Python/2.7/site-packages/ansible/utils/__init__.py, line 
254, in check_conditional
conditional = template.template(basedir, conditional, inject, 
fail_on_undefined=fail_on_undefined)
  File /Library/Python/2.7/site-packages/ansible/utils/template.py, line 
115, in template
varname = template_from_string(basedir, varname, vars, 
fail_on_undefined)
  File /Library/Python/2.7/site-packages/ansible/utils/template.py, line 
357, in template_from_string
res = jinja2.utils.concat(rf)
  File template, line 8, in root
  File /Library/Python/2.7/site-packages/jinja2/runtime.py, line 485, in 
_fail_with_undefined_error
raise self._undefined_exception(hint)
jinja2.exceptions.UndefinedError: 'test_err' is undefined



Reason we are trying to use ignore_errors via variable is because we are 
using our own module to run 'cucumber' tests in a role, we want to give 
control via variable weather to stop execution upon failures to the role 
user. Because in case tests are run in CI ( via jenkins) we want jenkins 
plugin to compile results, for command line users, ansible console we will 
have control.

I hope this clarifies.

Thanks,
Yasir.

On Tuesday, October 7, 2014 10:10:11 AM UTC-4, Mark wrote:

 Hi Yasir,

 Have you read through: 
 http://docs.ansible.com/playbooks_error_handling.html  ?

 Ignore_errors is taking yes or no, because simply put there isn't any 
 other answer possible to Do you want me to ignore the errors? yes/no. You 
 are answering with Mooo and the system doesnt speak cowish, yet
 I'm interested in knowing why do you want to let ignore_errors take a 
 variable?

 Regards,
 Mark




 On Monday, October 6, 2014 7:22:18 PM UTC+2, Yasir Saleem wrote:

 Hi,
I was trying to use ignore_errors to take a variable, but it fails.

 Here is example play for ignore error not working:

 - hosts: jump
   remote_user: deploy
   gather_facts: yes
   tasks:
 - set_fact: test_err=yes
 - debug: var=test_err
   ignore_errors: {{ test_err }}

 output was:

 #
 PLAY [jump] 
 *** 

 GATHERING FACTS 
 *** 
 ok: [qa10-jump1]

 TASK: [set_fact test_err=yes] 
 * 
 ok: [qa10-jump1]

 TASK: [debug var=test_err] 
  
 Traceback (most recent call last):
   File /usr/local/bin/ansible-playbook, line 309, in module
 sys.exit(main(sys.argv[1:]))
   File /usr/local/bin/ansible-playbook, line 249, in main
 pb.run()
   File /Library/Python/2.7/site-packages/ansible/playbook/__init__.py, 
 line 339, in run
 if not self._run_play(play):
   File /Library/Python/2.7/site-packages/ansible/playbook/__init__.py, 
 line 695, in _run_play
 if not self._run_task(play, task, False):
   File /Library/Python/2.7/site-packages/ansible/playbook/__init__.py, 
 line 468, in _run_task
 task.ignore_errors =  utils.check_conditional(cond , play.basedir, 
 task.module_vars, fail_on_undefined=C.DEFAULT_UNDEFINED_VAR_BEHAVIOR)
   File /Library/Python/2.7/site-packages/ansible/utils/__init__.py, 
 line 254, in check_conditional
 conditional = template.template(basedir, conditional, inject, 
 fail_on_undefined=fail_on_undefined)
   File /Library/Python/2.7/site-packages/ansible/utils/template.py, 
 line 115, in template
 varname = template_from_string(basedir, varname, vars

Re: [ansible-project] Re: ignore_errors does not take variable

2014-10-07 Thread Yasir Saleem
I tried few combinations:

#
- hosts: jump
  remote_user: deploy
  gather_facts: yes
  tasks:
- set_fact: test_err=yes
- debug: var=test_err
- debug: var=test_err
  ignore_errors: test_err | bool 
#

or 


- hosts: jump
  remote_user: deploy
  gather_facts: yes
  tasks:
- set_fact: test_err={{ 'yes' |bool }}
- debug: var=test_err
- debug: var=test_err
  ignore_errors: test_err 

or 


- hosts: jump
  remote_user: deploy
  gather_facts: yes
  tasks:
- set_fact: test_err=True
- debug: var=test_err
- debug: var=test_err
  ignore_errors: test_err


In all cases got following error:


PLAY [jump] 
*** 

GATHERING FACTS 
*** 
ok: [qactld1-jump]

TASK: [set_fact test_err=True] 
 
ok: [qactld1-jump]

TASK: [debug var=test_err] 
 
ok: [qactld1-jump] = {
test_err: True
}

TASK: [debug var=test_err] 
 
ERROR: error while evaluating conditional: test_err
##


On Tuesday, October 7, 2014 10:57:16 AM UTC-4, Michael Peters wrote:

 You are setting test_err to the *string* yes, but ingore_errors is 
 looking for a boolean expression. Also, you don't need to using the 
 {{ }} syntax in ignore_errors since it is already using jinja2. Try 
 using the bool filter: 

 - hosts: jump 
   remote_user: deploy 
   gather_facts: yes 
   tasks: 
 - set_fact: test_err=yes 
 - debug: var=test_err 
   ignore_errors: test_err | bool 



 On Tue, Oct 7, 2014 at 10:51 AM, Yasir Saleem yasi...@gmail.com 
 javascript: wrote: 
  I am setting test_err to 'yes' via set_fact: 
  
  below is playbook details: 
  
  ## 
  - hosts: jump 
remote_user: deploy 
gather_facts: yes 
tasks: 
  - set_fact: test_err=yes 
  - debug: var=test_err 
  - debug: var=test_err 
ignore_errors: {{ test_err }} 
  
   
  
  output of above playbook: 
  
  ## 
  PLAY [jump] 
  *** 
  
  GATHERING FACTS 
  *** 
  ok: [qactld1-jump] 
  
  TASK: [set_fact test_err=yes] 
  * 
  ok: [qactld1-jump] 
  
  TASK: [debug var=test_err] 
   
  ok: [qactld1-jump] = { 
  test_err: yes 
  } 
  
  TASK: [debug var=test_err] 
   
  Traceback (most recent call last): 
File /usr/local/bin/ansible-playbook, line 309, in module 
  sys.exit(main(sys.argv[1:])) 
File /usr/local/bin/ansible-playbook, line 249, in main 
  pb.run() 
File /Library/Python/2.7/site-packages/ansible/playbook/__init__.py, 
  line 339, in run 
  if not self._run_play(play): 
File /Library/Python/2.7/site-packages/ansible/playbook/__init__.py, 
  line 695, in _run_play 
  if not self._run_task(play, task, False): 
File /Library/Python/2.7/site-packages/ansible/playbook/__init__.py, 
  line 468, in _run_task 
  task.ignore_errors =  utils.check_conditional(cond , play.basedir, 
  task.module_vars, fail_on_undefined=C.DEFAULT_UNDEFINED_VAR_BEHAVIOR) 
File /Library/Python/2.7/site-packages/ansible/utils/__init__.py, 
 line 
  254, in check_conditional 
  conditional = template.template(basedir, conditional, inject, 
  fail_on_undefined=fail_on_undefined) 
File /Library/Python/2.7/site-packages/ansible/utils/template.py, 
 line 
  115, in template 
  varname = template_from_string(basedir, varname, vars, 
  fail_on_undefined) 
File /Library/Python/2.7/site-packages/ansible/utils/template.py, 
 line 
  357, in template_from_string 
  res = jinja2.utils.concat(rf) 
File template, line 8, in root 
File /Library/Python/2.7/site-packages/jinja2/runtime.py, line 485, 
 in 
  _fail_with_undefined_error 
  raise self._undefined_exception(hint) 
  jinja2.exceptions.UndefinedError: 'test_err' is undefined 
  
   
  
  Reason we are trying to use ignore_errors via variable is because we are 
  using our own module to run 'cucumber' tests in a role, we want to give 
  control via variable weather to stop execution upon failures to the role 
  user. Because in case tests are run in CI ( via jenkins) we want jenkins 
  plugin to compile results, for command line users, ansible console we 
 will 
  have control. 
  
  I hope this clarifies. 
  
  Thanks, 
  Yasir. 
  
  On Tuesday, October 7, 2014 10:10:11 AM UTC-4, Mark wrote: 
  
  Hi Yasir, 
  
  Have you read through: 
  http://docs.ansible.com/playbooks_error_handling.html  ? 
  
  Ignore_errors is taking yes or no, because simply put there isn't any 
  other answer possible to Do you want me to ignore the errors

[ansible-project] ignore_errors does not take variable

2014-10-06 Thread Yasir Saleem
Hi,
   I was trying to use ignore_errors to take a variable, but it fails.

Here is example play for ignore error not working:

- hosts: jump
  remote_user: deploy
  gather_facts: yes
  tasks:
- set_fact: test_err=yes
- debug: var=test_err
  ignore_errors: {{ test_err }}

output was:

#
PLAY [jump] 
*** 

GATHERING FACTS 
*** 
ok: [qa10-jump1]

TASK: [set_fact test_err=yes] 
* 
ok: [qa10-jump1]

TASK: [debug var=test_err] 
 
Traceback (most recent call last):
  File /usr/local/bin/ansible-playbook, line 309, in module
sys.exit(main(sys.argv[1:]))
  File /usr/local/bin/ansible-playbook, line 249, in main
pb.run()
  File /Library/Python/2.7/site-packages/ansible/playbook/__init__.py, 
line 339, in run
if not self._run_play(play):
  File /Library/Python/2.7/site-packages/ansible/playbook/__init__.py, 
line 695, in _run_play
if not self._run_task(play, task, False):
  File /Library/Python/2.7/site-packages/ansible/playbook/__init__.py, 
line 468, in _run_task
task.ignore_errors =  utils.check_conditional(cond , play.basedir, 
task.module_vars, fail_on_undefined=C.DEFAULT_UNDEFINED_VAR_BEHAVIOR)
  File /Library/Python/2.7/site-packages/ansible/utils/__init__.py, line 
254, in check_conditional
conditional = template.template(basedir, conditional, inject, 
fail_on_undefined=fail_on_undefined)
  File /Library/Python/2.7/site-packages/ansible/utils/template.py, line 
115, in template
varname = template_from_string(basedir, varname, vars, 
fail_on_undefined)
  File /Library/Python/2.7/site-packages/ansible/utils/template.py, line 
357, in template_from_string
res = jinja2.utils.concat(rf)
  File template, line 8, in root
  File /Library/Python/2.7/site-packages/jinja2/runtime.py, line 485, in 
_fail_with_undefined_error
raise self._undefined_exception(hint)
jinja2.exceptions.UndefinedError: 'test_err' is undefined

##

When I use a static value, 'yes' it works:

- hosts: jump
  remote_user: deploy
  gather_facts: yes
  tasks:
- set_fact: test_err=yes
- debug: var=test_err
  ignore_errors: yes

output was:

###
PLAY [jump] 
*** 

GATHERING FACTS 
*** 
ok: [qa10-jump1]

TASK: [set_fact test_err=yes] 
* 
ok: [qa10-jump1]

TASK: [debug var=test_err] 
 
ok: [qa10-jump1] = {
test_err: yes
}

PLAY RECAP 
 
qa10-jump1 : ok=3changed=0unreachable=0failed=0
##

Isn't this a bug? 

I am using ansible 1.7.1 release

Thanks,
Yasir.

-- 
You received this message because you are 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/8984b829-bccc-47d6-b389-ac3e2faf4b95%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] unable to update sudoers file on RH6u5 with validate option.

2014-07-25 Thread Yasir Saleem
Mike,

  I am sorry, I was able to fix the problem by specify full path for visudo 
command. It was in '/usr/sbin/visudo' 

Validate part looks like below:

validate='/usr/sbin/visudo -cf %s' 

For my RH6U5 boxes root does not have /usr/sbin in the path.

I could have replied earlier, When I tried to reply yesterday I was not 
able to access the group...

Thanks,

Yasir.

On Thursday, July 24, 2014 6:43:10 PM UTC-4, Michael DeHaan wrote:

 H.

 No such file or directory *MIGHT* be referring to visudo.  Can you try 
 explicitly pathing it?




 On Thu, Jul 24, 2014 at 9:05 AM, Yasir Saleem yasi...@gmail.com 
 javascript: wrote:


 Hi,
   I am not able to change '/etc/sudoers' file successfully on RH 6.5 
 (Santiago) when using validate option. The same thing works fine on RH6u4 
 sever.

 Below is my playbook and response from the server.

 Note: When I run the commented 'lineinfile' task works fine on RH6u5 as 
 well but I want to validate before changing 'sudoers' file.

 - hosts: proxy
   gather_facts: yes
   remote_user: {{ ssh_remote_user }}
   sudo: yes
   tasks:
 - name: update sudoer file to allow ADMIN nopasswd
   lineinfile: dest=/etc/sudoers state=present regexp='^%admin ALL =' 
 line='%admin ALL=(ALL) NOPASSWD:ALL' validate='visudo -cf %s'
   #lineinfile: dest=/etc/sudoers state=present regexp='^%admin ALL =' 
 line='%admin ALL=(ALL) NOPASSWD:ALL'


 TASK: [update sudoer file to allow ADMIN nopasswd] 
 *** 
 failed: [proxy10-qa1] = {cmd: visudo -cf /tmp/tmp8UPaDy, failed: 
 true, rc: 2}
 msg: [Errno 2] No such file or directory

 FATAL: all hosts have already failed -- aborting

 Thanks,
 Yasir.

 -- 
 You received this message because you are subscribed to the Google Groups 
 Ansible Project group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to ansible-proje...@googlegroups.com javascript:.
 To post to this group, send email to ansible...@googlegroups.com 
 javascript:.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/ansible-project/ffda7799-0b24-469a-89fa-476dc389024c%40googlegroups.com
  
 https://groups.google.com/d/msgid/ansible-project/ffda7799-0b24-469a-89fa-476dc389024c%40googlegroups.com?utm_medium=emailutm_source=footer
 .
 For more options, visit https://groups.google.com/d/optout.




-- 
You received this message because you are subscribed to the Google Groups 
Ansible Project group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/646370af-42fc-4ad6-b4f9-4891daa6d0d1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Best way to import ENV variables with defaults

2014-07-18 Thread Yasir Saleem
Hi,
 I want to important env variables as fellow in a group_vars file.:

project_id: {{ lookup('env','PROJECT_ID') | default('FOO_PROJECT') }}

I want it to pick default value if ENV variable is not defined. Default 
part is not working. Am I doing it right? Is there a better way to do it?


Another unrelated question:

What is difference between?

flag: 'True'
flag: True

Thanks,
Yasir.

-- 
You received this message because you are 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/b238a149-c601-4329-be35-199296d23729%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Best way to import ENV variables with defaults

2014-07-18 Thread Yasir Saleem
Morgan,

 Thanks a lot, passing true to the 'default' did the trick. It works now!!

Working statement...

project_id: {{ lookup('env','PROJECT_ID') | default('FOO_PROJECT',true) }}

For Question B:

In when statement, which is preferred

when: flag is defined and flag == 'False'  
Or 
when: flag is defined and flag == False

Are the equivalent in ansible? 

Thanks.
Yasir.

On Friday, July 18, 2014 9:47:42 AM UTC-4, C. Morgan Hamill wrote:

 Excerpts from Michael DeHaan's message of 2014-07-18 09:21:53 -0400: 
  The lookup plugin will return empty string, not None, if that env is not 
  found. 
  
  However that is still False in Python.   That's curious and may be 
 related 
  to how default is implemented.   Will have to try that. 

 Jinja's `default` filter will, by default, only use the value passed to 
 to it if the variable in question is undefined, like, fo' real. 

 If you want to use the default value whenever the variable is False in 
 a boolean context, then use: 

 my_variable|default(my_default, true) 

 Check it out: http://jinja.pocoo.org/docs/templates/#builtin-filters 
 -- 
 Morgan Hamill 


-- 
You received this message because you are 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/e807280a-3d9f-43db-aece-d601c4e04d9b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.