Skip to content

Commit

Permalink
Fix ansible lint - Issue 103
Browse files Browse the repository at this point in the history
  • Loading branch information
Shm013 committed Sep 27, 2020
1 parent 09df22a commit 213390a
Show file tree
Hide file tree
Showing 26 changed files with 133 additions and 119 deletions.
7 changes: 7 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[flake8]
# Recommend matching the black line length (default 88),
# rather than using the flake8 default of 79:
max-line-length = 88
extend-ignore =
# See https://github.com/PyCQA/pycodestyle/issues/373
E203,
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
ko_fi: sleepingkyoto
custom:
- "https://monappy.jp/u/lae"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.vscode/
.history
*.retry
*.code-workspace
*.code-workspace
*.sw?
3 changes: 3 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
extends: default

rules:
Expand All @@ -11,3 +12,5 @@ rules:
# NOTE(retr0h): Templates no longer fail this lint rule.
# Uncomment if running old Molecule templates.
# truthy: disable

ignore: .travis.yml
14 changes: 7 additions & 7 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ netbox_git_uri: "https://github.com/netbox-community/netbox.git"
netbox_install_epel: true

netbox_superuser_username: admin
#netbox_superuser_password: changeme
# netbox_superuser_password: changeme
netbox_superuser_email: admin@localhost

netbox_database: netbox
netbox_database_user: netbox
#netbox_database_password: changeme
#netbox_database_host: localhost
# netbox_database_password: changeme
# netbox_database_host: localhost
netbox_database_port: 5432
#netbox_database_socket: /var/run/postgresql
# netbox_database_socket: /var/run/postgresql
netbox_database_conn_age: 0

netbox_redis_host: 127.0.0.1
Expand All @@ -41,12 +41,12 @@ netbox_metrics_dir: netbox_metrics
netbox_metrics_path: "/run/{{ netbox_metrics_dir }}"

