From 616cb434f058f53e7f6c1035333a4ecfdf8ebe97 Mon Sep 17 00:00:00 2001 From: Chris Hammer Date: Wed, 12 Feb 2020 08:01:10 -0500 Subject: [PATCH] 0.1.0-DEV-20200212-80132 ------------------------ * INITIAL: - initial repo commit --- .ansible-lint | 9 ++++ .gitlab-ci.yml | 84 ++++++++++++++++++++++++++++++++++++ README.md | 38 ++++++++++++++++ defaults/main/dhcpd_vars.yml | 28 ++++++++++++ handlers/main.yml | 7 +++ meta/main.yml | 52 ++++++++++++++++++++++ tasks/main.yml | 20 +++++++++ templates/dhcpd_conf.j2 | 32 ++++++++++++++ tests/inventory | 2 + tests/test.yml | 5 +++ vars/main.yml | 2 + 11 files changed, 279 insertions(+) create mode 100644 .ansible-lint create mode 100644 .gitlab-ci.yml create mode 100644 README.md create mode 100644 defaults/main/dhcpd_vars.yml create mode 100644 handlers/main.yml create mode 100644 meta/main.yml create mode 100644 tasks/main.yml create mode 100644 templates/dhcpd_conf.j2 create mode 100644 tests/inventory create mode 100644 tests/test.yml create mode 100644 vars/main.yml diff --git a/.ansible-lint b/.ansible-lint new file mode 100644 index 0000000..0ba8132 --- /dev/null +++ b/.ansible-lint @@ -0,0 +1,9 @@ +parseable: true +quiet: false +skip_list: + - '010' + - '201' + - '305' + - '403' +use_default_rules: true +verbosity: 1 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..880ece0 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,84 @@ +# CI Mark that build is executed in CI environment +# GITLAB_CI Mark that build is executed in GitLab CI environment +# CI_SERVER Mark that build is executed in CI environment +# CI_SERVER_NAME CI server that is used to coordinate builds +# CI_SERVER_VERSION Not yet defined +# CI_SERVER_REVISION Not yet defined +# CI_BUILD_REF The commit revision for which project is built +# CI_BUILD_BEFORE_SHA The first commit that were included in push request +# CI_BUILD_REF_NAME The branch or tag name for which project is built +# CI_BUILD_ID The unique id of the current build that GitLab CI uses internally +# CI_BUILD_REPO The URL to clone the Git repository +# CI_PROJECT_ID The unique id of the current project that GitLab CI uses internally +# CI_PROJECT_DIR The full path where the repository is cloned and where the build is ran + + +variables: + ANSIBLE_ROLE: "zen_dhcpd" + ANSIBLE_ROLE_PATH: "${CI_PROJECT_DIR}" + ANSIBLE_EXTRA_VARS: "" + + +stages: + - check_and_lint + - test_deploy + + +### BEGIN TEMPLATES ### +.tags_template: &tags_template + tags: + - zen-ci-workstation + + +.header_template: &header + variables: + DOCKER_IMG_TAG: "7.7.1908" + + +.check_versions_template: &check_vers + <<: *tags_template + stage: check_and_lint + only: + - development + script: + - /usr/bin/hostname + - "cd ${CI_PROJECT_DIR} && git log -1" + - "ansible --version" + - "ansible-lint --version" + + +.lint_play_template: &lint_play + <<: *tags_template + stage: check_and_lint + only: + - development + script: + - "ansible-lint -v ${ANSIBLE_ROLE_PATH}" + + +.test_deploy_template: &test_deploy + <<: *tags_template + stage: test_deploy + only: + - development + script: + - cp -av ${ANSIBLE_ROLE_PATH} /etc/ansible/roles/${ANSIBLE_ROLE} + - ansible-playbook -v --connection=local ${ANSIBLE_EXTRA_VARS} tests/test.yml +### END TEMPLATES ### + + +### BEGIN JOBS ### +Version Checks: + <<: *header + <<: *check_vers + + +Lint Play: + <<: *header + <<: *lint_play + + +Test Deploy: + <<: *header + <<: *test_deploy +### END JOBS ### diff --git a/README.md b/README.md new file mode 100644 index 0000000..cc7c5d1 --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +Zen DHCPd +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/defaults/main/dhcpd_vars.yml b/defaults/main/dhcpd_vars.yml new file mode 100644 index 0000000..fec6de4 --- /dev/null +++ b/defaults/main/dhcpd_vars.yml @@ -0,0 +1,28 @@ +--- +dhcp_conf_file : /etc/dhcp/dhcpd.conf +dhcp_conf_version : 1.0 +dhcp_conf_revision : 20200212-125405 + + +dhcp_ddns_style : none +dhcp_authoritive : "True" + +dhcp_domain_name: "thezengarden.net" + +dhcp_default_lease : 86400 +dhcp_max_lease : 604800 + + +dhcp_subnet : 10.1.1.0 +dhcp_netmask : 255.255.255.0 +dhcp_router : 10.1.1.10 +dhcp_range_from : 10.1.1.161 +dhcp_range_to : 10.1.1.199 +dhcp_broadcast : 10.1.1.255 +dhcp_dns : 10.1.1.210 + + +# pxeboot stuff +pxeboot_file : pxelinux.0 +pxeboot_server : 10.1.1.193 + diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..496fe81 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,7 @@ +--- +# handlers file for zen_dhcpd +- name: restart dhcpd + service: + name : dhcpd + state: restarted + when: ansible_virtualization_type != "docker" diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..45b0a2a --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.9 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..a7c091c --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,20 @@ +--- +# tasks file for zen_dhcpd +- name: install dhcpd package + yum: name=dhcp state=present + + +- name: deploy dhcpd config + template: + src: templates/dhcpd_conf.j2 + dest: "/etc/dhcp/dhcpd.conf" + mode: 0644 + notify: restart dhcpd + + +- name: enable/start dhcpd + service: + name: dhcpd + enabled: yes + state: started + when: ansible_distribution_major_version == "7" and ansible_virtualization_type != "docker" diff --git a/templates/dhcpd_conf.j2 b/templates/dhcpd_conf.j2 new file mode 100644 index 0000000..6815e09 --- /dev/null +++ b/templates/dhcpd_conf.j2 @@ -0,0 +1,32 @@ +##################################################### +# The Zen Garden Network # +# # +# Configuration : {{ dhcp_conf_file }} # +# Version : {{ dhcp_conf_version }}-{{ dhcp_conf_revision }} # +# # +# Chris H. # +##################################################### + + +ddns-update-style {{ dhcp_ddns_style }}; + +option domain-name "{{ dhcp_domain_name }}"; + +default-lease-time {{ dhcp_default_lease }}; +max-lease-time {{ dhcp_max_lease }}; + +{% if dhcp_authoritive == 'True' %} +authoritative; +{% endif %} + +subnet {{ dhcp_subnet }} netmask {{ dhcp_netmask }} +{ + range {{ dhcp_range_from }} {{ dhcp_range_to }}; + option routers {{ dhcp_router }}; + option broadcast-address {{ dhcp_broadcast }}; + option domain-name "{{ dhcp_domain_name }}"; + option domain-name-servers {{ dhcp_dns }}; + + filename "{{ pxeboot_file }}"; + next-server {{ pxeboot_server }}; +} diff --git a/tests/inventory b/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 0000000..ad2a221 --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - zen_dhcpd \ No newline at end of file diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..ce3665c --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for zen_dhcpd \ No newline at end of file