Skip to content

Commit

Permalink
Add support for Ansible 2.9
Browse files Browse the repository at this point in the history
  • Loading branch information
walterdolce committed Jun 7, 2019
1 parent 9d12d88 commit 9cd8435
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 80 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Example Playbook

- hosts: all
roles:
- role: wtanaka.gcloud_sdk
- role: wtanaka.gcloud-sdk

Variables
---------
Expand Down
10 changes: 7 additions & 3 deletions tasks/Debian.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
---
- include: get_key.yml
- include_tasks: get_key.yml

- name: add google cloud key to apt-key
apt_key: file=/root/A7317B0F.gpg
become: yes

- name: sources.list
template: >
src=google-cloud-sdk.list.j2
dest=/etc/apt/sources.list.d/google-cloud-sdk.list
force=no
register: sources_list_result
become: yes

# Install apt-transport-https
- name: install apt-transport-https
action: "{{backcompat_pkg_mgr}} name=apt-transport-https"
register: result_install_transport_https
until: result_install_transport_https|success
until: result_install_transport_https is success
# Workaround https://github.com/ansible/ansible/issues/16868 and
# increase default retry count
retries: 20
delay: 10
become: yes

- name: apt-get update
apt: update_cache=true cache_valid_time=0
when: sources_list_result.changed
register: result_apt_update
until: result_apt_update|success
until: result_apt_update is success
# Workaround https://github.com/ansible/ansible/issues/16868 and
# increase default retry count
retries: 20
delay: 10
become: yes
6 changes: 3 additions & 3 deletions tasks/Debian_sudo.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- include: get_key_sudo.yml
- include_tasks: get_key_sudo.yml

- name: add google cloud key to apt-key
apt_key: file=/root/A7317B0F.gpg
Expand All @@ -18,7 +18,7 @@
action: "{{backcompat_pkg_mgr}} name=apt-transport-https"
sudo: yes
register: result_install_transport_https
until: result_install_transport_https|success
until: result_install_transport_https is success
# Workaround https://github.com/ansible/ansible/issues/16868 and
# increase default retry count
retries: 20
Expand All @@ -29,7 +29,7 @@
when: sources_list_result.changed
sudo: yes
register: result_apt_update
until: result_apt_update|success
until: result_apt_update is success
# Workaround https://github.com/ansible/ansible/issues/16868 and
# increase default retry count
retries: 20
Expand Down
9 changes: 5 additions & 4 deletions tasks/RedHat.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
- name: repo
template: >
src=google-cloud-sdk.repo.j2
dest=/etc/yum.repos.d/google-cloud-sdk.repo
force=no
template:
src: google-cloud-sdk.repo.j2
dest: /etc/yum.repos.d/google-cloud-sdk.repo
force: no
become: yes
12 changes: 7 additions & 5 deletions tasks/become.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---
- { become: yes, include: compat.yml }
- { become: yes, include: Debian.yml, when: ansible_os_family == 'Debian' }
- { become: yes, include: RedHat.yml, when: ansible_os_family == 'RedHat' }
- { become: yes, include: install_package_names.yml }
- { become: yes, include: install_additional_packages.yml }
- include_tasks: compat.yml
- include_tasks: Debian.yml
when: ansible_os_family == 'Debian'
- include_tasks: RedHat.yml
when: ansible_os_family == 'RedHat'
- include_tasks: install_package_names.yml
- include_tasks: install_additional_packages.yml
38 changes: 18 additions & 20 deletions tasks/compat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
(apt-get update -qq && apt-get install -y python-apt)));
fi
register: result_python_apt
until: result_python_apt|success
until: result_python_apt is success
# Workaround https://github.com/ansible/ansible/issues/16868 and
# increase default retry count
retries: 20
delay: 10
when: should_run and ansible_os_family == 'Debian'
changed_when: False
become: yes

- name: install python-pycurl on ansible < 1.6.0 and ubuntu et al
raw: >
Expand All @@ -25,13 +26,14 @@
(apt-get update -qq && apt-get install -y python-pycurl)));
fi
register: result_python_pycurl
until: result_python_pycurl|success
until: result_python_pycurl is success
# Workaround https://github.com/ansible/ansible/issues/16868 and
# increase default retry count
retries: 20
delay: 10
when: should_run and ansible_os_family == 'Debian'
changed_when: False
become: yes

- name: install python2-yum on ansible <=1.9.2/fedora 24
raw: >
Expand All @@ -40,13 +42,14 @@
(> /dev/null command -v yum && ! > /dev/null command -v dnf && yum install -y python2-yum);
fi
register: result_python_yum
until: result_python_yum|success
until: result_python_yum is success
# Workaround https://github.com/ansible/ansible/issues/16868 and
# increase default retry count
retries: 20
delay: 10
when: should_run and ansible_os_family == 'RedHat'
changed_when: False
become: yes

