Re: [ansible-project] Run a playbook with arbitrary host not in the inventory hosts list?

2015-08-18 Thread Brian Coca
-i 'myhost,'  will define an inventory on the command line where you
can add any host/ip you want.

^ observe the , is needed even if only 1 host is defined to signify
this is a list and not a path to a file


-- 
Brian Coca

-- 
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/CAJ5XC8mrHETVwxWHqugL2PQ%3DGJXADh3UbLoR4o6gOYfuS7Cauw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] When using ec2 or rax in a role, facts set following an add_host loop are lost when execution returns to the calling playbook

2015-08-18 Thread Mark Casey
Hello,

I'm actually revisiting a problem I originally just worked around... maybe 
18 to 24 months ago. I just now did some searching of the list, but there 
were just pages and pages for most searches I tried so apologies if this is 
a solved thing and I missed it.

What I do now to deploy to cloud hosts is have the playbook call a role 
named rax/add_rax or ec2/add_ec2. In that role I use the appropriate cloud 
module to create the hosts (or discover they are already there, of course), 
then I run the add_host loop on the result. The next role that it runs is 
named gather_custom_facts and it detects what provider is in use and uses 
the appropriate "get_facts" type module to set facts named 'private_ip' and 
'public_ip' for each host. (not to imply that hosts from different 
providers are in the same ansible-playbook run; that is still on a Someday 
list somewhere)

I do it this way so that plays work on both clouds with the same names for 
these IP variables (or facts in this case, I suppose). The problem is that 
I feel like it adds quite a bit of overhead (measured both in computing 
resources and to the learning curve for new team members). To just have a 
single ping: task you're already two or three plays in just to have 
inventory.

It seems like the easiest thing would be to use set_fact in the cloud 
provider-specific create/"persist" role and have it still exist in the 
calling playbook. But, of course, the hosts aren't actually in inventory 
yet (and even if they are the set_fact would still be a local_action). I've 
revisited this once or twice in the past and never really got anywhere so 
here I am. :)

Any ideas?

Thank you,
Mark

P.S.: For entertainment value only, I was wondering also if it'd be 
possible to write an inventory script that simply calls ansible-playbook 
again and spits out some inventory-compatible json after running these two 
or three host gathering roles.

-- 
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/04c2bb44-54d8-49b8-9a2b-454301486919%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Run a playbook with arbitrary host not in the inventory hosts list?

2015-08-18 Thread Peter Loron
Hello. I often want to run a playbook against an arbitrary host, sometimes 
one not defined in my inventory hosts file. Is there a way of specifying an 
arbitrary hostname or IP on the ansible-playbook command line to run things 
this way? It's a pain to have to edit the inventory each time I want to run 
something against a temporary machine (e.g. for testing).

Thanks.

-Pete

-- 
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/8db0dadf-ffa7-42fa-92fc-39b30cc2115c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] installation on Mac OSX issue

2015-08-18 Thread Matt Martz
The recommended method of installing Ansible on Mac is to install from
source and not via homebrew.

http://docs.ansible.com/ansible/intro_installation.html#latest-releases-on-mac-osx


You are likely to only run into problems with homebrew installed ansible

On Tuesday, August 18, 2015, Sebastian M Cheung 
wrote:

> After installation via $brew install ansible
>
>
> then, I added in ~/.bashrc
>
>
> #Ansible
>
> export PATH=/usr/local/Cellar/ansible/1.9.2/bin:$PATH
>
>
> $source .bashrc
>
>
> then
>
>
> $ ansible
>
> /usr/local/Cellar/ansible/1.9.2/bin/ansible:
> /usr/local/Cellar/ansible/1.9.2/libexec/bin/ansible: /usr/bin/python: bad
> interpreter: No such file or directory
>
> /usr/local/Cellar/ansible/1.9.2/bin/ansible: line 2:
> /usr/local/Cellar/ansible/1.9.2/libexec/bin/ansible: Undefined error: 0
>
>
> anyone? My default python is
>
>
> $which python
>
> /Users/seb/anaconda/bin/python so I guess it doesn't know which python
> interpreter to use? If so how to modify Ansible script
>
>
> Thanks
>
>
>
>
> Sebastian
>
> --
> 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/57590de1-4591-4052-bc1d-056989713051%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Matt Martz
@sivel
sivel.net

-- 
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/CAD8N0v_91jB5armSfkN6mLU0UcQ%2BAr2BV--agh8RM0X7Hm0DhQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] installation on Mac OSX issue

2015-08-18 Thread Sebastian M Cheung
 

After installation via $brew install ansible


then, I added in ~/.bashrc


#Ansible

export PATH=/usr/local/Cellar/ansible/1.9.2/bin:$PATH


$source .bashrc


then


$ ansible

/usr/local/Cellar/ansible/1.9.2/bin/ansible: 
/usr/local/Cellar/ansible/1.9.2/libexec/bin/ansible: /usr/bin/python: bad 
interpreter: No such file or directory

