-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ansible lint #3141
Open
jhesketh
wants to merge
6
commits into
SUSE-Cloud:master
Choose a base branch
from
jhesketh:ansible-lint
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,191
−65
Open
Ansible lint #3141
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4efb3dd
ansible-ardana: run ansbile-lint during the deploy
3f3045f
Fix flake8 errors
35fc0a2
ardana_deploy: move lint_params to a variable
73427b0
Run ansible-lint on a copy of the target path
e5b8239
openstack-ardana: refactor ardana_deploy role
d55dc1b
Break out ardana init into a pipeline stage
jhesketh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# | ||
# (c) Copyright 2018 SUSE LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
|
||
--- | ||
|
||
- name: Configure ardana | ||
hosts: "{{ ardana_env }}" | ||
remote_user: ardana | ||
gather_facts: True | ||
|
||
tasks: | ||
- block: | ||
- name: Remove versioned features from input model when not enabled | ||
replace: | ||
path: "{{ input_model_path }}/data/control_plane.yml" | ||
regexp: '(.*{{ item }}.*)' | ||
replace: '#\1' | ||
when: not versioned_features[item].enabled | ||
delegate_to: localhost | ||
loop: | ||
- manila | ||
- freezer | ||
- heat-api-cloudwatch | ||
|
||
- include_role: | ||
name: ardana_init |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# | ||
# (c) Copyright 2018 SUSE LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
|
||
--- | ||
|
||
- name: Run lint on ardana | ||
hosts: "{{ ardana_env }}" | ||
remote_user: ardana | ||
gather_facts: True | ||
|
||
tasks: | ||
- block: | ||
- include_role: | ||
name: ardana_lint | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
scripts/jenkins/ardana/ansible/roles/ardana_init/defaults/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# | ||
# (c) Copyright 2018 SUSE LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
--- | ||
|
||
ardana_openstack_path: "~/openstack/ardana/ansible" | ||
ardana_scratch_path: "~/scratch/ansible/next/ardana/ansible" | ||
|
||
ardana_openstack_playbooks: | ||
- "config-processor-run.yml -e encrypt='' -e rekey=''" | ||
- "ready-deployment.yml" |
77 changes: 77 additions & 0 deletions
77
scripts/jenkins/ardana/ansible/roles/ardana_init/tasks/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# | ||
# (c) Copyright 2018 SUSE LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
--- | ||
|
||
- name: Run ardana-init | ||
command: "ardana-init" | ||
environment: | ||
ARDANA_INIT_AUTO: 1 | ||
|
||
- name: Copy ardana input model | ||
copy: | ||
src: "{{ input_model_path }}/" | ||
dest: "~/openstack/my_cloud/definition" | ||
register: input_model | ||
|
||
- name: Change VRRP offset | ||
replace: | ||
path: "~/openstack/ardana/ansible/roles/keepalived/defaults/main.yml" | ||
regexp: "keepalived_vrrp_offset: 0" | ||
replace: "keepalived_vrrp_offset: {{ vrrp_offset }}" | ||
register: vrrp | ||
when: is_physical_deploy | ||
|
||
- name: Commit changes | ||
shell: | | ||
git add -A | ||
git commit -m 'Add input model' | ||
args: | ||
chdir: "{{ ardana_openstack_path }}" | ||
when: input_model.changed or vrrp.changed | ||
|
||
- include_tasks: setup_ses_config.yml | ||
when: ses_enabled | ||
|
||
- name: Run playbooks from "{{ ardana_openstack_path }}" | ||
command: "ansible-playbook -i hosts/localhost {{ item }}" | ||
args: | ||
chdir: "{{ ardana_openstack_path }}" | ||
loop: "{{ ardana_openstack_playbooks }}" | ||
register: ansible_openstack_plays | ||
when: not (ansible_openstack_plays | default({})) is failed | ||
|
||
- include_tasks: setup_rhel_repo.yml | ||
when: rhel_enabled | ||
|
||
- include_tasks: reimage_nodes.yml | ||
when: is_physical_deploy | ||
|
||
- name: Import Devel:Cloud:X key when cloudsource is staging or devel | ||
shell: "ansible {{ item }} resources" | ||
args: | ||
chdir: "{{ ardana_scratch_path }}" | ||
environment: | ||
ANSIBLE_HOST_KEY_CHECKING: False | ||
ANSIBLE_SSH_ARGS: '-o UserKnownHostsFile=/dev/null' | ||
loop: | ||
- '-m copy -a "src=`find /srv/www/*/x86_64/repos/*Cloud* -name content.key` dest=/tmp/"' | ||
- '-b -a "rpm --import /tmp/content.key"' | ||
when: "'staging' in cloudsource or 'devel' in cloudsource" | ||
|
||
- include_tasks: setup_mu_repos.yml | ||
when: | ||
- not update_after_deploy | ||
- maint_updates_list | length |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions
22
scripts/jenkins/ardana/ansible/roles/ardana_lint/defaults/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# | ||
# (c) Copyright 2018 SUSE LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
--- | ||
|
||
lint_venv: "/tmp/ansible-lint" | ||
ardana_scratch_path: "/var/lib/ardana/scratch/ansible/next/ardana/ansible" | ||
lint_params: '-p -x templating,resources,ANSIBLE0002 -r {{ lint_venv }}/lint-rules -r {{ lint_venv }}/lib/python2.7/site-packages/ansiblelint/rules' | ||
|
||
lint_path: "{{ ardana_scratch_path }}" |
Empty file.
52 changes: 52 additions & 0 deletions
52
...ardana/ansible/roles/ardana_lint/files/lint-rules/ardana_action_name_should_match_rule.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# | ||
# (c) Copyright 2015-2016 Hewlett Packard Enterprise Development LP | ||
# (c) Copyright 2017 SUSE LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
|
||
import os | ||
import sys | ||
|
||
from ansiblelint import AnsibleLintRule | ||
|
||
|
||
class ArdanaActionNameShouldMatchRule(AnsibleLintRule): | ||
id = 'ARDANAANSIBLE0006' | ||
shortdesc = 'Action name should match $role | $task | description' | ||
description = 'Action name should match $role | $task | description' | ||
tags = ['formatting'] | ||
|
||
def matchtask(self, file, task): | ||
if sys.modules['ardana_noqa'].skip_match(file): | ||
return False | ||
if 'name' in task: | ||
filename = file['path'] | ||
# ignore handlers | ||
if 'handlers' in filename: | ||
return False | ||
if 'role' in filename: | ||
task_name = os.path.splitext(os.path.basename(filename))[0] | ||
dirs = filename.split('/') | ||
role = dirs[len(dirs) - 3] | ||
return not task['name'].startswith("%s | %s" % (role, | ||
task_name)) | ||
return False | ||
|
||
|
||
# ansible-lint expects the filename and class name to match | ||
# Python style expects filenames to be all lowercase | ||
# Python style expects classnames to be CamelCase | ||
# Resolution: trick ansible lint with this class | ||
class ardana_action_name_should_match_rule(ArdanaActionNameShouldMatchRule): | ||
pass |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will the lint rules be removed from ardana-dev-tools, it might be better to not have two copies that need to be kept in sync?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That'd be a good thing to do as a follow up to this in the ci-squad. I'm not sure if it'd be better to remove or find a path to keep them in sync so that likely needs some thought.