diff --git a/roles/os_config/README.md b/roles/os_config/README.md new file mode 100644 index 0000000..5712025 --- /dev/null +++ b/roles/os_config/README.md @@ -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 diff --git a/roles/os_config/defaults/main.yml b/roles/os_config/defaults/main.yml new file mode 100644 index 0000000..80c03c2 --- /dev/null +++ b/roles/os_config/defaults/main.yml @@ -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 diff --git a/roles/os_config/tasks/main.yml b/roles/os_config/tasks/main.yml new file mode 100644 index 0000000..09d7f10 --- /dev/null +++ b/roles/os_config/tasks/main.yml @@ -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" diff --git a/roles/os_config/tests/inventory b/roles/os_config/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/os_config/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/os_config/tests/test.yml b/roles/os_config/tests/test.yml new file mode 100644 index 0000000..2d4df54 --- /dev/null +++ b/roles/os_config/tests/test.yml @@ -0,0 +1,6 @@ +--- +- name: Test os_config role + hosts: localhost + connection: local + roles: + - stackhpc.openstack.os_config