Ansible 102: copy repositories file and install packages
How to create repo file and install packages using ansible
We need Create yml files on ansible machine. can add any IPs of machines in hosts file
Create local repo file:
[root@cloud ansible]# vim /etc/ansible/local.repo
[httpRepo]
name=http repository
baseurl=http://172.17.7.119/repos/rhel/7
enable=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
Create hosts file:
[root@cloud ansible]# vim /etc/ansible/hosts
[root@cloud ansible]# vim /etc/ansible/hosts
[update]
172.17.7.1
172.17.7.2
172.17.7.3
172.17.7.4
172.17.7.5
172.17.7.6
172.17.7.7
172.17.7.8
......
......
#########
Create YAML file to copy repo file from local to remote machines
[root@cloud ansible]# vim /etc/ansible/copy-repofile.yaml
[root@cloud ansible]# vim /etc/ansible/copy-repofile.yaml
- hosts: update
tasks:
- name: Ansible copy files remote to remote
copy:
src: /etc/ansible/local.repo
dest: /etc/yum.repos.d/
Run YAML file by ansible:
[root@cloud ansible]# ansible-playbook -s copy-repofile.yaml
Create YAML file to install packages:
[root@cloud ansible]# vim /etc/ansible/install-package.yaml
[root@cloud ansible]# vim /etc/ansible/install-package.yaml
---
- hosts: update
gather_facts: no
tasks:
- name: Install ksh
yum:
name: ksh
state: latest
Run YAML file by ansible:
[root@cloud ansible]# ansible-playbook -s install-package.yaml
Note that there two machine unreachable because of ssh authentication 😏😏
--------------------------------------------------------------------------------------------------------------------
Good Luck
https://www.linkedin.com/in/ahmedms/
Comments
Post a Comment