Hi i am new to ansible i have to deploy nodejs12.8.4, SSL and ngnix latest to Ubuntu 20.04 server can someone guide me how to do it thank you.
this is my yml file:
hosts: all
become: true
tasks:
- name: install nodejs prerequisites
apt:
name:
- apt-transport-https
- gcc
- g++
- make
state: present
- name: add nodejs apt key
apt_key:
url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key
state: present
- name: add nodejs repository
apt_repository:
repo: deb https://deb.nodesource.com/node_12.x {{ ansible_lsb.codename }} main
state: present
update_cache: yes
- name: install nodejs
apt:
name: nodejs
state: present
it install nodejs 12 now i want to install nginx in same file how i add new task.
Try Ansible NGINX Role. See details at Github.
Q: "I want to install Nginx in the same file how I add a new task?"
A: Include the role
- include_role:
name: nginx
Download the role. See Roles and Using Roles in particular.
Related
I have trouble in setting up version for apache and nginx for below playbook.
---
- name: Install appache restart apache and install git
hosts: all
become: true
tasks:
- name : install appache2
package : name=apache2 state=present
- name : restart appache2
command : systemctl restart apache2
command : systemctl stop apache2
- name : uninstall appache2
package : name=apache2 state=absent
- name : Install git
package : name=git state=present
- name : install nginx
package : name=nginx state=present
I will write the examples as if you want to install apache v4.23 (supposedly it exists in your distribution and available in your package repository)
If you are using RHEL distros (Centos - Redhat // Or yum as package manager), that would be the format you will be using "$packagename-$version"
# Apache package name on RHEL is httpd, just putting apache for comparison.
tasks:
- name: install apache2
package:
name: apache2-4.23
state: present
Compared to if you are using apt for package management, that would be the format "$packagename=$version"
tasks:
- name: install apache2
package:
name: apache2=4.23
state: present
And generally it is one of the above 2 syntaxes.. So if you are not sure, try once with "-".. If it does not work, try with "=".
And on a side note, use service module to restart your services instead of using the command module
tasks:
- name: restart apache2
service:
name: apache2
state: started
I got some trouble with automating an installation using ansible.
I use this role (https://github.com/elastic/ansible-elasticsearch) to install elasticsearch on my ubuntu 16.04 server.
The role depends on the package python-jmespath, as mentioned in the documentation.
The role DOES NOT install the package itsself, so i try to install it before role execution.
- hosts: elasticsearch_master_servers
become: yes
tasks:
- name: preinstall jmespath
command: "apt-get install python-jmespath"
- name: Run the equivalent of "apt-get update" as a separate step
apt:
update_cache: yes
- hosts: elasticsearch_master_servers
become: yes
roles:
- role: elastic.elasticsearch
vars:
...
When running the playbook i expect the python-jmespath package to be installed before execuction of role takes place, but role execution fails with
You need to install \"jmespath\" prior to running json_query filter"
When i check if the package is installed manually using dpkg -s python-jmespath i can see the package is installed correctly.
A second run of the playbook (with the package already installed) doesnt fail.
Do I miss an ansible configuration, that updates the list of installed packages during the playbook run ?
Am I doing something wrong in general ?
Thanks in advance
FWIW. It's possible to tag installation tasks and install the packages in the first step. For example
- name: install packages
package:
name: "{{ item.name }}"
state: "{{ item.state|default('present') }}"
state: present
loop: "{{ packages_needed_by_this_role }}"
tags: manage_packages
Install packages first
shell> ansible_playbook my-playbook.yml -t manage_packages
and then run the playbook
shell> ansible_playbook my-playbook.yml
Notes
This approach makes checking of the playbooks with "--check" much easier.
Checking idempotency is also easier.
With tags: [manage_packages, never] the package task will be skipped when not explicitly selected. This will speed up the playbook.
I'm trying to install kubelet with Ansible, but I'm struggling to do it.
This is my playbook:
---
- hosts: all
become: yes
tasks:
- name: install docker
yum:
name: docker
state: present
update_cache: true
- name: add repo
yum_repository:
name: kuberepo
description: kubernetes-repo
baseurl: "https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64"
enabled: yes
gpgcheck: yes
repo_gpgcheck: yes
gpgkey:
- "https://packages.cloud.google.com/yum/doc/yum-key.gpg"
- "https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg"
- name: setenforce
shell: setenforce 0
- name: install kubelet
yum:
name: kubelet
state: present
update_cache: true
This is the error when i run the playbook (ansible-playbook -i hosts kube-dependencies.yml)
The "ok" from [master] node is because I manually executed "sudo yum install kubelet" on that machine, and it worked.
Conclusions:
So basically, manually executing the yum install command it works, but I can't make it work with ansible.
Any clues? Thanks in advance.
I had the same issue, I fix it adding version of kubelet
apt:
name: kubelet=1.20.0-00
state: present
update_cache: true
That worked for me
same issue with kubeletadm
- name: install kubeadm
apt:
name: kubeadm=1.14.0-00
state: present
Error
solution
- name: install kubeadm
apt:
name: kubeadm=1.20.0-00
state: present
Fix the problem
I hope I've helped
The best solution is to upgrade the version to install.
in every new version k8s changed many configs so some components become npt compatible (kubelet vs kubernetes-cni (= 0.7.5) are not compatible.
version up, if not works then find another solution.
hope that this clarification help.
I am trying to install Apache2 with Ansible. I have a role and handler for Apache.
My playbook (site.yml) contains:
---
- hosts: webservers
remote_user: ansrun
become: true
become_method: sudo
The Ansible role file contains:
---
- name: Install Apache 2
apt: name={{ item }} update_cache=yes state=present
with_items:
- apache2
when: ansible_distribution == "Ubuntu"
- name: Enable mod_rewrite
apache2_module: name=rewrite state=present
notify:
- reload apache2
Whenever I run the playbook, I get this message, but nothing has changed.
changed: [10.0.1.200] => (item=[u'apache2'])
I think this has something to do with the conditional.
You are running into a problem introduced to Ansible 2.2.0 (and fixed in 2.2.1).
With update_cache=yes the apt module was made to return changed-status whenever APT cache update occurred, not only when the actual package was upgraded.
You need to upgrade Ansible to version 2.2.1 (released officially on Jan 16th)
You need to do one of the following:
upgrade Ansible to at least 2.2.1 (currently in release candidate state and not available in PyPI, so you'd have to run Ansible from source);
downgrade Ansible to 2.1.3;
retain Ansible 2.2.0 and split the Install Apache 2 task into two:
one for cache update only (maybe with changed_when set to false),
one for the actual apache2 package installation (without update_cache=yes), calling the handler.
I'm getting the following error when trying to run a YML file:-
user#ubuntuA:~$ ansible-playbook -i hostfile setup.yml
ERROR:
apt is not a legal parameter of an Ansible Play
Ansible version: 1.9.2
yml-file:-
---
- name: Install MySQL server
apt: name=mysql-server state=latest
- name: Install Apache module for MySQL authentication
apt: name=libapache2-mod-auth-mysql state=latest
- name: Install MySQL module for PHP
apt: name=php5-mysql state=latest
Your yml file should look something like this:
---
- hosts: all
become: yes
tasks:
- name: Install packages
apt:
name:
- mysql-server
- libapache2-mod-auth-mysql
- php5-mysql
state: latest
cache_valid_time: 3600 # update cache if more than an hour old
You are trying to execute your setup.yml file directly with ansible-playbook. As #smiler171 mentioned in his answer, correct format for this is the following:
---
- hosts: all
tasks:
- name: Install MySQL server
apt: name=mysql-server state=latest
- name: Install Apache module for MySQL authentication
apt: name=libapache2-mod-auth-mysql state=latest
- name: Install MySQL module for PHP
apt: name=php5-mysql state=latest
Your current file format is for imports and includes. It is useful if you want to reuse tasks from setup.yml somewhere else. In this case you can create another file (let's say playbook.yml) like that:
---
- hosts: all
tasks:
- import_tasks: setup.yml
and run it:
ansible-playbook -i hostfile playbook.yml
Usually, that means that your playbook yml file does not comply with yml syntax. Check for spaces , hyphen etc. Take a look at existing working yml files, like the one pasted by smiller171 in the above answer. I also had a similar error , turned out that my syntax was incorrect.