- name: install python2-dnf on ansible 2.1/fedora 24
raw: >
Expand All @@ -55,13 +58,14 @@
(> /dev/null command -v dnf && dnf install -y python2-dnf);
fi
register: result_python_dnf
until: result_python_dnf|success
until: result_python_dnf is success
# Workaround https://github.com/ansible/ansible/issues/16868 and
# increase default retry count
retries: 20
delay: 10
when: should_run and ansible_os_family == 'RedHat'
changed_when: False
become: yes

# Set backcompat_pkg_mgr for versions of ansible that set
# ansible_pkg_mgr to yum instead of dnf
Expand All @@ -71,14 +75,15 @@
ignore_errors: True
when: should_run and ansible_os_family == 'RedHat'
changed_when: False
become: yes

- set_fact:
backcompat_pkg_mgr: 'dnf'
when: should_run and ansible_os_family == 'RedHat' and dnf_result|success
when: should_run and ansible_os_family == 'RedHat' and dnf_result is success

- set_fact:
backcompat_pkg_mgr: '{{ansible_pkg_mgr}}'
when: should_run and ansible_os_family == 'RedHat' and dnf_result|failed
when: should_run and ansible_os_family == 'RedHat' and dnf_result is failed

- set_fact:
backcompat_pkg_mgr: '{{ansible_pkg_mgr}}'
Expand All @@ -100,41 +105,34 @@
ignore_errors: True
changed_when: False
when: should_run
become: yes

# Install wget due to https://github.com/ansible/ansible/issues/12161
- name: install wget with non-dnf
action: "{{backcompat_pkg_mgr}} name=wget"
register: result_wget
until: result_wget|success
until: result_wget is success
# Workaround https://github.com/ansible/ansible/issues/16868 and
# increase default retry count
retries: 20
delay: 10
when: >
should_run and
(backcompat_pkg_mgr == "yum" or backcompat_pkg_mgr == "apt")
and wget_result|failed
and wget_result is failed
become: yes

# Install wget due to https://github.com/ansible/ansible/issues/12161
# Use command since dnf was only added as a module in ansible 1.9.0
- name: install wget with dnf
command: dnf install -y wget
register: result_wget_dnf
until: result_wget_dnf|success
until: result_wget_dnf is success
# Workaround https://github.com/ansible/ansible/issues/16868 and
# increase default retry count
retries: 20
delay: 10
args:
creates: /usr/bin/wget
when: should_run and backcompat_pkg_mgr == "dnf" and wget_result|failed

- name: Remove wheezy-updates
command: sed -i.old -e 's/\(.*deb.debian.org\/debian wheezy-updates\)/#\1/' /etc/apt/sources.list
changed_when: False
when: should_run and ansible_os_family == 'Debian'

- name: Switch debian wheezy to archives
command: sed -i.old -e 's/deb.debian.org\/debian wheezy/archive.debian.org\/debian wheezy/' /etc/apt/sources.list
changed_when: False
when: should_run and ansible_os_family == 'Debian'
when: should_run and backcompat_pkg_mgr == "dnf" and wget_result is failed
become: yes
32 changes: 10 additions & 22 deletions tasks/compat_sudo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
(apt-get update -qq && apt-get install -y python-apt)));
fi
register: result_python_apt
until: result_python_apt|success
until: result_python_apt is success
# Workaround https://github.com/ansible/ansible/issues/16868 and
# increase default retry count
retries: 20
Expand All @@ -27,7 +27,7 @@
(apt-get update -qq && apt-get install -y python-pycurl)));
fi
register: result_python_pycurl
until: result_python_pycurl|success
until: result_python_pycurl is success
# Workaround https://github.com/ansible/ansible/issues/16868 and
# increase default retry count
retries: 20
Expand All @@ -43,7 +43,7 @@
(> /dev/null command -v yum && ! > /dev/null command -v dnf && yum install -y python2-yum);
fi
register: result_python_yum
until: result_python_yum|success
until: result_python_yum is success
# Workaround https://github.com/ansible/ansible/issues/16868 and
# increase default retry count
retries: 20
Expand All @@ -59,7 +59,7 @@
(> /dev/null command -v dnf && dnf install -y python2-dnf);
fi
register: result_python_dnf
until: result_python_dnf|success
until: result_python_dnf is success
# Workaround https://github.com/ansible/ansible/issues/16868 and
# increase default retry count
retries: 20
Expand All @@ -78,11 +78,11 @@

