diff --git a/.gitignore b/.gitignore index e1cf205905d93c46016f27f9e4df6a1da11cfd86..78a7d185ba9c5bba0caac2042728722c01ce32dd 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ __pycache__ .vagrant/ *.log *.retry +tests/files/id_rsa +tests/files/id_rsa.pub diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000000000000000000000000000000000..bcb91fcf5582900d54aca3f2f83bc62f713cd17f --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule ".molecule/roles/openbsd-bootstrap"] + path = .molecule/roles/openbsd-bootstrap + url = https://www.shore.co.il/git/ansible-role-openbsd-bootstrap diff --git a/.molecule/roles/openbsd-bootstrap b/.molecule/roles/openbsd-bootstrap new file mode 160000 index 0000000000000000000000000000000000000000..87b397b1f5abe8cc7a89cb922c4c8d7df8898204 --- /dev/null +++ b/.molecule/roles/openbsd-bootstrap @@ -0,0 +1 @@ +Subproject commit 87b397b1f5abe8cc7a89cb922c4c8d7df8898204 diff --git a/tasks/main.yml b/tasks/main.yml index 6826745fb8fa26d310c23b60dd69714e77b33045..940fe619945be6f160ac999c791400c944ef4797 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,10 +1,10 @@ --- # tasks file for ansible-role-gitreceive - - name: Assertions assert: that: - ansible_os_family in ['Debian', 'OpenBSD'] + - gitreceive_public_keys is iterable - name: APT install prequisites when: ansible_pkg_mgr == 'apt' @@ -46,13 +46,15 @@ - name: Install when: gitreceive_fetch.changed - command: /usr/bin/make + tags: ['skip_ansible_lint'] + command: make args: chdir: /root/gitreceive - name: Init + tags: ['skip_ansible_lint'] when: gitreceive_fetch.changed - command: /usr/local/bin/gitreceive init + command: gitreceive init - name: Add public keys with_items: '{{ gitreceive_public_keys }}' @@ -64,8 +66,8 @@ - name: Copy reciever script when: gitreceive_receiver_script is defined - template: - src: gitreceive_receiver.j2 + copy: + content: '{{ gitreceive_receiver_script }}' dest: /home/git/receiver owner: git group: git diff --git a/templates/gitreceive_receiver.j2 b/templates/gitreceive_receiver.j2 deleted file mode 100644 index cf9de56f987a4aa3364d6aab5c995d4022f300e3..0000000000000000000000000000000000000000 --- a/templates/gitreceive_receiver.j2 +++ /dev/null @@ -1 +0,0 @@ -{{ gitreceive_receiver_script }} diff --git a/tests/files/id_rsa b/tests/files/id_rsa deleted file mode 100644 index 4b781c44f1b74a609a6ea29cf07141e2349b22b9..0000000000000000000000000000000000000000 --- a/tests/files/id_rsa +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEowIBAAKCAQEAoSJcYqXgO8B8L34QtsdGjC0mlF8Ee9avR3M91G6B+ki8PURd -8iBJCsAUlue+I/ojUbQet2YjMYmRKB6vjRTOSSmc9BujkDKrM2UU+edpnbL7q/N2 -Hyhh/t07zRi1OIDl+08mcBRdPNrR5uk3t3J5iNPD5xqoUt4XftBBjcRU7IEA7vOR -WljPfYkvdY8VmHaivD61N9LQLbCkXUXlwJRj6GctMSGrwabCQuYbIw4yCvVHdJm9 -bOcdMrbuHd+cfZUHHUWt/YKGMuzNpLprSHt5Miy/XixDdD6CcyZ3s6sG3PNAb+c0 -/S86Q3MFZNNRNGXIQYwHqHcHM4Kp2qOa2Z+I8QIDAQABAoIBAFnctNMbGOuZ1GgU -ETQt/E0OnRZfyztZJhVd0pyXKIuxZrFwYEg48yM4rgLeqO6dgHb/UaYMIxJsWvSZ -8GNouAabW3nTtCsl5s5Z0BHymbcl6y8hLr3/om8laEVgQyiI0jmOEayt3rWify8c -30LCZ78EApvvBPJ6A3ZopDZwyL+/635Mgblu43VK1cLQSJjGBFJDM6Z27JHjLyqV -mDPrhrIL3K/HwNTIrigi43jqUdNI+1LKa7tszjgiwqUvI+ECWMjCk1hnp86SNC7Z -GTennRUvrQ/0jg1LUxx8kzvId95LMWgNLBJrPaPlKW4uBPeWB4Pf4LM7g8fZI05U -IdK9THUCgYEAzQIokPvxYZ17np2rkjuQh6D0wg7Y8iNpSWINb7OOQyHksLo2Ovw7 -38LLfyGQfJJ95cQi1yhTncsd59eNIkV/g9/AARa05oYfJ7wNZGoAE2SxoTPgAzTl -xQPVeclCvLE73mwzK6sEWnzGU5MDKMH48uGMfLqiDnZfalZ03Scdov8CgYEAyTaG -9igsJxFIvNqQZbTP/h7xAoltnPNXZRVJA4br7XqdQGCPE9zHv4Wxa+/Mtk6N0bCJ -SgKXiN4uPRHXKpYQ61ZgvbKw9e5rYvRX03y+ya9w8iOIzZTIS2f9+M6YbPoOMjq9 -LRhCwiPTe2v9D77eusmQb8BoVb1Dq3+QTYKpBA8CgYBCy4Y+Huh5vp7tgj/JiIDB -wA6fP8kts531W+42y9D5TIy/jBxpQY+ci1JUXLI/9FbyyuHzKl98FRbsWA3S8cPn -Srq7YBOW3HJANwRCCEt4BiHd/RHq2YxXkbU3VfzZkAGKqcROYQ0tEmRoDIlF+VVM -hXKJnSF6BtV1xy+SctE0LwKBgEPjgeXL6BnGWyRdGhs2xnaXOfoBJFqwP+x7Igdu -nmuh0yzFZ4DsHPkhwpsIbamVF4SIa8ns1fP4AuHYAyD7QPomSr22bL6Nku3wQzG4 -BSdHanRISQAUEwBeNfKcwhECzYdlCi8M4HlgXRpndRq666taFsGdyZYkJZDXmXiN -fTlBAoGBAJ5GPrG5fpTmo1Pcot4MU3iA2L0/auc9qtXDARJpBJdXYF/a3KWGLmvT -+G0PHQ82z1Yn9qIgc4cD3A9FpUnEY8kPagpTHpwLCjGBpx5VPRmIwpGPy6zuP1gQ -w1GRFfHjaWq16KKomhVFkxBuMKwAs8v1rGXMQ2DZsDXB8GssP6Cu ------END RSA PRIVATE KEY----- diff --git a/tests/files/id_rsa.pub b/tests/files/id_rsa.pub deleted file mode 100644 index a9590de544b5ae7dd4998c99c3c6e0723b97dea4..0000000000000000000000000000000000000000 --- a/tests/files/id_rsa.pub +++ /dev/null @@ -1 +0,0 @@ -ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQChIlxipeA7wHwvfhC2x0aMLSaUXwR71q9Hcz3UboH6SLw9RF3yIEkKwBSW574j+iNRtB63ZiMxiZEoHq+NFM5JKZz0G6OQMqszZRT552mdsvur83YfKGH+3TvNGLU4gOX7TyZwFF082tHm6Te3cnmI08PnGqhS3hd+0EGNxFTsgQDu85FaWM99iS91jxWYdqK8PrU30tAtsKRdReXAlGPoZy0xIavBpsJC5hsjDjIK9Ud0mb1s5x0ytu4d35x9lQcdRa39goYy7M2kumtIe3kyLL9eLEN0PoJzJnezqwbc80Bv5zT9LzpDcwVk01E0ZchBjAeodwczgqnao5rZn4jx nimrod@nimrod diff --git a/tests/files/receiver.sh b/tests/files/receiver.sh index 466983c9f9cb47152a37c86c538104faf07dc322..efff13d9ad3692d863f81cd7aefd0261afc41f5f 100644 --- a/tests/files/receiver.sh +++ b/tests/files/receiver.sh @@ -1,5 +1,5 @@ #!/bin/sh set -eu -mkdir -p /tmp/gitreceive -tar -xC /tmp/gitreceive -f - +mkdir -p /var/tmp/gitreceive +tar -xC /var/tmp/gitreceive -f - echo "OK" diff --git a/tests/playbook.yml b/tests/playbook.yml index 74f5903a5dcae27b8a0a4c3b1c7b2709c09dcede..f4dfde1d75d1dd7ea9ee84e8ec9cfa5063ad1eee 100644 --- a/tests/playbook.yml +++ b/tests/playbook.yml @@ -1,13 +1,19 @@ --- - hosts: ansible-role-gitreceive-openbsd gather_facts: false - roles: [ansible-role-openbsd-bootstrap] + roles: [openbsd-bootstrap] - hosts: all vars: gitreceive_public_keys: - '{{ lookup("file", "id_rsa.pub") }}' gitreceive_receiver_script: '{{ lookup("file", "files/receiver.sh") }}' + pre_tasks: + - name: Create SSH keypair + become: False + local_action: command ssh-keygen -t rsa -N '' -f files/id_rsa + args: + creates: files/id_rsa roles: [ansible-role-gitreceive] post_tasks: - name: Create .ssh directory @@ -35,9 +41,9 @@ creates: /root/.ssh/known_hosts - name: Add localhost as a git remote - command: git remote add test git@localhost:test - args: - chdir: /root/gitreceive - register: gitreceive_add_remote - changed_when: gitreceive_add_remote.rc == 0 - failed_when: gitreceive_add_remote.rc != 0 and not 'already exists' in gitreceive_add_remote.stderr + blockinfile: + dest: /root/gitreceive/.git/config + block: | + [remote "test"] + url = git@localhost:test + fetch = +refs/heads/*:refs/remotes/test/* diff --git a/tests/test_gitreceive.py b/tests/test_gitreceive.py index e9c6f8245e591c6d62e8dc343649ad454a4d4bb7..0e9cb6979b9b06336bff84330f7c1c14fd0a3199 100644 --- a/tests/test_gitreceive.py +++ b/tests/test_gitreceive.py @@ -1,8 +1,10 @@ -def test_gitreceive(Command, Ansible): - Command('rm -rf /home/git/test /tmp/gitreceive') - push = Command('git -C /root/gitreceive push test master') +def test_gitreceive(Command, Sudo): + with Sudo(): + Command('rm -rf /home/git/test /var/tmp/gitreceive') + push = Command('git -C /root/gitreceive push test master') assert push.rc == 0 assert 'OK' in push.stderr - second_push = Command('git -C /root/gitreceive push test master') + with Sudo(): + second_push = Command('git -C /root/gitreceive push test master') assert second_push.rc == 0 - assert 'Everything up-to-date' == second_push.stderr + assert 'Everything up-to-date' in second_push.stderr