Skip to content
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
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions jenkins/ci.suse.de/pipelines/openstack-ardana.Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,17 @@ pipeline {
}
}

stage('Prepare Ardana') {
steps {
script {
ardana_lib.ansible_playbook('ardana-init')
}
script {
ardana_lib.ansible_playbook('ardana-lint')
}
}
}

stage('Deploy cloud') {
when {
expression { deploy_cloud == 'true' }
Expand Down
39 changes: 39 additions & 0 deletions scripts/jenkins/ardana/ansible/ardana-init.yml
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
27 changes: 27 additions & 0 deletions scripts/jenkins/ardana/ansible/ardana-lint.yml
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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@
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"

ardana_scratch_playbooks:
- play: "ardana-ssh-keyscan.yml"
when: "{{ is_physical_deploy and when_cloud9 }}"
- play: "wipe_disks.yml -e automate=true"
when: "{{ is_physical_deploy }}"
- play: "site.yml"
- play: "ardana-cloud-configure.yml"

61 changes: 0 additions & 61 deletions scripts/jenkins/ardana/ansible/roles/ardana_deploy/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,67 +15,6 @@
#
---

- 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

- name: Run playbooks from "{{ ardana_scratch_path }}"
command: "ansible-playbook {{ item.play }}"
args:
Expand Down
23 changes: 23 additions & 0 deletions scripts/jenkins/ardana/ansible/roles/ardana_init/defaults/main.yml
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 scripts/jenkins/ardana/ansible/roles/ardana_init/tasks/main.yml
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
22 changes: 22 additions & 0 deletions scripts/jenkins/ardana/ansible/roles/ardana_lint/defaults/main.yml
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 }}"
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
Loading