This is an automated email from the ASF dual-hosted git repository. machristie pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/airavata.git
commit ed1e86aa16ad812f7698b77f47b20dcedb0291bd Author: Marcus Christie <[email protected]> AuthorDate: Wed Jul 6 11:09:17 2022 -0400 AIRAVATA-3609 Fix delegation of database setup tasks for Ansible 2.13 --- dev-tools/ansible/requirements.txt | 20 ++++++++++++++++++-- dev-tools/ansible/roles/django/tasks/database.yml | 16 ++++++++-------- dev-tools/ansible/roles/django/tasks/main.yml | 16 ++++++++++++---- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/dev-tools/ansible/requirements.txt b/dev-tools/ansible/requirements.txt index dc30cfd1fd..85f5923373 100644 --- a/dev-tools/ansible/requirements.txt +++ b/dev-tools/ansible/requirements.txt @@ -15,5 +15,21 @@ # specific language governing permissions and limitations # under the License. -ansible~=2.3.1 -docker<3.0 +ansible==6.0.0 +ansible-core==2.13.1 +certifi==2021.10.8 +cffi==1.15.0 +charset-normalizer==2.0.12 +cryptography==36.0.2 +docker==5.0.3 +idna==3.3 +Jinja2==3.1.1 +MarkupSafe==2.1.1 +packaging==21.3 +pycparser==2.21 +pyparsing==3.0.8 +PyYAML==6.0 +requests==2.27.1 +resolvelib==0.5.4 +urllib3==1.26.9 +websocket-client==1.3.2 diff --git a/dev-tools/ansible/roles/django/tasks/database.yml b/dev-tools/ansible/roles/django/tasks/database.yml index 4589562088..4b69a1b233 100644 --- a/dev-tools/ansible/roles/django/tasks/database.yml +++ b/dev-tools/ansible/roles/django/tasks/database.yml @@ -22,22 +22,22 @@ - name: Adds Python MySQL support on Debian/Ubuntu apt: pkg="python-mysqldb" state=present - become_user: root - when: ansible_os_family == 'Debian' + become: true + when: hostvars[delegated_host].ansible_os_family == 'Debian' -- name: Adds Python MySQL support on RedHat/CentOS - yum: name=MySQL-python state=present - become_user: root - when: ansible_os_family == 'RedHat' +# Explicitly lookup hostvars for delegated host. There seem to be bugs around +# delegation and ansible facts, see https://github.com/ansible/ansible/issues/30630 +- include_tasks: install_deps_{{ hostvars[delegated_host].ansible_distribution }}_{{ hostvars[delegated_host].ansible_distribution_major_version }}.yml + when: hostvars[delegated_host].ansible_os_family == "RedHat" - name: create django database ({{ django_database_name }}) mysql_db: name="{{ django_database_name }}" state=present encoding=utf8 collation=utf8_bin - name: give access to {{ django_db_username }} from remote (internal ip) - mysql_user: name="{{ django_db_username }}" password="{{ django_db_password }}" host="{{ ansible_default_ipv4.address }}" + mysql_user: name="{{ django_db_username }}" password="{{ django_db_password }}" host="{{ django_internal_ip }}" - name: give access to {{ django_db_username }} from remote (public ip) - mysql_user: name="{{ django_db_username }}" password="{{ django_db_password }}" host="{{ ansible_host }}" + mysql_user: name="{{ django_db_username }}" password="{{ django_db_password }}" host="{{ django_public_ip }}" - name: give access to {{ django_db_username }} from localhost mysql_user: name="{{ django_db_username }}" password="{{ django_db_password }}" host="localhost" diff --git a/dev-tools/ansible/roles/django/tasks/main.yml b/dev-tools/ansible/roles/django/tasks/main.yml index 75b4e88d51..819eb821b7 100644 --- a/dev-tools/ansible/roles/django/tasks/main.yml +++ b/dev-tools/ansible/roles/django/tasks/main.yml @@ -27,11 +27,19 @@ with_items: - "{{ groups['database'] }}" +# Use 'apply' to propagate delegate_to and become* to included tasks, see +# https://github.com/ansible/ansible/issues/35398 - name: Run tasks to setup Django database - include: database.yml - delegate_to: "{{ item }}" - become: yes - become_user: "{{ hostvars[item]['user'] }}" + include_tasks: database.yml + args: + apply: + delegate_to: "{{ item }}" + become: yes + become_user: "{{ hostvars[item]['user'] }}" + vars: + delegated_host: "{{ item }}" + django_public_ip: "{{ ansible_host }}" + django_internal_ip: "{{ ansible_default_ipv4.address }}" with_items: - "{{ django_database_hosts }}"
