In this video we look at how to use a Git Push to deploy our Ansible configs. To start with, we need to make sure Git is installed on our Ansible Master server. 2 days ago - I'm pretty new to ansible, How should I write my playbook in order to install Git?
![]()
Ansible has a specific module for managing yum packages. You can install, remove, upgrade or downgrade versions, etc. Using this module. As with other package management modules in Ansible, the yum module also requires two parameters for the primary command.
Name – The package you want to install. State – what should be the state of the package after the task is completed; present or absent. By default, the value is ‘present.’ So if you do not give any value for this parameter, the package will be installed. Installing a package In the below task, I am trying to install the git package using the yum module. I have set the name parameter to ‘git’ and the state parameter to present. hosts: all tasks: - name: Install a yum package in Ansible example yum: name: git state: present If the package was not on the remote server, then the latest version will be installed.
Note: If you had seen the documentation, you might have noticed two parameters, ‘present’ and ‘installed’. Both of them has the same behavior.
Note: If the package was already installed on the server, then it won’t be updated to a new version. This is because the ‘state’ is already ‘present.’ If you run the task in debug mode, you would see a message like below.
Git-1.8.3.1-12.el74.x8664 providing git is already installed Installing the latest version If you want to install the newest version always then you can set the state parameter to ‘latest.’ This will install the latest package whether the package is present or not. The below task will install the latest version of git in every run. hosts: all tasks: - name: Install latest yum package example. Yum: name: git state: latest You would get such a message if the task were run in debug mode.Package git.x8664 0:1.8.3.1-6.el7 will be updated. Installing a specific version Sometimes you may want to install a particular version of the packages. It is usually due to some dependencies.
You can do this by appending the version also with the package name. eg: git-1.8.3.1-6.el7 The below task tries to install the git package with version and release, 1.8.3.1-6.el7 on the remote server. hosts: all tasks: - name: Install specific version of a package in Ansible.
Yum: name: git-1.8.3.1-6.el7 state: present output - root@rpm # yum info git Installed Packages Name: git Arch: x8664 Version: 1.8.3.1 Release: 6.el7 Now there are three possible scenarios in such cases. The package is not already installed on the system. This is fine. The package will be installed correctly every time. The package is already present installed, but the version you gave is more recent.
The updated version will be installed. The package is already present installed, but the version you gave is an older one.
In this case, it won’t install the downgrade version. But it won’t throw an error either. If you run the task in debug mode, you can see the following message. Package matching git-1.8.3.1-6.el7.x8664 already installed. Checking for update. NNothing to do n' But if you are okay with the version being downgraded, you need to mention it explicitly. You can set a parameter ‘allowdowngrade’ to true.
Note that this is only available from ‘2.4’.
I am trying to create a new Ansible role called 'Adminer' which requires the 'Apache' role. I've specified the Apache role as a dependency in meta/main.yml: - dependencies: - src: [email protected]:alexandrubau/ansible-apache.git name: apache I'm testing the Adminer role using Vagrant and I get the following error: vagrant provision default: Running provisioner: shell. Default: Running: inline script default: Running provisioner: ansiblelocal.
Vagrant has automatically selected the compatibility mode '2.0' according to the Ansible version installed (2.4.2.0). Alternatively, the compatibility mode can be specified in your Vagrantfile: default: Running ansible-playbook. The role 'apache' was not found in /vagrant/tests/roles:/home/vagrant/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/:/vagrant/tests The error appears to have been in '/vagrant/meta/main.yml': line 3, column 5, but may be elsewhere in the file depending on the exact syntax problem. The offending line appears to be: dependencies: - src: ^ here Ansible failed to complete successfully.
Any error output should be visible above. Please fix these errors and try again.
Shouldn't Ansible download the new role from the supplied git repo? Here's my Vagrant file: # -.- mode: ruby -.- # vi: set ft=ruby: $script =.
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |