diff --git a/.ansible-lint b/.ansible-lint new file mode 100644 index 0000000..b6d3809 --- /dev/null +++ b/.ansible-lint @@ -0,0 +1,5 @@ +skip_list: + - yaml[colons] + - yaml[empty-lines] + - yaml[line-length] + - no-changed-when diff --git a/.drone.env b/.drone.env new file mode 100644 index 0000000..cb9f953 --- /dev/null +++ b/.drone.env @@ -0,0 +1,4 @@ +# export ANSIBLE_LINT_EXCLUSION="--exclude collections/ansible_collections/ansible* --exclude collections/ansible_collections/community* --exclude .gitea" +export ANSIBLE_LINT_EXCLUSION="--exclude collections/ansible_collections --exclude .gitea" +export ANSIBLE_INVENTORY="-i 127.0.0.1, --connection=local" +export ANSIBLE_PLAYBOOK="baseos.yml" diff --git a/.drone.yml b/.drone.yml index 0483d9e..ad4e45d 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,16 +1,7 @@ --- kind: pipeline type: docker -name: run_ansible_tests_centos9 - -global-variables: - ansible_image : &ansible_image "gitea.thezengarden.net/podman/ansible-dev/centos9:release-34" - ansible_inventory : &ansible_inventory "-i 127.0.0.1, --connection=local" - ansible_playbook : &ansible_playbook "baseos.yml" - -environment: - ANSIBLE_INVENTORY : *ansible_inventory - ANSIBLE_PLAYBOOK : *ansible_playbook +name: CentOS_9-Ansible-Pipeline trigger: branch: @@ -19,42 +10,37 @@ trigger: event: [push] steps: - - name: "ansible_environment_verify" - image: *ansible_image + - name: ansible_environment_verify + image: gitea.thezengarden.net/podman/ansible-dev/centos9:release commands: + - . ./.drone.env + - env - git log -1 - ansible --version - ansible-lint --version - - name: "ansible_galaxy_requirements" - image: *ansible_image + - name: ansible_galaxy_requirements + image: gitea.thezengarden.net/podman/ansible-dev/centos9:release commands: - ansible-galaxy install -r requirements.yml - - name: "ansible_lint" - image: *ansible_image + - name: ansible_lint + image: gitea.thezengarden.net/podman/ansible-dev/centos9:release commands: - - ansible-lint --offline + - . ./.drone.env + - ansible-lint --offline $ANSIBLE_LINT_EXCLUSION - - name: "ansible_playbook_execution" - image: *ansible_image + - name: ansible_playbook_execution + image: gitea.thezengarden.net/podman/ansible-dev/centos9:release commands: + - . ./.drone.env - ansible-playbook -v $ANSIBLE_INVENTORY $ANSIBLE_PLAYBOOK --- kind: pipeline type: docker -name: run_ansible_tests_fedora39 - -global-variables: - ansible_image : &ansible_image "gitea.thezengarden.net/podman/ansible-dev/fedora39:release-34" - ansible_inventory : &ansible_inventory "-i 127.0.0.1, --connection=local" - ansible_playbook : &ansible_playbook "baseos.yml" - -environment: - ANSIBLE_INVENTORY : *ansible_inventory - ANSIBLE_PLAYBOOK : *ansible_playbook +name: Fedora_39-Ansible-Pipeline trigger: branch: @@ -63,42 +49,37 @@ trigger: event: [push] steps: - - name: "ansible_environment_verify" - image: *ansible_image + - name: ansible_environment_verify + image: gitea.thezengarden.net/podman/ansible-dev/fedora39:release commands: + - . ./.drone.env + - env - git log -1 - ansible --version - ansible-lint --version - - name: "ansible_galaxy_requirements" - image: *ansible_image + - name: ansible_galaxy_requirements + image: gitea.thezengarden.net/podman/ansible-dev/fedora39:release commands: - ansible-galaxy install -r requirements.yml - - name: "ansible_lint" - image: *ansible_image + - name: ansible_lint + image: gitea.thezengarden.net/podman/ansible-dev/fedora39:release commands: - - ansible-lint --offline + - . ./.drone.env + - ansible-lint --offline $ANSIBLE_LINT_EXCLUSION - - name: "ansible_playbook_execution" - image: *ansible_image + - name: ansible_playbook_execution + image: gitea.thezengarden.net/podman/ansible-dev/fedora39:release commands: + - . ./.drone.env - ansible-playbook -v $ANSIBLE_INVENTORY $ANSIBLE_PLAYBOOK --- kind: pipeline type: docker -name: run_ansible_tests_debian11 - -global-variables: - ansible_image : &ansible_image "gitea.thezengarden.net/podman/ansible-dev/debian11:release-34" - ansible_inventory : &ansible_inventory "-i 127.0.0.1, --connection=local" - ansible_playbook : &ansible_playbook "baseos.yml" - -environment: - ANSIBLE_INVENTORY : *ansible_inventory - ANSIBLE_PLAYBOOK : *ansible_playbook +name: Debian_11-Ansible-Pipeline trigger: branch: @@ -107,42 +88,37 @@ trigger: event: [push] steps: - - name: "ansible_environment_verify" - image: *ansible_image + - name: ansible_environment_verify + image: gitea.thezengarden.net/podman/ansible-dev/debian11:release commands: + - . ./.drone.env + - env - git log -1 - ansible --version - ansible-lint --version - - name: "ansible_galaxy_requirements" - image: *ansible_image + - name: ansible_galaxy_requirements + image: gitea.thezengarden.net/podman/ansible-dev/debian11:release commands: - ansible-galaxy install -r requirements.yml - - name: "ansible_lint" - image: *ansible_image + - name: ansible_lint + image: gitea.thezengarden.net/podman/ansible-dev/debian11:release commands: - - ansible-lint --offline + - . ./.drone.env + - ansible-lint --offline $ANSIBLE_LINT_EXCLUSION - - name: "ansible_playbook_execution" - image: *ansible_image + - name: ansible_playbook_execution + image: gitea.thezengarden.net/podman/ansible-dev/debian11:release commands: + - . ./.drone.env - ansible-playbook -v $ANSIBLE_INVENTORY $ANSIBLE_PLAYBOOK --- kind: pipeline type: docker -name: run_ansible_tests_debian12 - -global-variables: - ansible_image : &ansible_image "gitea.thezengarden.net/podman/ansible-dev/debian12:release-34" - ansible_inventory : &ansible_inventory "-i 127.0.0.1, --connection=local" - ansible_playbook : &ansible_playbook "baseos.yml" - -environment: - ANSIBLE_INVENTORY : *ansible_inventory - ANSIBLE_PLAYBOOK : *ansible_playbook +name: Debian_12-Ansible-Pipeline trigger: branch: @@ -151,24 +127,28 @@ trigger: event: [push] steps: - - name: "ansible_environment_verify" - image: *ansible_image + - name: ansible_environment_verify + image: gitea.thezengarden.net/podman/ansible-dev/debian12:release commands: + - . ./.drone.env + - env - git log -1 - ansible --version - ansible-lint --version - - name: "ansible_galaxy_requirements" - image: *ansible_image + - name: ansible_galaxy_requirements + image: gitea.thezengarden.net/podman/ansible-dev/debian12:release commands: - ansible-galaxy install -r requirements.yml - - name: "ansible_lint" - image: *ansible_image + - name: ansible_lint + image: gitea.thezengarden.net/podman/ansible-dev/debian12:release commands: - - ansible-lint --offline + - . ./.drone.env + - ansible-lint --offline $ANSIBLE_LINT_EXCLUSION - - name: "ansible_playbook_execution" - image: *ansible_image + - name: ansible_playbook_execution + image: gitea.thezengarden.net/podman/ansible-dev/debian12:release commands: + - . ./.drone.env - ansible-playbook -v $ANSIBLE_INVENTORY $ANSIBLE_PLAYBOOK diff --git a/.gitea/workflows/ansible-test.yml b/.gitea/workflows/ansible-test.yml new file mode 100644 index 0000000..a525dac --- /dev/null +++ b/.gitea/workflows/ansible-test.yml @@ -0,0 +1,38 @@ +name: Ansible Code Pipeline +run-name: ${{ gitea.actor }} is running Ansible Code Pipeline +on: + push: + branches: + - testing + +jobs: + Ansible-Development-Pipeline: + strategy: + matrix: + os: [ ansible-dev-centos9, ansible-dev-fedora39, ansible-dev-debian11, ansible-dev-debian12 ] + runs-on: ${{ matrix.os }} + steps: + - name: Clone repository + uses: actions/checkout@v3 + + - name: Ansible Environment Verify + run: | + . ./.drone.env + env + git log -1 + ansible --version + ansible-lint --version + + - name: Install Ansible Galaxy Dependencies + run: | + ansible-galaxy install -r requirements.yml + + - name: Run Ansible-Lint + run: | + . ./.drone.env + ansible-lint --offline $ANSIBLE_LINT_EXCLUSION + + - name: Run Ansible-Playbook + run: | + . ./.drone.env + ansible-playbook -v $ANSIBLE_INVENTORY $ANSIBLE_PLAYBOOK diff --git a/.gitignore b/.gitignore index 17494aa..fda0e54 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ inventory/* host_vars -ansible.cfg collections/ansible_collections/ +testing*.yml diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..d58a63d --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,26 @@ +[defaults] +inventory = inventory/hosts +roles_path = roles +collections_path = collections +remote_tmp = /tmp/.ansible-${USER}/tmp +gathering = smart +gather_timeout = 600 +fact_caching = jsonfile +fact_caching_connection = /tmp/.ansible_facts +fact_caching_timeout = 300 +retry_files_enabled = false +forks = 40 +timeout = 30 +host_key_checking = false +display_skipped_hosts = false +deprecation_warnings = false + +# callback_whitelist is deprecated +# we only include here for backwards compatibility +callback_whitelist = ansible.posix.profile_tasks, ansible.posix.timer +callbacks_enabled = ansible.posix.profile_tasks, ansible.posix.timer + +[ssh_connection] +pipelining = True +ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey + diff --git a/baseos.yml b/baseos.yml index 5320a26..9ec5ff1 100644 --- a/baseos.yml +++ b/baseos.yml @@ -1,5 +1,5 @@ --- -- name: Deploy a standardized base configuration +- name: Deploy a standardized configuration to target hosts hosts: all become: true gather_facts: true @@ -10,10 +10,10 @@ tasks: - - name: Include relevant role(s) + - name: Include defined role(s) ansible.builtin.include_role: name: "{{ item }}" - loop: "{{ __baseos_include_roles }}" + loop: "{{ baseos_include_roles }}" ... diff --git a/collections/requirements.yml b/collections/requirements.yml deleted file mode 100644 index 62af71e..0000000 --- a/collections/requirements.yml +++ /dev/null @@ -1,14 +0,0 @@ ---- -collections: - # Our Collections - - name: jchristianh.basos - source: https://github.com/jchristianh-ansible-collections/baseos.git - type: git - version: main - - # External Collections - - name: community.general - - name: ansible.posix - - -... diff --git a/requirements.yml b/requirements.yml new file mode 100644 index 0000000..416cc34 --- /dev/null +++ b/requirements.yml @@ -0,0 +1,13 @@ +--- +collections: + # Local Collections + - name: jchristianh.baseos + source: https://gitea.thezengarden.net/ansible_collections/ansible-collection-baseos.git + type: git + version: 1.0.21 + + # Galaxy Collections + - name: community.general + - name: ansible.posix + +... diff --git a/testing/ansible-test.sh b/testing/ansible-test.sh new file mode 100755 index 0000000..1db0573 --- /dev/null +++ b/testing/ansible-test.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +ansible-playbook -v -i localhost, --connection=local baseos.yml diff --git a/testing/env-test.sh b/testing/env-test.sh new file mode 100755 index 0000000..e5edb50 --- /dev/null +++ b/testing/env-test.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +echo "Which environment to test? (centos9, fedora39, debian11, debian12)" +read test_environment + +CNAME="testing-${test_environment}" +IMG_TAG="release" + +podman pull gitea.thezengarden.net/podman/ansible-dev/${test_environment}:${IMG_TAG} + +podman run -ti --rm --name ${CNAME} --hostname ${CNAME} \ + --cap-add SYS_ADMIN --uts=private \ + -v /home/chris/Development/Ansible/Plays/baseos:/opt/ansible/baseos \ + -v /home/chris/Development/Ansible/Collections/jchristianh/baseos:/opt/ansible/baseos/collections/ansible_collections/jchristianh/baseos \ + gitea.thezengarden.net/podman/ansible-dev/${test_environment}:${IMG_TAG} \ + /bin/bash diff --git a/vars/baseos_vars.yml b/vars/baseos_vars.yml index 9d688d7..56974d9 100644 --- a/vars/baseos_vars.yml +++ b/vars/baseos_vars.yml @@ -1,5 +1,5 @@ --- -__baseos_include_roles: +baseos_include_roles: - jchristianh.baseos.resolv_conf - jchristianh.baseos.hostname - jchristianh.baseos.etc_hosts @@ -9,5 +9,4 @@ __baseos_include_roles: - jchristianh.baseos.base_packages - jchristianh.baseos.snmpd_conf - ...