/usr/local/Cellar/ansible/1.9.2/bin/ansible: line 2: 
/usr/local/Cellar/ansible/1.9.2/libexec/bin/ansible: Undefined error: 0


anyone? My default python is 


$which python

/Users/seb/anaconda/bin/python so I guess it doesn't know which python 
interpreter to use? If so how to modify Ansible script


Thanks




Sebastian

-- 
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/57590de1-4591-4052-bc1d-056989713051%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Ignoring errors in check mode

2015-08-18 Thread Albertdev
Nobody got any comments if and where to best report these errors? While my 
original mail was more of a rant than a constructive topic, I still have 
these errors when I try to put a variable in ignore_errors:

When I directly reference a variable:

ERROR: error while evaluating conditional: ansible_check_mode
>

When I use a jinja placeholder:

Traceback (most recent call last):
>   File "/usr/bin/ansible-playbook", line 323, in 
> sys.exit(main(sys.argv[1:]))
>   File "/usr/bin/ansible-playbook", line 263, in main
> pb.run()
>   File "/usr/lib/python2.6/site-packages/ansible/playbook/__init__.py", 
> line 348, in run
> if not self._run_play(play):
>   File "/usr/lib/python2.6/site-packages/ansible/playbook/__init__.py", 
> line 788, in _run_play
> if not self._run_task(play, task, False):
>   File "/usr/lib/python2.6/site-packages/ansible/playbook/__init__.py", 
> line 493, in _run_task
> task.ignore_errors =  utils.check_conditional(cond, play.basedir, 
> task.module_vars, fail_on_undefined=C.DEFAULT_UNDEFINED_VAR_BEHAVIOR)
>   File "/usr/lib/python2.6/site-packages/ansible/utils/__init__.py", line 
> 265, in check_conditional
> conditional = template.template(basedir, conditional, inject, 
> fail_on_undefined=fail_on_undefined)
>   File "/usr/lib/python2.6/site-packages/ansible/utils/template.py", line 
> 121, in template
> varname = template_from_string(basedir, varname, templatevars, 
> fail_on_undefined)
>   File "/usr/lib/python2.6/site-packages/ansible/utils/template.py", line 
> 368, in template_from_string
> res = jinja2.utils.concat(rf)
>   File "", line 8, in root
>   File "/usr/lib/python2.6/site-packages/jinja2/runtime.py", line 485, in 
> _fail_with_undefined_error
> raise self._undefined_exception(hint)
> jinja2.exceptions.UndefinedError: 'ansible_check_mode' is undefined
>



I have since worked around the problem like this but I hate this kind of 
boilerplate:

---
> - hosts: all
>   name: testing
>   tasks:
> - name: print variable
>   action: debug msg="Does variable exist [{{ ansible_check_mode 
> }}]"
> - name: Make symlink
>   action: file src="/ohwhat/hai" dest="/there/youare" state=link
>   ignore_errors: True
>   register: symlinkresult
> - name: Fail if symlink could not be created
>   action: fail msg="Symlink could not be created"
>   when: "{{ not ( ansible_check_mode) and (symlinkresult | failed) 
> }}"
>



With best regards,

Albert

-- 
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/797001d6-a1c4-41e9-91d0-5dfd5b1eddda%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Using when: x in y if y is a list of dicts

2015-08-18 Thread Rob White
Hi guys,

I wonder if anyone knows if it's possible do use the 'in' clause with a 
list of dicts.

I have a list that looks like this:

[{u'state': None, u'id': u'i-233b31yy'}, {u'state': None, u'id': 
u'i-2a2281xx'}]

I want to add_host if an id is not in the list, something like:

vars:
  mylist:
- {u'state': None, u'id': u'i-233b31yy'}
- {u'state': None, u'id': u'i-2a2281xx'}
tasks:
  local_action:
module: add_host
name: "{{ ansible_ec2_local_ipv4 }}"
group: not_in_elb
  when: ansible_ec2_instance_id not in mylist

The above fails because the list items are dicts.  How can I just look at 
the id value of each dict in the list?

-- 
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/49ce10fc-2b25-4187-97e3-6c25b5b509a7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] how to abort task execution for other hosts if one task fails for one host

2015-08-18 Thread Leon Xie
hi all,

I have the below ansible playbook

++
- name: do task for AA
  hosts: AA
  roles:
- AA_ROLE

- name: do task for BB
  hosts: BB
  roles:
- BB_ROLE
++

Currently even if one task in AA_ROLE for AA fails, the tasks in BB_ROLE 
for BB will also be run.

what I want is that if any task in AA_ROLE fails, the tasks in BB_ROLE 
won't be executed.

is there any method to achieve this?

thanks a lot in advance.

-- 
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/c81c7673-c7bd-4648-b451-c8603ca7f08f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.