netbox_config:
#SECRET_KEY:
# SECRET_KEY:
ALLOWED_HOSTS:
- localhost
- 127.0.0.1
#NAPALM_USERNAME:
#NAPALM_PASSWORD:
# NAPALM_USERNAME:
# NAPALM_PASSWORD:
MEDIA_ROOT: "{{ netbox_shared_path }}/media"
REPORTS_ROOT: "{{ netbox_shared_path }}/reports"
SCRIPTS_ROOT: "{{ netbox_shared_path }}/scripts"
Expand Down
24 changes: 12 additions & 12 deletions examples/netbox_config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
netbox_config:
#SECRET_KEY: "hLk3ED%o#P0teb&UjKN)Quvr=SW$HcM^Z(Rzy_sBXFfpY+5TVC" # let this be generated by the role so you don't have to store it
# SECRET_KEY: "hLk3ED%o#P0teb&UjKN)Quvr=SW$HcM^Z(Rzy_sBXFfpY+5TVC" # let this be generated by the role so you don't have to store it
ALLOWED_HOSTS:
- 127.0.0.1
- localhost
Expand All @@ -17,22 +17,22 @@ netbox_config:
- Dale Gribble
- [email protected]
# note that the array is nested above
BANNER_BOTTOM: *BANNER_TOP
BANNER_BOTTOM: '*BANNER_TOP'
BANNER_LOGIN: ''
BANNER_TOP: &BANNER_TOP 'Your banner text'
# you probably won't need this, but you can reference other variables like above
BASE_PATH: netbox/
CACHE_TIMEOUT: 900
CHANGELOG_RETENTION: 90
CORS_ORIGIN_ALLOW_ALL: False
#CORS_ORIGIN_REGEX_WHITELIST:
CORS_ORIGIN_ALLOW_ALL: false
# CORS_ORIGIN_REGEX_WHITELIST:
CORS_ORIGIN_WHITELIST:
- hostname.domain.example
DATE_FORMAT: N j, Y
DATETIME_FORMAT: 'N j, Y g:i a'
DEBUG: yes
DEBUG: true
# yes, no, false, true, False, True are all valid booleans in Ansible - they will be inserted correctly in configuration.py
ENFORCE_GLOBAL_UNIQUE: False
ENFORCE_GLOBAL_UNIQUE: false
EMAIL:
SERVER: localhost
PORT: 25
Expand All @@ -48,7 +48,7 @@ netbox_config:
- ::1
LOGGING:
version: 1
disable_existing_loggers: False
disable_existing_loggers: false
handlers:
console:
class: logging.StreamHandler
Expand All @@ -57,19 +57,19 @@ netbox_config:
handlers:
- console
level: INFO
LOGIN_REQUIRED: yes
LOGIN_REQUIRED: true
LOGIN_TIMEOUT: 1209600
MAINTENANCE_MODE: False
MAINTENANCE_MODE: false
MAX_PAGE_SIZE: 500
MEDIA_ROOT: /srv/netbox_media
METRICS_ENABLED: True
METRICS_ENABLED: true
NAPALM_USERNAME: netbox
NAPALM_PASSWORD: NetBox42
NAPALM_TIMEOUT: 30
NAPALM_ARGS:
keepalive: 60
PAGINATE_COUNT: 100
PREFER_IPV4: False
PREFER_IPV4: false
REPORTS_ROOT: /srv/netbox_reports
SESSION_FILE_PATH: "{{ netbox_shared_path }}/sessions"
# quotes aren't necessary as you can see - but in my opinion quotes make this more readable
Expand All @@ -78,4 +78,4 @@ netbox_config:
SHORT_TIME_FORMAT: 'H:i:s'
TIME_FORMAT: 'g:i a'
TIME_ZONE: UTC
WEBHOOKS_ENABLED: False
WEBHOOKS_ENABLED: false
38 changes: 19 additions & 19 deletions examples/playbook_single_host_deploy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- hosts: all
become: yes
become: true
roles:
- geerlingguy.postgresql
- davidwittman.redis
Expand Down Expand Up @@ -33,24 +33,24 @@
- rhel-*-extras-rpms
when: "ansible_distribution == 'Red Hat Enterprise Linux'"
- block:
- name: Set PostgreSQL facts to use PG10 for RedHat distributions
set_fact:
postgresql_version: 10
postgresql_packages:
- postgresql10
- postgresql10-server
- postgresql10-contrib
- postgresql10-libs
postgresql_data_dir: /var/lib/pgsql/10/data
postgresql_bin_path: /usr/pgsql-10/bin
postgresql_config_path: /var/lib/pgsql/10/data
postgresql_daemon: postgresql-10
- name: Install the EPEL yum repository
yum:
name: epel-release
- name: Install the PostgreSQL yum repository
yum:
name: "https://download.postgresql.org/pub/repos/yum/reporpms/EL-{{ ansible_distribution_major_version }}-x86_64/pgdg-redhat-repo-latest.noarch.rpm"
- name: Set PostgreSQL facts to use PG10 for RedHat distributions
set_fact:
postgresql_version: 10
postgresql_packages:
- postgresql10
- postgresql10-server
- postgresql10-contrib
- postgresql10-libs
postgresql_data_dir: /var/lib/pgsql/10/data
postgresql_bin_path: /usr/pgsql-10/bin
postgresql_config_path: /var/lib/pgsql/10/data
postgresql_daemon: postgresql-10
- name: Install the EPEL yum repository
yum:
name: epel-release
- name: Install the PostgreSQL yum repository
yum:
name: "https://download.postgresql.org/pub/repos/yum/reporpms/EL-{{ ansible_distribution_major_version }}-x86_64/pgdg-redhat-repo-latest.noarch.rpm"
when: "ansible_os_family == 'RedHat' and ansible_distribution_major_version =='7'"

# You can use this playbook as-is to setup a full NetBox server, just change
Expand Down
6 changes: 3 additions & 3 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
systemd:
name: netbox.socket
state: restarted
daemon_reload: yes
daemon_reload: true

- name: restart netbox.service
systemd:
name: netbox.service
state: restarted
daemon_reload: yes
daemon_reload: true

- name: reload netbox.service
systemd:
Expand All @@ -21,4 +21,4 @@
systemd:
name: netbox-rqworker.service
state: restarted
daemon_reload: yes
daemon_reload: true
1 change: 1 addition & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
galaxy_info:
author: Musee Ullah
description: Installs and configures NetBox, a DCIM suite, in a production setting.
Expand Down
13 changes: 8 additions & 5 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ driver:
name: vagrant
provider:
name: virtualbox
lint:
name: yamllint
enabled: false
lint: |
set -e
yamllint .
ansible-lint
flake8
platforms:
- name: debian-9
box: generic/debian9
Expand All @@ -21,5 +23,6 @@ scenario:
name: default
verifier:
name: testinfra
lint:
name: flake8
lint: |
set -e
flake8
2 changes: 1 addition & 1 deletion molecule/default/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
netbox_database_socket: "{{ postgresql_unix_socket_directories[0] }}"
# webhooks
netbox_webhooks_enabled: true
#db
# db
postgresql_users:
- name: "{{ netbox_database_user }}"
role_attr_flags: CREATEDB,NOSUPERUSER
Expand Down
58 changes: 29 additions & 29 deletions tasks/deploy_netbox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
extra_args: "-c {{ netbox_current_path }}/constraints.txt"
virtualenv: "{{ netbox_virtualenv_path }}"
virtualenv_command: "{{ netbox_python_binary }} -m venv"
become: True
become: true
become_user: "{{ netbox_user }}"
retries: 2
register: _netbox_virtualenv_setup
Expand All @@ -43,7 +43,7 @@
name: "{{ item }}"
state: present
virtualenv: "{{ netbox_virtualenv_path }}"
become: True
become: true
become_user: "{{ netbox_user }}"
retries: 2
register: _netbox_pip_additional_install
Expand Down Expand Up @@ -116,31 +116,31 @@
loop: "{{ netbox_reports }}"

