How can I add a PPA repository using Ansible?
Oh, this seems to have been entirely caused by me forgetting the -s
option!
Without this it wasn't using sudo
.
How should I use Ansible to add a repository to Ubuntu 16.04?
ansible_become_user
is the user "you become" so you are trying to execute the task as the mydeployer
user. You cannot do that, you should run it as the root
.
Remove ansible_become_user=mydeployer
from your inventory. Or change it to ansible_become_user=root
, but this is default value anyway.
Is there a more elegant way to manage a mix of linux mint and ubuntu servers using ansible?
One way to do this is to use the omit
filter. See the documentation. This can be used to make the codename
parameter optional when running the apt_repository
module.
Example:
- name: set distro codename when OS is Linux Mint
ansible.builtin.set_fact:
distro_codename: focal
when: ansible_facts['distribution'] == 'Linux Mint' and ansible_distribution_release == 'una'
- name: Add Ansible PPA
ansible.builtin.apt_repository:
repo: "ppa:ansible/ansible"
codename: "{{ distro_codename | default(omit) }}"
This will ensure that the codename
is used while creating APT repository if it is set (for Linux Mint in this case). Otherwise it will be omitted.
Question on updating packages using Ansible
I was able to successfully update my packages with the latest updates for certain packages I wanted such as ansible, git, and vagrant. Here is how the code looks:
###### PPA Repository Setup
###### Add a complete set of repositories into the source list to be updated to the latest version.
###### The only repositories that are up to date are git, ansible, and vagrant. The others will have to be
###### installed separately.
- name: Add stable repositories from PPA to system
apt_repository:
repo: "{{ item }}"
loop:
- ppa:ansible/ansible # Latest Ansible repo
- ppa:git-core/ppa # Latest git repo
- ppa:tiagohillebrandt/vagrant # Latest Vagrant repo (this is a personal ppa so this needs to be wary)
And let's say you want to add the GPG keys for different repositories such as Docker, here is an example:
###### Docker Setup
###### Setup Docker's GPG key and Docker's repository. It is recommended prior to installation to have
###### these apps installed: apt-transport-https, ca-certificates, curl, gnupg-agent, and software-properties-common.
- name: Add Docker GPG apt key
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present
- name: Add Docker Repository
apt_repository:
repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable
state: present
Now the repo named deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable
is something I need to work on. If the version of your Ubuntu let's say 18.04. You would replace $(lsb_release -cs)
with bionic
. However, lsb_release
should provide the version. Thanks for the help all and I hope this helps anyone out there
Ansible no longer works
Your issue is coming from the fact that you are using the instructions to install Ansible on an Ubuntu distribution, when, as you stated it, Pengwin is a Debian based one.
So you should use the chapter on how to install Ansible on Debian and not how to install Ansible on Ubuntu.
Better, still, because Pengwin is a very particular distribution, since it is a WSL one, you might want to try the installation via pip
:
Ansible can be installed with
pip
, the Python package manager. If
pip
isn’t already available on your system of Python, run the
following commands to install it:$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
$ python get-pip.py --user
Then install Ansible:
$ pip install --user ansible
https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-ansible-with-pip
Git package upgrade to latest using ansible
Ansible executes the same code, across all the inventory hosts. You should start with what's different on 50.51.52.21
. It probably has a different repo that provides git.
Validate that with grep ^ /etc/apt/sources.list /etc/apt/sources.list.d/* | grep git
(on the working node), it will list all the installed repositories.
Add a task to validate the git repository is installed on your ubuntu server.
- apt_repository:
repo: 'ppa:git-core/ppa'
state: present
This should be set as the first task, then run the apt update and ultimately install git task.
How to Install Java 8 Using Ansible Without PPA
In my case, I sign up for oracle account then download the .rpm/.tar.gz package directly from Oracle into one of my PC.
I transfer the files to an ansible control server and use ansible playbook to distribute the files to other remote servers using copy module.
Finally I write the ansible role to extract and install them locally using the following methods.
CentOS: You can easily use yum to install the rpm package.
Ubuntu: Follow these steps.
https://www.vultr.com/docs/how-to-manually-install-java-8-on-ubuntu-16-04
It's not quite a good way since you need to transfer the installer to each server.
I too still looking for a way to use script to download from the oracle website directly, but there is no way to do without sign on authentication.
Related Topics
The Button.Connect Syntax in Genie
Convert a Base64 Ldif File to Plaintext (For Import)
How to Two Mmap on Same /Dev File
Omnibus or Source - Can't Decide Which One to Use for Gitllab Backup/Restore
How to Disable The Gnome Desktop Screen Lock
Does Routing Affect a Socket with a Bound Source Address
Run Script on Startup with Raspbian Jessi Wheezy and Raspberry Pi2B
Find All Instances of Word Occurring in a File
How to Strip Down My Yocto Linux
How to Determine from Where a Program Jumped to an Invalid Address - Without Single-Stepping
Setting an Acpi Field in Linux
Chef-Server Stuck Ruby_Block[Supervise_Rabbitmq_Sleep] Action Run on Docker Container