My solution has been to build testing into the image-building step, so:

1) create instance
2) run nodejs ansible role on instance
3) bake instance into image... but don't do it if port 80 isn't open on the 
instance:

- name: convert instance to ami
  hosts: localhost
  vars:
    region: us-west-2
    tags: { type: nodejs-pre-image }
  # check that the web daemon will actually start before building the image
  # -- this test could definitely be more comprehensive, ie, with uri module
  tasks:
  - name: wait for port 80 open
    wait_for:
     host: "{{item.private_ip}}"
     port: 80
    with_items: ec2.tagged_instances
  - name: build ami
    ec2_ami:
    [ ..... and so on .... ]


This has the added benefit of forcing me to do what I've been meaning to do 
anyway, build some testing into my Ansible scripts. That's a good thing! 


On Monday, January 4, 2016 at 11:13:26 AM UTC-6, James Lucas wrote:
>
> Thanks for the suggestion. Unfortunately, this does not work. I tried your 
> suggestion:
>
> - name: run ansible on all hosts in group
>   become: yes
>   hosts: nodejs
>   max_fail_percentage: 1
>   roles:
>   - nodejs
>
>
> ... as well as the 'any_errors_fatal' option, like this:
>
> - name: run ansible on all hosts in group
>   become: yes
>   hosts: nodejs
>   any_errors_fatal: True
>   roles:
>   - nodejs
>
> However, regardless of failure on the play run against nodejs, the 
> playbook continues running straight into the 'convert instance to ami' play:
>
> - name: convert instance to ami
>   hosts: localhost
>   vars:
>     region: us-west-2
>   tasks:
>   - name: build ami
>     ec2_ami:
>      name: amlx-nodejs
>      description: basic nodejs image
>      instance_id: "{{item.id}}"
>      region: "{{region}}"
>      wait: yes
>     with_items: ec2.tagged_instances
>
>
> Is this the way Ansible is supposed to work? Should I be separating this 
> out into separate playbooks and having a service like Jenkins manage 
> running multiple playbooks?
>
>
>
> On Thursday, December 31, 2015 at 4:08:05 PM UTC-6, chris meyers wrote:
>>
>> Use ansible maximum fail percentage and set it to 1% (or 0% if 0 isn't 
>> treated special). This way, if any tasks fail on the play executing on the 
>> play running against the nodejs group, the Ami play following will not run. 
>> http://docs.ansible.com/ansible/playbooks_delegation.html#maximum-failure-percentage
>>
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/f05e03e2-b8e6-4c59-a433-ecb9ba7b80b7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to