Skip to content
This repository was archived by the owner on Oct 7, 2025. It is now read-only.
Merged
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
10 changes: 9 additions & 1 deletion docs/roles/debian/ansible.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Ansible
(Re-)install Ansible from the official repository.
Install Ansible in a Python virtual environment.

Note, it is vitally important that Ansible is *not* installed via `apt` or `pip` globally, or you will likely not get the correct version of Ansible when you try to run shell scripts.

This will not usually be necessary but, depending on your CI user set-up, you may need to add this as a pre-build step in your config where shell profiles are not automatically loaded, so Ansible is loaded into `$PATH`:

```sh
. /etc/profile.d/ansible-path.sh
```

<!--TOC-->
<!--ENDTOC-->
Expand Down
10 changes: 9 additions & 1 deletion roles/debian/ansible/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Ansible
(Re-)install Ansible from the official repository.
Install Ansible in a Python virtual environment.

Note, it is vitally important that Ansible is *not* installed via `apt` or `pip` globally, or you will likely not get the correct version of Ansible when you try to run shell scripts.

This will not usually be necessary but, depending on your CI user set-up, you may need to add this as a pre-build step in your config where shell profiles are not automatically loaded, so Ansible is loaded into `$PATH`:

```sh
. /etc/profile.d/ansible-path.sh
```

<!--TOC-->
<!--ENDTOC-->
Expand Down
28 changes: 28 additions & 0 deletions roles/debian/ansible/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
---
- name: Ensure system Ansible is not installed.
ansible.builtin.apt:
pkg: ansible
state: absent

- name: Ensure Ansible is not installed globally with pip3 on older versions of Debian.
ansible.builtin.pip:
name: ansible
state: absent
executable: pip3
when: ansible_distribution_major_version | int < 12

- name: Set up Python packages.
ansible.builtin.include_role:
name: debian/python_common

- name: Ensure pip is at latest version.
ansible.builtin.pip:
name:
- pip
state: latest
virtualenv: "{{ ce_ansible.venv_path | default(_venv_path) }}"
virtualenv_command: "{{ ce_ansible.venv_command | default(_venv_command) }}"
update_only: true
become: true
become_user: "{{ ce_provision.username }}"

- name: Install Ansible.
ansible.builtin.pip:
name:
Expand All @@ -23,6 +46,11 @@
become: true
become_user: "{{ ce_provision.username }}"

- name: Add the venv to $PATH using profile.d.
ansible.builtin.copy:
content: "export PATH=$PATH:{{ ce_ansible.venv_path | default(_venv_path) }}/bin"
dest: "/etc/profile.d/ansible-path.sh"

- name: Create systemd timer to upgrade Ansible.
ansible.builtin.include_role:
name: contrib/systemd_timers
Expand Down
21 changes: 17 additions & 4 deletions scripts/_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ parse_options(){
shift
BOTO_PROFILE="$1"
;;
"--ansible-path")
shift
ANSIBLE_PATH="$1"
;;
*)
usage
exit 1
Expand Down Expand Up @@ -140,11 +144,20 @@ cleanup_build_tmp_dir(){
}
# Trigger actual Ansible job.
ansible_play(){
if [ "$LINT" = "yes" ]; then
# apt repo installed
ANSIBLE_BIN=$(command -v ansible-lint)
if [ -n "$ANSIBLE_PATH" ]; then
if [ "$LINT" = "yes" ]; then
# apt repo installed
ANSIBLE_BIN=$(command -v ansible-lint)
else
ANSIBLE_BIN=$(command -v ansible-playbook)
fi
else
ANSIBLE_BIN=$(command -v ansible-playbook)
if [ "$LINT" = "yes" ]; then
# apt repo installed
ANSIBLE_BIN="$ANSIBLE_PATH/ansible-lint"
else
ANSIBLE_BIN="$ANSIBLE_PATH/ansible-playbook"
fi
fi
if [ "$ABSOLUTE_PLAYBOOK_PATH" = "yes" ]; then
ANSIBLE_CMD="$ANSIBLE_BIN $TARGET_PROVISION_PLAYBOOK"
Expand Down
1 change: 1 addition & 0 deletions scripts/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ usage(){
echo ''
echo 'Available options:'
echo '--ansible-extra-vars: Variable to pass as --extra-vars arguments to ansible-playbook. Make sure to escape them properly.'
echo '--ansible-path: Pass the path to the directory containing the Ansible binaries if you are not using the version of Ansible in PATH.'
echo '--workspace: Local existing clone of the repo/branch (if your deployment tool already has one). This will skip the cloning/fetching of the repo.'
echo '--user: Linux user executing the script (defaults to controller).'
echo '--absolute-playbook-path: Prevent prepending of the workspace path to the playbook path when Ansible is called.'
Expand Down