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

Scaffold a sample ansible role and playbook in existing collection: init #99

Merged
merged 13 commits into from
Mar 12, 2024
Merged
3 changes: 3 additions & 0 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ astimezone
autorefs
autosectionlabel
basesystem
boto
BUILDDIR
caplog
capsys
Expand Down Expand Up @@ -110,6 +111,7 @@ representer
Representer
returndocs
Rocannon's
rolename
rtype
rulebook
rulebooks
Expand Down Expand Up @@ -160,6 +162,7 @@ userbase
viewcode
volmount
wantd
webservers
workdir
xdist
xmss
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Stuff we don't want prettier to ever to look into
tests/fixtures/collection/testorg/testcol/playbooks/
tests/fixtures/collection/testorg/testcol/roles/
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{% raw %}---
- name: Network Getting Started First Playbook Extended
gather_facts: false
hosts: all
tasks:

- name: Get config for IOS devices
cisco.ios.ios_facts:
gather_subset: all

- name: Display the config
ansible.builtin.debug:
msg: "The hostname is {{ ansible_net_hostname }} and the OS is {{ ansible_net_version }}"

- name: Update the hostname
cisco.ios.ios_config:
lines:
- hostname ios-changed

- name: Get changed config for IOS devices
cisco.ios.ios_facts:
gather_subset: all

- name: Display the changed config
ansible.builtin.debug:
msg: "The new hostname is {{ ansible_net_hostname }} and the OS is {{ ansible_net_version }}"
{%- endraw %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
- name: Update web servers
hosts: webservers
become: true

tasks:
- name: Ensure apache is at the present version
ansible.builtin.dnf:
name: httpd
state: present

- name: Write the apache config file
ansible.builtin.template:
src: /srv/httpd.j2
dest: /etc/httpd.conf
mode: "0644"

- name: Update db servers
hosts: databases
become: true

tasks:
- name: Ensure postgresql is at the present version
ansible.builtin.dnf:
name: postgresql
state: present

- name: Ensure that postgresql is started
ansible.builtin.service:
name: postgresql
state: started
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{{ namespace|capitalize }}.{{ collection_name|capitalize }} Run Role
========================

A brief description of the role goes here.

Requirements
------------

Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.

Role Variables
--------------

A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.

Dependencies
------------

A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.

Example Playbook
----------------

Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:

```yaml
- name: Execute tasks on servers
hosts: servers
roles:
- role: {{ namespace }}.{{ collection_name }}.run
run_x: 42
```

Another way to consume this role would be:

```yaml
- name: Initialize the run role from {{ namespace }}.{{ collection_name }}
hosts: servers
gather_facts: false
tasks:
- name: Trigger invocation of run role
ansible.builtin.include_role:
name: {{ namespace }}.{{ collection_name }}.run
vars:
run_x: 42
```

License
-------

# TO-DO: Update the license to the one you want to use (delete this line after setting the license)
BSD

Author Information
------------------

An optional section for the role authors to include contact information, or a website (HTML is not allowed).
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# defaults file for run
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# handlers file for run
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
galaxy_info:
author: foo
description: {{ namespace|capitalize }}.{{ collection_name|capitalize }} Run Role
company: {{ namespace | capitalize }}

# 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

# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: GPL-2.0-or-later

min_ansible_version: "2.14"

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

#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99

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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# tasks file for run
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
localhost
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# vars file for run
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
- name: Network Getting Started First Playbook Extended
gather_facts: false
hosts: all
tasks:

- name: Get config for IOS devices
cisco.ios.ios_facts:
gather_subset: all

- name: Display the config
ansible.builtin.debug:
msg: "The hostname is {{ ansible_net_hostname }} and the OS is {{ ansible_net_version }}"

- name: Update the hostname
cisco.ios.ios_config:
lines:
- hostname ios-changed

- name: Get changed config for IOS devices
cisco.ios.ios_facts:
gather_subset: all

- name: Display the changed config
ansible.builtin.debug:
msg: "The new hostname is {{ ansible_net_hostname }} and the OS is {{ ansible_net_version }}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
- name: Update web servers
hosts: webservers
become: true

tasks:
- name: Ensure apache is at the present version
ansible.builtin.dnf:
name: httpd
state: present

- name: Write the apache config file
ansible.builtin.template:
src: /srv/httpd.j2
dest: /etc/httpd.conf
mode: "0644"

- name: Update db servers
hosts: databases
become: true

tasks:
- name: Ensure postgresql is at the present version
ansible.builtin.dnf:
name: postgresql
state: present

- name: Ensure that postgresql is started
ansible.builtin.service:
name: postgresql
state: started
57 changes: 57 additions & 0 deletions tests/fixtures/collection/testorg/testcol/roles/run/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Testorg.Testcol Run Role
========================

A brief description of the role goes here.

Requirements
------------

Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.

Role Variables
--------------

A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.

Dependencies
------------

A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.

Example Playbook
----------------

Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:

```yaml
- name: Execute tasks on servers
hosts: servers
roles:
- role: testorg.testcol.run
run_x: 42
```

Another way to consume this role would be:

```yaml
- name: Initialize the run role from testorg.testcol
hosts: servers
gather_facts: false
tasks:
- name: Trigger invocation of run role
ansible.builtin.include_role:
name: testorg.testcol.run
vars:
run_x: 42
```

License
-------

# TO-DO: Update the license to the one you want to use (delete this line after setting the license)
BSD

Author Information
------------------

An optional section for the role authors to include contact information, or a website (HTML is not allowed).
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# defaults file for run
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# handlers file for run
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
galaxy_info:
author: foo
description: Testorg.Testcol Run Role
company: Testorg

# 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

# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: GPL-2.0-or-later

min_ansible_version: "2.14"

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

#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99

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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# tasks file for run
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
localhost
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# vars file for run