- set_fact:
backcompat_pkg_mgr: 'dnf'
when: should_run and ansible_os_family == 'RedHat' and dnf_result|success
when: should_run and ansible_os_family == 'RedHat' and dnf_result is success

- set_fact:
backcompat_pkg_mgr: '{{ansible_pkg_mgr}}'
when: should_run and ansible_os_family == 'RedHat' and dnf_result|failed
when: should_run and ansible_os_family == 'RedHat' and dnf_result is failed

- set_fact:
backcompat_pkg_mgr: '{{ansible_pkg_mgr}}'
Expand All @@ -109,7 +109,7 @@
- name: install wget with non-dnf
action: "{{backcompat_pkg_mgr}} name=wget"
register: result_wget
until: result_wget|success
until: result_wget is success
# Workaround https://github.com/ansible/ansible/issues/16868 and
# increase default retry count
retries: 20
Expand All @@ -118,31 +118,19 @@
when: >
should_run and
(backcompat_pkg_mgr == "yum" or backcompat_pkg_mgr == "apt")
and wget_result|failed
and wget_result is failed
# Install wget due to https://github.com/ansible/ansible/issues/12161
# Use command since dnf was only added as a module in ansible 1.9.0
- name: install wget with dnf
command: dnf install -y wget
register: result_wget_dnf
until: result_wget_dnf|success
until: result_wget_dnf is success
# Workaround https://github.com/ansible/ansible/issues/16868 and
# increase default retry count
retries: 20
delay: 10
args:
creates: /usr/bin/wget
sudo: yes
when: should_run and backcompat_pkg_mgr == "dnf" and wget_result|failed

- name: Remove wheezy-updates
command: sed -i.old -e 's/\(.*deb.debian.org\/debian wheezy-updates\)/#\1/' /etc/apt/sources.list
changed_when: False
sudo: yes
when: should_run and ansible_os_family == 'Debian'

- name: Switch debian wheezy to archives
command: sed -i.old -e 's/deb.debian.org\/debian wheezy/archive.debian.org\/debian wheezy/' /etc/apt/sources.list
changed_when: False
sudo: yes
when: should_run and ansible_os_family == 'Debian'
when: should_run and backcompat_pkg_mgr == "dnf" and wget_result is failed
3 changes: 2 additions & 1 deletion tasks/get_key.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
args:
creates: /root/A7317B0F.gpg
register: result_download
until: result_download|success
until: result_download is success
# Workaround https://github.com/ansible/ansible/issues/16868 and
# increase default retry count
retries: 20
delay: 10
become: yes
2 changes: 1 addition & 1 deletion tasks/get_key_sudo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
creates: /root/A7317B0F.gpg
sudo: yes
register: result_download
until: result_download|success
until: result_download is success
# Workaround https://github.com/ansible/ansible/issues/16868 and
# increase default retry count
retries: 20
Expand Down
9 changes: 6 additions & 3 deletions tasks/install_additional_packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- name: install {{gcloud_sdk_additional_package_names | join(' ')}} with default package manager
action: "{{backcompat_pkg_mgr}} name={{item}}"
register: result_install_additional
until: result_install_additional|success
until: result_install_additional is success
# Workaround https://github.com/ansible/ansible/issues/16868 and
# increase default retry count
retries: 20
Expand All @@ -11,6 +11,7 @@
gcloud_sdk_additional_package_names is defined and
(backcompat_pkg_mgr == "yum" or backcompat_pkg_mgr == "apt")
with_items: "{{ gcloud_sdk_additional_package_names }}"
become: yes

# Handle dnf case for Fedora
- name: "check if {{gcloud_sdk_additional_package_names | join(' ')}} exists"
Expand All @@ -19,16 +20,18 @@
ignore_errors: True
register: package_exists_result
when: gcloud_sdk_additional_package_names is defined and backcompat_pkg_mgr == "dnf"
become: yes

# Use command since dnf was only added as a module in ansible 1.9.0
- name: install {{gcloud_sdk_additional_package_names | join (' ')}} with dnf
command: dnf install -y {{gcloud_sdk_additional_package_names | join(' ')}}
register: result_install_additional_dnf
until: result_install_additional_dnf|success
until: result_install_additional_dnf is success
# Workaround https://github.com/ansible/ansible/issues/16868 and
# increase default retry count
retries: 20
delay: 10
when: >
gcloud_sdk_additional_package_names is defined and backcompat_pkg_mgr == "dnf" and
package_exists_result|failed
package_exists_result is failed
become: yes
Loading

0 comments on commit 9cd8435

Please sign in to comment.