- block:
- name: Run database migrations for NetBox
django_manage:
command: migrate
app_path: "{{ netbox_current_path }}/netbox"
virtualenv: "{{ netbox_virtualenv_path }}"

- name: Create a super user for NetBox
shell: "printf '{{ netbox_superuser_script }}' |\
{{ netbox_virtualenv_path }}/bin/python {{ netbox_current_path }}/netbox/manage.py shell"
register: _netbox_superuser_result
changed_when: "'changed' in _netbox_superuser_result.stdout"
when:
- not netbox_ldap_enabled

- name: Generate static assets for NetBox
django_manage:
command: collectstatic
app_path: "{{ netbox_current_path }}/netbox"
virtualenv: "{{ netbox_virtualenv_path }}"

- name: Clear expired user sessions in NetBox
django_manage:
command: clearsessions
app_path: "{{ netbox_current_path }}/netbox"
virtualenv: "{{ netbox_virtualenv_path }}"

become: True
- name: Run database migrations for NetBox
django_manage:
command: migrate
app_path: "{{ netbox_current_path }}/netbox"
virtualenv: "{{ netbox_virtualenv_path }}"

- name: Create a super user for NetBox
shell: "printf '{{ netbox_superuser_script }}' |\
{{ netbox_virtualenv_path }}/bin/python {{ netbox_current_path }}/netbox/manage.py shell"
register: _netbox_superuser_result
changed_when: "'changed' in _netbox_superuser_result.stdout"
when:
- not netbox_ldap_enabled

- name: Generate static assets for NetBox
django_manage:
command: collectstatic
app_path: "{{ netbox_current_path }}/netbox"
virtualenv: "{{ netbox_virtualenv_path }}"

- name: Clear expired user sessions in NetBox
django_manage:
command: clearsessions
app_path: "{{ netbox_current_path }}/netbox"
virtualenv: "{{ netbox_virtualenv_path }}"

become: true
become_user: "{{ netbox_user }}"
2 changes: 1 addition & 1 deletion tasks/generate_secret_key.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
args:
creates: "{{ netbox_shared_path }}/generated_secret_key"
executable: /bin/bash
become: True
become: true
become_user: "{{ netbox_user }}"

- name: Load saved SECRET_KEY
Expand Down
2 changes: 1 addition & 1 deletion tasks/install_packages_apt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
name: "{{ _netbox_apt_packages | flatten }}"
state: present
cache_valid_time: 3600
update_cache: yes
update_cache: true
vars:
_netbox_apt_packages:
- "{{ netbox_python_packages }}"
Expand Down
4 changes: 1 addition & 3 deletions tasks/install_packages_dnf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
dnf:
name: "{{ _netbox_dnf_packages | flatten }}"
state: present
update_cache: yes
update_cache: true
vars:
_netbox_dnf_packages:
- "{{ 'epel-release' if netbox_install_epel else [] }}"
Expand All @@ -12,5 +12,3 @@
- "{{ netbox_ldap_packages if netbox_ldap_enabled else [] }}"
- "{{ 'git' if netbox_git else [] }}"
- "{{ 'acl' if ('SUDO_USER' in ansible_env and ansible_env.SUDO_USER != 'root') else [] }}"


2 changes: 1 addition & 1 deletion tasks/install_packages_yum.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
yum:
name: "{{ _netbox_yum_packages | flatten }}"
state: present
update_cache: yes
update_cache: true
vars:
_netbox_yum_packages:
- "{{ netbox_python_packages }}"
Expand Down
Loading

0 comments on commit 213390a

Please sign in to comment.