Skip to content
This repository was archived by the owner on Jul 17, 2023. It is now read-only.

Commit

Permalink
Updated as per comments.
Browse files Browse the repository at this point in the history
*) Fixed as per yamllint
*) Fixed as per ansible-review and ansible-lint
*) Moved inventory file to inventory_files
*) Added standards.py under rules/ansible-review.
*) Updated ansible.cfg as per suggestions
*) Added some best practices to CONTRIBUTING.md

Signed-off-by: Kedar Bidarkar <[email protected]>
  • Loading branch information
kbidarkar authored and chris1984 committed Jul 19, 2018
1 parent 4f86d26 commit ccf9fed
Show file tree
Hide file tree
Showing 16 changed files with 467 additions and 85 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ log/
logs-*/

# Byte-compiled / optimized / DLL files
rules/ansible-review/__pycache__
__pycache__/
venv/
env/
Expand Down Expand Up @@ -52,10 +53,11 @@ coverage.xml
.pydevproject
.settings/


# Sphinx documentation
docs/_build/

# Ansible
*.retry

# Galaxy Roles
galaxy_roles/
88 changes: 85 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,94 @@ git push origin your-branch-name
You will then be able to create a pull request from your commit.

All fixes or new addition to the project should be accompanied by tests that
should PASS.
should PASS. Run the role/playbook twice, to make sure it's idempotent.

Feel free to raise issues in the repo if you feel a fix or new feature support is needed.

