Skip to content

Commit

Permalink
Added ability to control no_log behavior
Browse files Browse the repository at this point in the history
This change makes the default behavior of molecule to enable logging
of its tasks. This may expose credentials if they are defined in
molecule.yml files.

User can override this behaviour by defining MOLECULE_NO_LOG variable
to true of false. When defined that value would override any value
of `provider.log` mentioned inside molecule.yaml.

When variable is not defined, the value from molecule.yml file will be
used.

When none of these are defined, logging will be enabled.

This matches Ansible behavior where environment variables do take
precedence over values defined in playbooks.

Fixes: #1666
Signed-off-by: Sorin Sbarnea <[email protected]>
  • Loading branch information
ssbarnea committed Mar 18, 2019
1 parent c0a0685 commit 08f105c
Show file tree
Hide file tree
Showing 42 changed files with 70 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[flake8]
exclude = .venv/,.tox/,dist/,build/,doc/,.eggs/,molecule/provisioner/ansible/plugins/libraries/goss.py
format = pylint
ignore = E741,W503,W504
ignore = E741,W503,W504,H
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
vars:
resource_group_name: molecule
location: westus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
vars:
resource_group_name: molecule
tasks:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
tasks:
# Developer must implement.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
tasks:
# Developer must implement.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
vars:
ssh_user: ubuntu
ssh_port: 22
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
tasks:
- block:
- name: Populate instance config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
vars:
ssh_port: 22
ssh_user: "{{ lookup('env', 'USER') }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
tasks:
- name: Destroy molecule instance(s)
gce:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
vars:
ssh_user: root
ssh_port: 22
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
tasks:
- block:
- name: Populate instance config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
tasks:
- name: Create molecule instance(s)
lxc_container:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
tasks:
- name: Destroy molecule instance(s)
lxc_container:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
vars:
ssh_user: cloud-user
ssh_port: 22
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
tasks:
- name: Destroy molecule instance(s)
os_server:
Expand Down
3 changes: 3 additions & 0 deletions molecule/provisioner/ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,9 @@ def inventory(self):
"{{ lookup('file', molecule_file) | molecule_from_yaml }}",
'molecule_instance_config':
"{{ lookup('env', 'MOLECULE_INSTANCE_CONFIG') }}",
'molecule_no_log':
"{{ lookup('env', 'MOLECULE_NO_LOG') or not "
"molecule_yml.provisioner.log|default(True) | bool }}"
}

# All group
Expand Down
2 changes: 1 addition & 1 deletion molecule/provisioner/ansible/playbooks/docker/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
tasks:
- name: Log into a Docker registry
docker_login:
Expand Down
2 changes: 1 addition & 1 deletion molecule/provisioner/ansible/playbooks/docker/destroy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
tasks:
- name: Destroy molecule instance(s)
docker_container:
Expand Down
2 changes: 1 addition & 1 deletion molecule/provisioner/ansible/playbooks/lxd/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
tasks:
- name: Create default source variable
set_fact:
Expand Down
2 changes: 1 addition & 1 deletion molecule/provisioner/ansible/playbooks/lxd/destroy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
tasks:
- name: Destroy molecule instance(s)
lxd_container:
Expand Down
2 changes: 1 addition & 1 deletion molecule/provisioner/ansible/playbooks/vagrant/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
tasks:
- name: Create molecule instance(s)
molecule_vagrant:
Expand Down
2 changes: 1 addition & 1 deletion molecule/provisioner/ansible/playbooks/vagrant/destroy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
tasks:
- name: Destroy molecule instance(s)
molecule_vagrant:
Expand Down
2 changes: 1 addition & 1 deletion test/resources/playbooks/azure/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
vars:
resource_group_name: molecule
location: westus
Expand Down
2 changes: 1 addition & 1 deletion test/resources/playbooks/azure/destroy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
vars:
resource_group_name: molecule
tasks:
Expand Down
2 changes: 1 addition & 1 deletion test/resources/playbooks/docker/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
tasks:
- name: Log into a Docker registry
docker_login:
Expand Down
2 changes: 1 addition & 1 deletion test/resources/playbooks/docker/destroy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
tasks:
- name: Destroy molecule instance(s)
docker_container:
Expand Down
2 changes: 1 addition & 1 deletion test/resources/playbooks/ec2/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
vars:
ssh_user: ubuntu
ssh_port: 22
Expand Down
2 changes: 1 addition & 1 deletion test/resources/playbooks/ec2/destroy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
vars:
resource_group_name: molecule
tasks:
Expand Down
2 changes: 1 addition & 1 deletion test/resources/playbooks/gce/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
vars:
ssh_port: 22
ssh_user: "{{ lookup('env', 'USER') }}"
Expand Down
2 changes: 1 addition & 1 deletion test/resources/playbooks/gce/destroy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
tasks:
- name: Destroy molecule instance(s)
gce:
Expand Down
2 changes: 1 addition & 1 deletion test/resources/playbooks/linode/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
vars:
ssh_user: root
ssh_port: 22
Expand Down
2 changes: 1 addition & 1 deletion test/resources/playbooks/linode/destroy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
tasks:
- block:
- name: Populate instance config
Expand Down
2 changes: 1 addition & 1 deletion test/resources/playbooks/lxc/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
tasks:
- name: Create molecule instance(s)
lxc_container:
Expand Down
2 changes: 1 addition & 1 deletion test/resources/playbooks/lxc/destroy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
tasks:
- name: Destroy molecule instance(s)
lxc_container:
Expand Down
2 changes: 1 addition & 1 deletion test/resources/playbooks/lxd/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
tasks:
- name: Create default source variable
set_fact:
Expand Down
2 changes: 1 addition & 1 deletion test/resources/playbooks/lxd/destroy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
tasks:
- name: Destroy molecule instance(s)
lxd_container:
Expand Down
2 changes: 1 addition & 1 deletion test/resources/playbooks/openstack/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
vars:
ssh_user: cloud-user
ssh_port: 22
Expand Down
2 changes: 1 addition & 1 deletion test/resources/playbooks/openstack/destroy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
tasks:
- name: Destroy molecule instance(s)
os_server:
Expand Down
2 changes: 1 addition & 1 deletion test/resources/playbooks/vagrant/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
tasks:
- name: Create molecule instance(s)
molecule_vagrant:
Expand Down
2 changes: 1 addition & 1 deletion test/resources/playbooks/vagrant/destroy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
tasks:
- name: Destroy molecule instance(s)
molecule_vagrant:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- name: Side Effect
hosts: all
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
no_log: "{{ molecule_no_log }}"
tasks:
- name: Kill ntpd on target
command: pkill ntpd
Loading

0 comments on commit 08f105c

Please sign in to comment.