Skip to content

Commit

Permalink
Added ability to control no_log behavior (#1839)
Browse files Browse the repository at this point in the history
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 disabled in order to
keep the behaviour consistent with previous versions. In the future
we may want to change the default value in order to improve the user
experience.

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 authored Mar 26, 2019
1 parent 9e54cf5 commit 6805318
Show file tree
Hide file tree
Showing 41 changed files with 69 additions and 39 deletions.
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(False) | 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 6805318

Please sign in to comment.