diff --git a/molecule/backup-with-preexisting-config/Dockerfile.j2 b/molecule/backup-with-preexisting-config/Dockerfile.j2 new file mode 100644 index 0000000..17464f7 --- /dev/null +++ b/molecule/backup-with-preexisting-config/Dockerfile.j2 @@ -0,0 +1,26 @@ +# Molecule managed + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +{% if item.env is defined %} +{% for var, value in item.env.items() %} +{% if value %} +ENV {{ var }} {{ value }} +{% endif %} +{% endfor %} +{% endif %} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python3 openjdk-8-jre tomcat8 unzip sudo bash ca-certificates iproute2 python3-apt aptitude && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install /usr/bin/python3 /usr/bin/python3-config /usr/bin/dnf-3 sudo bash iproute && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum install -y /usr/bin/python /usr/bin/python2-config sudo yum-plugin-ovl bash iproute && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python3 sudo bash iproute2 && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python3 sudo bash ca-certificates; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python3 sudo bash ca-certificates iproute2 && xbps-remove -O; fi + +# Create pre-existing yml file to test backup +RUN mkdir /var/lib/tomcat8/newrelic +RUN echo "Old App Name" >> /var/lib/tomcat8/newrelic/newrelic.yml \ No newline at end of file diff --git a/molecule/backup-with-preexisting-config/INSTALL.rst b/molecule/backup-with-preexisting-config/INSTALL.rst new file mode 100644 index 0000000..d926ca2 --- /dev/null +++ b/molecule/backup-with-preexisting-config/INSTALL.rst @@ -0,0 +1,22 @@ +******* +Docker driver installation guide +******* + +Requirements +============ + +* Docker Engine + +Install +======= + +Please refer to the `Virtual environment`_ documentation for installation best +practices. If not using a virtual environment, please consider passing the +widely recommended `'--user' flag`_ when invoking ``pip``. + +.. _Virtual environment: https://virtualenv.pypa.io/en/latest/ +.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site + +.. code-block:: bash + + $ python3 -m pip install 'molecule[docker]' diff --git a/molecule/backup-with-preexisting-config/converge.yml b/molecule/backup-with-preexisting-config/converge.yml new file mode 100644 index 0000000..c203c1e --- /dev/null +++ b/molecule/backup-with-preexisting-config/converge.yml @@ -0,0 +1,19 @@ +--- +- name: Converge + hosts: all + tasks: + - name: "Run agent install role" + include_role: + name: "newrelic-java-agent-ansible-role" + vars: + nr_java_agent_config: + license_key: YOUR_LICENSE_KEY + app_name: Molecule backup test + collector_host: localhost + + server_type: tomcat + server_root: /var/lib/tomcat8 + jvm_conf_file: /usr/share/tomcat8/bin/setenv.sh + server_user: tomcat8 + server_group: tomcat8 + restart_web_server: false diff --git a/molecule/backup-with-preexisting-config/molecule.yml b/molecule/backup-with-preexisting-config/molecule.yml new file mode 100644 index 0000000..0298549 --- /dev/null +++ b/molecule/backup-with-preexisting-config/molecule.yml @@ -0,0 +1,14 @@ +--- +dependency: + name: galaxy +driver: + name: docker +platforms: + - name: instance + image: ubuntu:18.04 + pre_build_image: False + privileged: True +provisioner: + name: ansible +verifier: + name: ansible diff --git a/molecule/backup-with-preexisting-config/verify.yml b/molecule/backup-with-preexisting-config/verify.yml new file mode 100644 index 0000000..32cbfa3 --- /dev/null +++ b/molecule/backup-with-preexisting-config/verify.yml @@ -0,0 +1,25 @@ +--- +# This is an example playbook to execute Ansible tests. + +- name: Verify + hosts: all + tasks: + - name: Make sure the backup file was created + wait_for: + path: /var/lib/tomcat8/newrelic/newrelic.yml.orig + search_regex: Old App Name + timeout: 1 + + - name: Make sure the new app name is in the newrelic.yml file + wait_for: + path: /var/lib/tomcat8/newrelic/newrelic.yml + search_regex: Molecule backup test + timeout: 1 + + - name: Make sure .prev is _not_ created + block: + - stat: + path: /var/lib/tomcat8/newrelic/newrelic.yml.prev + register: prev + - assert: + that: not prev.stat.exists diff --git a/molecule/backup-without-preexisting-config/Dockerfile.j2 b/molecule/backup-without-preexisting-config/Dockerfile.j2 new file mode 100644 index 0000000..d2b0906 --- /dev/null +++ b/molecule/backup-without-preexisting-config/Dockerfile.j2 @@ -0,0 +1,22 @@ +# Molecule managed + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +{% if item.env is defined %} +{% for var, value in item.env.items() %} +{% if value %} +ENV {{ var }} {{ value }} +{% endif %} +{% endfor %} +{% endif %} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python3 openjdk-8-jre tomcat8 unzip sudo bash ca-certificates iproute2 python3-apt aptitude && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install /usr/bin/python3 /usr/bin/python3-config /usr/bin/dnf-3 sudo bash iproute && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum install -y /usr/bin/python /usr/bin/python2-config sudo yum-plugin-ovl bash iproute && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python3 sudo bash iproute2 && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python3 sudo bash ca-certificates; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python3 sudo bash ca-certificates iproute2 && xbps-remove -O; fi diff --git a/molecule/backup-without-preexisting-config/INSTALL.rst b/molecule/backup-without-preexisting-config/INSTALL.rst new file mode 100644 index 0000000..d926ca2 --- /dev/null +++ b/molecule/backup-without-preexisting-config/INSTALL.rst @@ -0,0 +1,22 @@ +******* +Docker driver installation guide +******* + +Requirements +============ + +* Docker Engine + +Install +======= + +Please refer to the `Virtual environment`_ documentation for installation best +practices. If not using a virtual environment, please consider passing the +widely recommended `'--user' flag`_ when invoking ``pip``. + +.. _Virtual environment: https://virtualenv.pypa.io/en/latest/ +.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site + +.. code-block:: bash + + $ python3 -m pip install 'molecule[docker]' diff --git a/molecule/backup-without-preexisting-config/converge.yml b/molecule/backup-without-preexisting-config/converge.yml new file mode 100644 index 0000000..76d3420 --- /dev/null +++ b/molecule/backup-without-preexisting-config/converge.yml @@ -0,0 +1,51 @@ +--- +- name: Converge + hosts: all + tasks: + - name: "Run agent install role once" + include_role: + name: "newrelic-java-agent-ansible-role" + vars: + nr_java_agent_config: + license_key: YOUR_LICENSE_KEY + app_name: Molecule backup first run + collector_host: localhost + + server_type: tomcat + server_root: /var/lib/tomcat8 + jvm_conf_file: /usr/share/tomcat8/bin/setenv.sh + server_user: tomcat8 + server_group: tomcat8 + restart_web_server: false + + - name: "Run agent install role again - create .orig" + include_role: + name: "newrelic-java-agent-ansible-role" + vars: + nr_java_agent_config: + license_key: YOUR_LICENSE_KEY + app_name: Molecule backup second run + collector_host: localhost + + server_type: tomcat + server_root: /var/lib/tomcat8 + jvm_conf_file: /usr/share/tomcat8/bin/setenv.sh + server_user: tomcat8 + server_group: tomcat8 + restart_web_server: false + + - name: "Run agent install role once more - create .prev" + include_role: + name: "newrelic-java-agent-ansible-role" + vars: + nr_java_agent_config: + license_key: YOUR_LICENSE_KEY + app_name: Molecule backup third run + collector_host: localhost + + server_type: tomcat + server_root: /var/lib/tomcat8 + jvm_conf_file: /usr/share/tomcat8/bin/setenv.sh + server_user: tomcat8 + server_group: tomcat8 + restart_web_server: false diff --git a/molecule/backup-without-preexisting-config/molecule.yml b/molecule/backup-without-preexisting-config/molecule.yml new file mode 100644 index 0000000..0298549 --- /dev/null +++ b/molecule/backup-without-preexisting-config/molecule.yml @@ -0,0 +1,14 @@ +--- +dependency: + name: galaxy +driver: + name: docker +platforms: + - name: instance + image: ubuntu:18.04 + pre_build_image: False + privileged: True +provisioner: + name: ansible +verifier: + name: ansible diff --git a/molecule/backup-without-preexisting-config/verify.yml b/molecule/backup-without-preexisting-config/verify.yml new file mode 100644 index 0000000..7ed4bb1 --- /dev/null +++ b/molecule/backup-without-preexisting-config/verify.yml @@ -0,0 +1,17 @@ +--- +# This is an example playbook to execute Ansible tests. + +- name: Verify + hosts: all + tasks: + - name: Make sure the .orig backup file was created correctly + wait_for: + path: /var/lib/tomcat8/newrelic/newrelic.yml.orig + search_regex: Molecule backup first run + timeout: 1 + + - name: Make sure the .prev backup file was created correctly + wait_for: + path: /var/lib/tomcat8/newrelic/newrelic.yml.prev + search_regex: Molecule backup second run + timeout: 1 diff --git a/molecule/respect_restart_web_server_false/Dockerfile.j2 b/molecule/respect_restart_web_server_false/Dockerfile.j2 new file mode 100644 index 0000000..d2b0906 --- /dev/null +++ b/molecule/respect_restart_web_server_false/Dockerfile.j2 @@ -0,0 +1,22 @@ +# Molecule managed + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +{% if item.env is defined %} +{% for var, value in item.env.items() %} +{% if value %} +ENV {{ var }} {{ value }} +{% endif %} +{% endfor %} +{% endif %} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python3 openjdk-8-jre tomcat8 unzip sudo bash ca-certificates iproute2 python3-apt aptitude && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install /usr/bin/python3 /usr/bin/python3-config /usr/bin/dnf-3 sudo bash iproute && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum install -y /usr/bin/python /usr/bin/python2-config sudo yum-plugin-ovl bash iproute && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python3 sudo bash iproute2 && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python3 sudo bash ca-certificates; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python3 sudo bash ca-certificates iproute2 && xbps-remove -O; fi diff --git a/molecule/respect_restart_web_server_false/INSTALL.rst b/molecule/respect_restart_web_server_false/INSTALL.rst new file mode 100644 index 0000000..d926ca2 --- /dev/null +++ b/molecule/respect_restart_web_server_false/INSTALL.rst @@ -0,0 +1,22 @@ +******* +Docker driver installation guide +******* + +Requirements +============ + +* Docker Engine + +Install +======= + +Please refer to the `Virtual environment`_ documentation for installation best +practices. If not using a virtual environment, please consider passing the +widely recommended `'--user' flag`_ when invoking ``pip``. + +.. _Virtual environment: https://virtualenv.pypa.io/en/latest/ +.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site + +.. code-block:: bash + + $ python3 -m pip install 'molecule[docker]' diff --git a/molecule/respect_restart_web_server_false/converge.yml b/molecule/respect_restart_web_server_false/converge.yml new file mode 100644 index 0000000..1d6cf95 --- /dev/null +++ b/molecule/respect_restart_web_server_false/converge.yml @@ -0,0 +1,20 @@ +--- +- name: Converge + hosts: all + tasks: + - name: "Include newrelic-java-agent" + include_role: + name: "newrelic-java-agent-ansible-role" + vars: + nr_java_agent_config: + license_key: YOUR_LICENSE_KEY + app_name: Tomcat Molecule test + collector_host: localhost + + server_type: tomcat + server_root: /var/lib/tomcat8 + jvm_conf_file: /usr/share/tomcat8/bin/setenv.sh + server_user: tomcat8 + server_group: tomcat8 + service_name: tomcat8 + restart_web_server: false diff --git a/molecule/respect_restart_web_server_false/molecule.yml b/molecule/respect_restart_web_server_false/molecule.yml new file mode 100644 index 0000000..0298549 --- /dev/null +++ b/molecule/respect_restart_web_server_false/molecule.yml @@ -0,0 +1,14 @@ +--- +dependency: + name: galaxy +driver: + name: docker +platforms: + - name: instance + image: ubuntu:18.04 + pre_build_image: False + privileged: True +provisioner: + name: ansible +verifier: + name: ansible diff --git a/molecule/respect_restart_web_server_false/verify.yml b/molecule/respect_restart_web_server_false/verify.yml new file mode 100644 index 0000000..e767ad3 --- /dev/null +++ b/molecule/respect_restart_web_server_false/verify.yml @@ -0,0 +1,17 @@ +--- +# This is an example playbook to execute Ansible tests. + +- name: Verify + hosts: all + tasks: + - name: Wait for tomcat to (not) restart + pause: + seconds: 10 + - name: Make sure agent log does not exist + block: + - name: + stat: + path: /var/lib/tomcat8/newrelic/logs/newrelic_agent.log + register: log_file + - assert: + that: not log_file.stat.exists diff --git a/tasks/backup_config.yml b/tasks/backup_config.yml index 0ee8b16..bfffb03 100644 --- a/tasks/backup_config.yml +++ b/tasks/backup_config.yml @@ -43,6 +43,10 @@ group: "{{ server_group }}" mode: "0640" become: true + # This task is not idempotent on the second run, only on subsequent runs, + # so disable idempotence testing. + tags: + - molecule-idempotence-notest # If neither .prev nor .orig exists, we've never run before. # Copy the existing newrelic.yml to .orig no matter what. @@ -56,7 +60,7 @@ group: "{{ server_group }}" mode: "0640" become: true - # This task is not idempotent on the first run, only on subsequent runs, + # This task is not idempotent on the second run, only on subsequent runs, # so disable idempotence testing. tags: - molecule-idempotence-notest diff --git a/tasks/install.yml b/tasks/install.yml index 839d6cd..b41ff2a 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -66,6 +66,10 @@ become: true notify: - restart web server + # This task always updates the newrelic.yml file's modified + # timestamp, so it is technically not idempotent + tags: + - molecule-idempotence-notest - name: Remove newrelic.yml.new file: