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

Add os_config role #13

Open
wants to merge 5 commits into
base: main
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
75 changes: 75 additions & 0 deletions roles/os_config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
stackhpc.openstack.os_config
============================

Add OpenStack client config file to default location of
`~/.config/openstack/clouds.yaml`

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

No requirements beyond installing Ansible.

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

`os_config_content` is a string that is written out into the config file.
Its often best setting that as an inline vault variable.

`os_config_destination` is the directory where the configuration is written.
This defaults to the home directory of the ansible user, but another common
location is "/etc/openstack".

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

There are no requirements for any other Ansible roles.

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

While you probably want to use and inline vault variable, here is a nice
example of using this role in a playbook:

---
- hosts: all
vars:
ansible_become: yes
my_cloud_config: |
---
clouds:
mycloud:
auth:
auth_url: http://openstack.example.com:5000
project_name: p3
username: user
password: secretpassword
region: RegionOne
roles:
- role: stackhpc.os-config
os_config_content: "{{ my_cloud_config }}"
os_config_destination: "/etc/openstack"
os_config_owner: root
os_config_group: root

An easy way to this example is:

sudo yum install python-virtualenv libselinux-python

virtualenv .venv --system-site-packages
. .venv/bin/activate
pip install -U pip
pip install -U ansible

ansible-galaxy install stackhpc.openstack.os_config

ansible-playbook -i "localhost," -c local test.yml

License
-------

Apache 2

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

http://www.stackhpc.com
14 changes: 14 additions & 0 deletions roles/os_config/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
os_config_destination: /home/{{ ansible_facts.user }}/.config/openstack
os_config_owner: "{{ ansible_facts.user }}"
os_config_group: "{{ ansible_facts.user }}"
os_config_content: |
---
clouds:
myprivateclound:
auth:
auth_url: http://openstack.example.com:5000
project_name: p3
username: user
password: secretpassword
region: RegionOne
16 changes: 16 additions & 0 deletions roles/os_config/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
- name: Create OpenStack config dir
ansible.builtin.file:
dest: "{{ os_config_destination }}"
owner: "{{ os_config_owner }}"
group: "{{ os_config_group }}"
state: directory
mode: "0770"

- name: Write OpenStack cloud config
ansible.builtin.copy:
content: "{{ os_config_content }}"
dest: "{{ os_config_destination }}/clouds.yaml"
owner: "{{ os_config_owner }}"
group: "{{ os_config_group }}"
mode: "0660"
2 changes: 2 additions & 0 deletions roles/os_config/tests/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
localhost

6 changes: 6 additions & 0 deletions roles/os_config/tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Test os_config role
hosts: localhost
connection: local
roles:
- stackhpc.openstack.os_config