Standards
=========
Install and Run [ansible-lint](https://github.com/willthames/ansible-lint) against your code changes.

Also, Install and Run [ansible-review](https://github.com/willthames/ansible-review) against your code changes.
Install and Run [ansible-lint](https://github.com/willthames/ansible-lint) against your code.

```
ansible-lint playbooks/install/satellite_63.yml
```

Install and Run [ansible-review](https://github.com/willthames/ansible-review) against your code.

```
git ls-files | grep -i yml | xargs ansible-review -d rules/ansible-review/
```

Probably you may also want to run yamllint.

```
git ls-files | grep -i yml | xargs yamllint
```

Some Best Practices
===================

Some Best Practices to follow while writing roles/tasks,

1. Ansible Roles:

a. Avoid one huge role.

b. One Role, One Goal.

c. Avoid various tasks within a role, that are not related.

d. Use `ansible-galaxy init role_name` to begin with roles.

e. Following the ansible-galaxy pattern for roles would later help make
the roles push to ansible-galaxy or make use of the role elsewhere easily

f. Include/Update the requirements.yml file for any external roles used in
the project.

g. Make sure there is a Readme.md file for each role created.

h. Test/Run the role at-least twice, to make sure it's idempotent.
(i.e, the role/playbook should not fail upon re-running it for the same
host.)

2. Ansible Vars:

a. Set a default value for every variable, they are like examples.

b. Prefer scalar variables over dictionary type variables as much as
possible.

3. Use Multi Line YAML notation, instead of key=value

Vertical code is easier to read and maintain.

4. Use ansible-vault for secret passwords

Example: Ec2, subscriptions password

5. Always seek out an ansible module first, instead of running a command as
part of roles/tasks.

a. If you ever need to use "command", try to make the command module
idempotent. In order to achieve idempotence, you could use the attributes
"creates" and "removes".

b. Avoid shell module as far as possible and should be used only for I/O
redirect if in case required.

c. Idempotence: An operation is idempotent if the result of performing it
once is exactly the same as the result of performing it repeatedly
without any intervening actions.

6. Have consistency in Naming Convention:

a. Tasks, playbooks, Variables, Roles and Tags.

b. Directory Structure/layout.

7. Use handlers while restarting services.

8. Make use of the ansible_variables (i.e facts fetched from host by setup module ) as
much as possible.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ Ansible playbooks for Satellite 6 systems' management.

This repository will be Python3.6 based.

You need Ansible installed.
You need Ansible 2.5.0+ installed.

We also recommend to install ansible-lint and ansible-review.
We also recommend to install yamllint, ansible-lint and ansible-review.

### Configuration

Expand Down Expand Up @@ -48,4 +48,7 @@ $ ansible-playbook -i inventory playbooks/install/satellite_63.yml
## Contributing

Please read [CONTRIBUTING.md](https://github.com/SatelliteQE/ansible-satellite6/blob/master/CONTRIBUTING.md) if you wish to contribute.


## License

ansible-satellite6 is licensed under [GPL version 3](https://github.com/SatelliteQE/ansible-satellite6/blob/master/LICENSE).
4 changes: 3 additions & 1 deletion ansible.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
library = foreman-ansible-modules/modules
module_utils = foreman-ansible-modules/module_utils
roles_path = $PWD/galaxy_roles:$PWD/roles
inventory = inventory
inventory = inventory_files/inventory
retry_files_enabled = False
stdout_callback = yaml
display_skipped_hosts = False
File renamed without changes.
1 change: 1 addition & 0 deletions requirements.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
---
# from galaxy
# - src: username.rolename
2 changes: 1 addition & 1 deletion roles/partition-disk/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
# defaults file for partition-disk
# defaults file for partition-disk
2 changes: 1 addition & 1 deletion roles/partition-disk/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
# handlers file for partition-disk
# handlers file for partition-disk
46 changes: 8 additions & 38 deletions roles/partition-disk/meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,20 @@
---
# Standards: 0.2
galaxy_info:
author: Satellite QE Team
description: Satellite QE Team
company: RedHat
company: Red Hat

# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker

# Some suggested licenses:
# - BSD (default)
# - MIT
# - GPLv2
# - GPLv3
# - Apache
# - CC-BY
license: GPLv3

min_ansible_version: 1.2

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
min_ansible_version: 2.5.0

# Optionally specify the branch Galaxy will use when accessing the GitHub
# repo for this role. During role install, if no tags are available,
# Galaxy will use this branch. During import Galaxy will access files on
# this branch. If Travis integration is configured, only notifications for this
# branch will be accepted. Otherwise, in all cases, the repo's default branch
# (usually master) will be used.
#github_branch:

#
# platforms is a list of platforms, and each platform has a name and a list of versions.
#
platforms:
- name: RHEL
versions:
- 7
- name: RHEL
versions:
- 7

galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.


dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
16 changes: 0 additions & 16 deletions roles/partition-disk/tasks/extend_root_partition.yaml

This file was deleted.

16 changes: 16 additions & 0 deletions roles/partition-disk/tasks/extend_root_partition.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
- name: "Extend root partition LV to all available VG space"
when: item.key in "lv_root"
lvol:
vg: "{{ item.value.vg }}"
lv: "{{ item.key }}"
size: +100%FREE
with_dict: "{{ ansible_lvm.lvs }}"

- name: "Resize the root filesystem"
when: item.key in "lv_root"
filesystem:
dev: "/dev/{{ item.value.vg }}/{{ item.key }}"
fstype: xfs
resizefs: true
with_dict: "{{ ansible_lvm.lvs }}"
4 changes: 2 additions & 2 deletions roles/partition-disk/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# tasks file for partition-disk
- include_tasks: remove_home_partition.yaml
- include_tasks: extend_root_partition.yaml
- include_tasks: remove_home_partition.yml
- include_tasks: extend_root_partition.yml
18 changes: 0 additions & 18 deletions roles/partition-disk/tasks/remove_home_partition.yaml

This file was deleted.

19 changes: 19 additions & 0 deletions roles/partition-disk/tasks/remove_home_partition.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- name: "Unmount /home partition"
mount:
name: /home
state: unmounted

- name: "Remove /home entry from /etc/fstab"
mount:
name: /home
state: absent

- name: "Remove /home Logical Volume"
when: item.key in "lv_home"
lvol:
vg: "{{ item.value.vg }}"
lv: "{{ item.key }}"
state: absent
force: true
with_dict: "{{ ansible_lvm.lvs }}"
2 changes: 1 addition & 1 deletion roles/partition-disk/vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
# vars file for partition-disk
# vars file for partition-disk
Loading

0 comments on commit ccf9fed

Please sign in to comment.