特拉维斯-CI很容易做到:
# Run the role/playbook again, checking to make sure it's idempotent.
- >
ansible-playbook -i tests/inventory tests/test.yml --connection=local --sudo --extra-vars "take_ownership_of_tmp=$OWN_TMP"
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)但是我不能使用Travis,因为我需要在Debian系统上测试我的角色。我使用测试-厨房与ansible_playbook供应器。
例如:
我的.kitchen.yml
---
driver:
name: vagrant
provisioner:
name: ansible_playbook
hosts: test-kitchen
ansible_verbosity: 2
ansible_verbose: true
require_ansible_repo: false
require_chef_omnibus: false
require_ansible_omnibus: true
require_chef_for_busser: false
ansible_omnibus_url: https://raw.githubusercontent.com/neillturner/omnibus-ansible/master/ansible_install.sh
platforms:
- name: debian-6.0.10-64-nocm
driver_config:
customize:
memory: 1024
cpus: 2
box: puppetlabs/debian-6.0.10-64-nocm
box_url: https://atlas.hashicorp.com/puppetlabs/boxes/debian-6.0.10-64-nocm/versions/1.0.2/providers/virtualbox.box
suites:
- name: default
verifier:
ruby_bindir: '/usr/bin'测试剧本( test /integration/default/default.yml)非常简单
---
- hosts: all
roles:
- preconf
vars:
#some vars here我可以在default.yml中添加preconf角色的第二个调用,但这没有帮助。
有了一次电话,厨房还给我一些更换的物品:
PLAY RECAP ********************************************************************
localhost : ok=12 changed=8 unreachable=0 failed=0 但是,对于两个调用,它返回项和,而不是两个单独的结果。
PLAY RECAP ********************************************************************
localhost : ok=24 changed=10 unreachable=0 failed=0 那么,我怎样才能第二次运行剧本,检查幂等测试的结果呢?
发布于 2015-09-10 03:20:55
我用BATS测试解决了:
#!/usr/bin/env bats
#
#
# Idempotence test
#
@test "Second run should change nothing" {
run bash -c "ansible-playbook -i /tmp/kitchen/hosts /tmp/kitchen/default.yml -c local | grep -q 'changed=0.*failed=0' && exit 0 || exit 1"
[ "$status" -eq 0 ]
}UPD Serverspec变体:
describe command('ansible-playbook -i /tmp/kitchen/hosts /tmp/kitchen/default.yml -c local') do
its(:stderr) { should match /changed=0.*failed=0/ }
its(:exit_status) { should eq 0 }
end发布于 2018-04-06 14:22:11
ansible_playbook和ansible_push厨房提供程序现在都支持idempotency_test参数,该参数实际上是第二次运行剧本,并检查failed或changed任务。
您可以简单地将idempotency_test: true添加到.kitchen.yml中,如下所示:
---
driver:
name: vagrant
provisioner:
name: ansible_playbook
hosts: test-kitchen
ansible_verbosity: 2
ansible_verbose: true
require_ansible_repo: false
require_chef_omnibus: false
require_ansible_omnibus: true
require_chef_for_busser: false
ansible_omnibus_url: https://raw.githubusercontent.com/neillturner/omnibus-ansible/master/ansible_install.sh
idempotency_test: true
platforms:
- name: debian-6.0.10-64-nocm
driver_config:
customize:
memory: 1024
cpus: 2
box: puppetlabs/debian-6.0.10-64-nocm
box_url: https://atlas.hashicorp.com/puppetlabs/boxes/debian-6.0.10-64-nocm/versions/1.0.2/providers/virtualbox.box
suites:
- name: default
verifier:
ruby_bindir: '/usr/bin'https://stackoverflow.com/questions/32473572
复制相似问题