Browse Source

ansible: fail fast, use pipelining, YAML errors

* fail fast: when a task fails for a given host, don't run the next
  tasks with other hosts
* use pipelining
* make yaml warnings into error
keep-around/cba7186220f3b1541e160a001e17bad0a30d8b63
Pierre-Louis Bonicoli 5 months ago
parent
commit
cba7186220
No known key found for this signature in database GPG Key ID: 6914C4A5EDAA6DD
  1. 4
      ansible.cfg
  2. 1
      playbooks/infrastructure/playbook.yml
  3. 6
      playbooks/infrastructure/test-pipelining.yml
  4. 18
      tests/enough/common/test_ansible_utils.py

4
ansible.cfg

@ -1,2 +1,6 @@
[defaults]
roles_path = playbooks/infrastructure/roles:playbooks/authorized_keys/roles:playbooks/backup/roles:playbooks/bind/roles:playbooks/icinga/roles:playbooks/postfix/roles:playbooks/weblate/roles:playbooks/packages/roles:playbooks/jdauphant.nginx/roles:playbooks/enough-nginx/roles:playbooks/certificate/roles:playbooks/wazuh/roles:playbooks/firewall/roles:playbooks/api/roles:playbooks/openvpn/roles:playbooks/jitsi/roles
any_errors_fatal = True
duplicate_dict_key = True
[connection]
pipelining = True

1
playbooks/infrastructure/playbook.yml

@ -1,2 +1,3 @@
---
- import_playbook: test-encrypted-volume.yml
- import_playbook: test-pipelining.yml

6
playbooks/infrastructure/test-pipelining.yml

@ -0,0 +1,6 @@
- hosts: infrastructure1-host
connection: local
tasks:
- name: Check that pipelining is enabled
assert:
that: ansible_pipelining

18
tests/enough/common/test_ansible_utils.py

@ -90,6 +90,24 @@ def test_get_variable():
assert expected[variable] == value
def test_pipelining_is_enabled(monkeypatch):
ansible = ansible_utils.Ansible(settings.CONFIG_DIR, settings.SHARE_DIR,
['localhost,'])
ansible.bake()('all', '-llocalhost', '-massert',
"-athat='ansible_pipelining'")
def test_pipelining_is_enabled_2(monkeypatch):
ansible = ansible_utils.Ansible(settings.CONFIG_DIR, settings.SHARE_DIR,
['localhost,'])
# environment variable takes precedence over ansible.cfg
monkeypatch.setenv('ANSIBLE_PIPELINING', 'False')
with pytest.raises(sh.ErrorReturnCode):
ansible.bake()('all', '-llocalhost', '-massert',
"-athat='ansible_pipelining'")
def test_get_role_variable():
defaults = yaml.safe_load(open('playbooks/api/roles/api/defaults/main.yml'))
variable = 'api_admin_password'

Loading…
Cancel
Save