Created
July 19, 2018 17:16
-
-
Save odyssey4me/5b0eacf86b544dec0a8a4ef4229c277c to your computer and use it in GitHub Desktop.
Patching a role via ansible
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: localhost | |
connection: local | |
gather_facts: no | |
vars: | |
role_prefix: "aodh" | |
path_prefix: "{{ lookup('env', 'HOME') }}/code/openstack/openstack-ansible-os_{{ role_prefix }}" | |
defaults_path: "{{ path_prefix }}/defaults/main.yml" | |
tasks_main_path: "{{ path_prefix }}/tasks/main.yml" | |
tasks: | |
- lineinfile: | |
path: "{{ defaults_path }}" | |
insertbefore: >- | |
^(.*)_oslomsg_{{ item }}_transport:.* | |
regexp: >- | |
^(.*)_oslomsg_{{ item }}_host_group:.* | |
line: >- | |
{{ role_prefix }}_oslomsg_{{ item }}_host_group: "{% raw %}{{ oslomsg_{% endraw %}{{ item }}{% raw %}_host_group | default('rabbitmq_all') }}{% endraw %}" | |
with_items: | |
- rpc | |
- notify | |
- lineinfile: | |
path: "{{ defaults_path }}" | |
insertbefore: >- | |
^(.*)_oslomsg_{{ item }}_transport:.* | |
regexp: >- | |
^(.*)_oslomsg_{{ item }}_setup_host:.* | |
line: >- | |
{{ role_prefix }}_oslomsg_{{ item }}_setup_host: "{% raw %}{{ ({% endraw %}{{ role_prefix }}{% raw %}_oslomsg_{% endraw %}{{ item }}{% raw %}_host_group in groups) | ternary(groups[{% endraw %}{{ role_prefix }}{% raw %}_oslomsg_{% endraw %}{{ item }}{% raw %}_host_group][0], 'localhost') }}{% endraw %}" | |
with_items: | |
- rpc | |
- notify | |
- replace: | |
path: "{{ defaults_path }}" | |
regexp: >- | |
^(.*)_oslomsg_(.*)_transport:.* | |
replace: >- | |
\1_oslomsg_\2_transport: "{% raw %}{{ oslomsg_\2_transport | default('rabbit') }}{% endraw %}" | |
- replace: | |
path: "{{ defaults_path }}" | |
regexp: >- | |
^(.*)_oslomsg_(.*)_servers:.* | |
replace: >- | |
\1_oslomsg_\2_servers: "{% raw %}{{ oslomsg_\2_servers | default('127.0.0.1') }}{% endraw %}" | |
- replace: | |
path: "{{ defaults_path }}" | |
regexp: >- | |
^(.*)_oslomsg_(.*)_port:.* | |
replace: >- | |
\1_oslomsg_\2_port: "{% raw %}{{ oslomsg_\2_port | default('5672') }}{% endraw %}" | |
- replace: | |
path: "{{ defaults_path }}" | |
regexp: >- | |
^(.*)_oslomsg_(.*)_use_ssl:.* | |
replace: >- | |
\1_oslomsg_\2_use_ssl: "{% raw %}{{ oslomsg_\2_use_ssl | default(False) }}{% endraw %}" | |
- lineinfile: | |
path: "{{ tasks_main_path }}" | |
insertbefore: >- | |
^- include.*: {{ role_prefix }}_db_setup.yml$ | |
line: "{{ item }}" | |
with_items: | |
- "- include_tasks: mq_setup.yml" | |
- " when:" | |
- " - \"{{ role_prefix }}_services['{{ role_prefix }}-api']['group'] in group_names\"" | |
- " - \"inventory_hostname == ((groups[{{ role_prefix }}_services['{{ role_prefix }}-api']['group']]| intersect(ansible_play_hosts)) | list)[0]\"" | |
- " with_items:" | |
- " - oslomsg_setup_host: \"{% raw %}{{ {% endraw %}{{ role_prefix }}{% raw %}_oslomsg_rpc_setup_host }}{% endraw %}\"" | |
- " oslomsg_userid: \"{% raw %}{{ {% endraw %}{{ role_prefix }}{% raw %}_oslomsg_rpc_userid }}{% endraw %}\"" | |
- " oslomsg_password: \"{% raw %}{{ {% endraw %}{{ role_prefix }}{% raw %}_oslomsg_rpc_password }}{% endraw %}\"" | |
- " oslomsg_vhost: \"{% raw %}{{ {% endraw %}{{ role_prefix }}{% raw %}_oslomsg_rpc_vhost }}{% endraw %}\"" | |
- " oslomsg_transport: \"{% raw %}{{ {% endraw %}{{ role_prefix }}{% raw %}_oslomsg_rpc_transport }}{% endraw %}\"" | |
- " - oslomsg_setup_host: \"{% raw %}{{ {% endraw %}{{ role_prefix }}{% raw %}_oslomsg_notify_setup_host }}{% endraw %}\"" | |
- " oslomsg_userid: \"{% raw %}{{ {% endraw %}{{ role_prefix }}{% raw %}_oslomsg_notify_userid }}{% endraw %}\"" | |
- " oslomsg_password: \"{% raw %}{{ {% endraw %}{{ role_prefix }}{% raw %}_oslomsg_notify_password }}{% endraw %}\"" | |
- " oslomsg_vhost: \"{% raw %}{{ {% endraw %}{{ role_prefix }}{% raw %}_oslomsg_notify_vhost }}{% endraw %}\"" | |
- " oslomsg_transport: \"{% raw %}{{ {% endraw %}{{ role_prefix }}{% raw %}_oslomsg_notify_transport }}{% endraw %}\"" | |
- " no_log: true" | |
- " tags:" | |
- " - {{ role_prefix }}-config" | |
- "" | |
- copy: | |
src: "{{ path_prefix }}/../openstack-ansible-tests/sync/tasks/mq_setup.yml" | |
dest: "{{ path_prefix }}/tasks/mq_setup.yml" | |
remote_src: yes | |
- shell: | | |
git add --all | |
git commit -a -m "Move MQ vhost/user creation into role" \ | |
-m "There is no record for why we implement the MQ vhost/user creation | |
outside of the role in the playbook, when we could do it inside the | |
role. | |
Implementing it inside the role allows us to reduce the quantity of | |
group_vars duplicated from the role, and allows us to better document | |
the required variables in the role. The delegation can still be done | |
as it is done in the playbook too. | |
In this patch we implement two new variables: | |
- {{ role_prefix }}_oslomsg_rpc_setup_host | |
- {{ role_prefix }}_oslomsg_notify_setup_host | |
These are used in the role to allow delegation of the MQ vhost/user | |
setup for each type to any host, but they default to using the first | |
member of the applicable oslomsg host group. | |
We also adjust some of the defaults to automatically inherit existing | |
vars set in group_vars form the integrated build so that we do not | |
need to do the wiring in the integrated build's group vars. We still | |
default them in the role too for independent role usage." | |
git checkout -b move-mq-setup-into-roles | |
git review | |
args: | |
executable: /bin/bash | |
chdir: "{{ path_prefix }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment