diff --git a/.kitchen.yml b/.kitchen.yml index 0f0d57a..5f523f8 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -145,9 +145,9 @@ platforms: # Archlinux - name: archlinux-rolling driver: - image: diodonfrost/opensuse-13.2-ansible + image: diodonfrost/archlinux-rolling-ansible run_command: /usr/lib/systemd/systemd - platform: opensuse + platform: arch provision_command: - sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config - systemctl enable sshd diff --git a/README.md b/README.md index 225dd44..25126f7 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,195 @@ -Role Name -========= +# ansible-role-ntp -A brief description of the role goes here. +[![Build Status](https://travis-ci.org/diodonfrost/ansible-role-ntp.svg?branch=master)](https://travis-ci.org/diodonfrost/ansible-role-ntp) +[![Ansible Galaxy](https://img.shields.io/badge/galaxy-diodonfrost.ntp-660198.svg)](https://galaxy.ansible.com/diodonfrost/ntp) -Requirements ------------- +his role provide a compliance for install ntp on your target host. -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. +## Requirements -Role Variables --------------- +This role was developed using Ansible 2.4 Backwards compatibility is not guaranteed. +Use `ansible-galaxy install diodonfrost.ntp` to install the role on your system. -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. +Supported platforms: -Dependencies ------------- +```yaml +- name: EL + versions: + - 7 + - 6 + - 5 +- name: Fedora + versions: + - 29 + - 28 + - 27 + - 26 +- name: Debian + versions: + - stretch + - jessie + - wheezy + - squeeze +- name: Ubuntu + versions: + - bionic + - xenial + - trusty + - precise + - trusty +- name: OracleLinux + versions: + - 7 + - 6 +- name: Amazon + versions: + - 2017.12 + - 2016.03 + - 2013.09 +- name: opensuse + versions: + - 13.2 + - 42.1 + - 42.2 + - 42.3 +- name: SLES + versions: + - 11 + - 12 + - 15 +- name: ArchLinux + versions: + - any +- name: Gentoo + versions: + - stage3 +``` -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. +## Role Variables -Example Playbook ----------------- +This role has multiple variables. The defaults for all these variables are the following: -Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: +```yaml +--- +# defaults file for ansible-role-ntp - - hosts: servers - roles: - - { role: username.rolename, x: 42 } +# Specify ntp version to install +# Depends on the operating system +# Accepted value: 6,7,8,9,11,latest +# latest take latest version of ntp supported by operating system +# Default latest +ntp_version: latest -License -------- +# Install ntp virtual machine +# Default is true +openjre_install: true -BSD +# Install ntp virtual machine and development kit for ntp +# Default is false +openjdk_install: false +``` -Author Information ------------------- +## Dependencies -An optional section for the role authors to include contact information, or a website (HTML is not allowed). +None + +## Example Playbook + +This is a sample playbook file for deploying the Ansible Galaxy ntp role in a localhost and installing openjdk-jre. + +```yaml +--- +- hosts: localhost + become: true + roles: + - role: diodonfrost.ntp +``` + +## Local Testing + +The preferred way of locally testing the role is to use Docker. You will have to install Docker on your system. + +You can also use vagrant and Virtualbox with vagrant to run tests locally. You will have to install Virtualbox and Vagrant on your system. For all our tests we use test-kitchen. + +Next install test-kitchen: + +```shell +# Install dependencies +gem install bundler +bundle install +``` + +### Testing with Docker + +```shell +# List all tests with kitchen +kitchen list + +# fast test on one machine +kitchen test default-centos-7 + +# test on all machines +kitchen test + +# for development, create environment +kitchen create default-centos-7 + +# Apply ansible playbook +kitchen converge default-centos-7 + +# Apply inspec tests +kitchen verify default-centos-7 +``` + +### Testing with Virtualbox + +```shell +# Specify kitchen file on Linux +export KITCHEN_YAML=.kitchen-vagrant.yml + +# fast test on one machine +kitchen test os-packaging-freebsd-112 +``` +### Testing Windows and Solaris with Virtualbox + +Windows and Solaris can only be test with Virtualbox provider,do not use 'kitchen test' command for testing Windows and Solaris environment. There 4 steps you will be using with test-kitchen as part of your workflow. + +First of all we must set the kitchen file: +```shell +# For testing Windows +export KITCHEN_YAML=.kitchen-windows.yml + +# For testing Solaris +export KITCHEN_YAML=.kitchen-solaris.yml +``` + +Provision the virtual machines, a Linux machine to run Ansible and Windows/Solaris machines to apply playbook again: +```shell +# deploy machines +kitchen create + +# Launch playbook +kitchen converge +``` + +Finaly launch inspec tests: +```shell +kitchen verify +``` + +For cleaning environment use: +```shell +kitchen destroy +``` + +## License + +Apache 2 + +## Resources + +[ntp on ubuntu](https://doc.ubuntu-fr.org/ntp) + +## Author Information + +This role was created in 2018 by diodonfrost. diff --git a/meta/main.yml b/meta/main.yml index 5d50bf4..fe849e4 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,60 +1,67 @@ galaxy_info: - author: your name - description: your description - company: your company (optional) + role_name: ntp + author: diodonfrost + company: diodonfrost + description: Ansible role for manage ntp daemon on a large number of os + license: license Apache - # 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 + min_ansible_version: 2.7 - # Some suggested licenses: - # - BSD (default) - # - MIT - # - GPLv2 - # - GPLv3 - # - Apache - # - CC-BY - license: license (GPLv2, CC-BY, etc) + platforms: + - name: EL + versions: + - 7 + - 6 + - 5 + - name: Fedora + versions: + - 29 + - 28 + - 27 + - 26 + - name: Debian + versions: + - stretch + - jessie + - wheezy + - squeeze + - name: Ubuntu + versions: + - bionic + - xenial + - trusty + - precise + - trusty + - name: OracleLinux + versions: + - 7 + - 6 + - name: Amazon + versions: + - 2017.12 + - 2016.03 + - 2013.09 + - name: opensuse + versions: + - 13.2 + - 42.1 + - 42.2 + - 42.3 + - name: SLES + versions: + - 11 + - 12 + - 15 + - name: ArchLinux + versions: + - any + - name: Gentoo + versions: + - stage3 - min_ansible_version: 2.4 - - # If this a Container Enabled role, provide the minimum Ansible Container version. - # min_ansible_container_version: - - # Optionally specify the branch Galaxy will use when accessing the GitHub - # repo for this role. During role install, if no tags are available, - # Galaxy will use this branch. During import Galaxy will access files on - # this branch. If Travis integration is configured, only notifications for this - # branch will be accepted. Otherwise, in all cases, the repo's default branch - # (usually master) will be used. - #github_branch: - - # - # 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. + galaxy_tags: + - system + - packaging + - ntp dependencies: [] - # List your role dependencies here, one per line. Be sure to remove the '[]' above, - # if you add dependencies to this list. \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml index 9399e7f..8db2220 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,2 +1,8 @@ --- -# tasks file for ansible-role-ntp \ No newline at end of file +# Main tasks file for ansible-role-ntp + +- name: Include OS specific variables. + include_vars: "{{ ansible_os_family }}.yml" + +- name: Install ntp agent + include_tasks: "packages/setup-{{ ansible_system }}.yml" diff --git a/tasks/packages/setup-Linux.yml b/tasks/packages/setup-Linux.yml new file mode 100644 index 0000000..9f3ac2c --- /dev/null +++ b/tasks/packages/setup-Linux.yml @@ -0,0 +1,13 @@ +--- +# Tasks file for install ntp daemon on Linux system + +- name: Install ntp daemon on Linux + package: + name: "{{ ntp_package }}" + state: present + +- name: Service ntp on Linux + service: + name: "{{ ntp_service }}" + enabled: yes + state: started diff --git a/tests/inspec/install_spec.rb b/tests/inspec/install_spec.rb index 9a11949..ea17ff0 100644 --- a/tests/inspec/install_spec.rb +++ b/tests/inspec/install_spec.rb @@ -1,7 +1,8 @@ # Test ntp daemon install ntp_package = "ntp" -ntp_service = "ntp" +ntp_service = "ntpd" +ntp_service = "ntp" if os.family == "debian" control 'install-01' do impact 1.0 diff --git a/vars/Archlinux.yml b/vars/Archlinux.yml new file mode 100644 index 0000000..cba4248 --- /dev/null +++ b/vars/Archlinux.yml @@ -0,0 +1,2 @@ +ntp_package: ntp +ntp_service: ntpd diff --git a/vars/Debian.yml b/vars/Debian.yml new file mode 100644 index 0000000..0e42ddd --- /dev/null +++ b/vars/Debian.yml @@ -0,0 +1,2 @@ +ntp_package: ntp +ntp_service: ntp diff --git a/vars/Gentoo.yml b/vars/Gentoo.yml new file mode 100644 index 0000000..ed19340 --- /dev/null +++ b/vars/Gentoo.yml @@ -0,0 +1,2 @@ +ntp_package: net-misc/ntp +ntp_service: ntp-client diff --git a/vars/RedHat.yml b/vars/RedHat.yml new file mode 100644 index 0000000..cba4248 --- /dev/null +++ b/vars/RedHat.yml @@ -0,0 +1,2 @@ +ntp_package: ntp +ntp_service: ntpd diff --git a/vars/Suse.yml b/vars/Suse.yml new file mode 100644 index 0000000..0e42ddd --- /dev/null +++ b/vars/Suse.yml @@ -0,0 +1,2 @@ +ntp_package: ntp +ntp_service: ntp