-> show kernel version and other info
# uname -a
-> show machine info
# hostnamectl
-> show specific release version
# rpm --query centos-release
Thursday, 9 August 2018
How to check available yum packages?
e.g. install/update ansible by yum
-> Go to repo path
# cd /etc/yum.repos.d/
-> Add source paths into repo file to be able to install ansible
# vi epel.repo
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch/debug
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
#baseurl=http://download.fedoraproject.org/pub/epel/7/SRPMS
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
-> Search yum package
# yum search ansible
-> Check available yum package
# yum list available | grep ansible
-> Check available all yum packages with its duplicates
# yum list available --showduplicates | grep ansible
-> Install ansible
# yum install ansible
-> Download only yum package
# yum install ansible --downloadonly --downloaddir=/root
-> Check available yum packages for upgrade
# yum check-updates | grep ansible
-> Update ansible
# yum update ansible
-> Check yum history
# yum history list
-> Go to repo path
# cd /etc/yum.repos.d/
-> Add source paths into repo file to be able to install ansible
# vi epel.repo
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch/debug
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
#baseurl=http://download.fedoraproject.org/pub/epel/7/SRPMS
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
-> Search yum package
# yum search ansible
-> Check available yum package
# yum list available | grep ansible
-> Check available all yum packages with its duplicates
# yum list available --showduplicates | grep ansible
# yum install ansible
-> Download only yum package
# yum install ansible --downloadonly --downloaddir=/root
-> Check available yum packages for upgrade
# yum check-updates | grep ansible
-> Update ansible
# yum update ansible
-> Check yum history
# yum history list
How to install/configure/run ansible?
-> Set hostname
# hostnamectl set-hostname ansible_host
-> Add remote hosts into /etc/hosts file
# vi /etc/hosts
10.10.10.2 remote_host_2
10.10.10.3 remote_host_3
-> Generate ssh key without passphase
# ssh-keygen
-> Install ssh key into remote servers
# ssh-copy-id remote_host_2
# ssh-copy-id remote_host_3
-> Install ansible rpm packages
# yum install ansible
-> Add remote hosts as nodes into /etc/ansible/hosts file
# vi /etc/ansible/hosts
[remote_hosts]
remote_host_2
remote_host_3
-> Prepare an ansible playbook in /etc/ansible/
# vi my_very_first_playbook.yml
# example playbook
- name: Run the role for me
hosts: remote_hosts
roles:
- example-role
-> Prepare a role for the playbook in /etc/ansible/roles/example-role/
# vi main.yml
- name: checking Command Scheduler service
service:
name=crond.service
state=started
-> Run the playbook in /etc/ansible/
# ansible-playbook my_very_first_playbook.yml
or
# ansible-playbook -i hosts my_very_first_playbook.yml
(i -> inventory, its default location is /etc/ansible/hosts)
-> To check the ansible logs
# tail -f /var/log/ansible.log
# hostnamectl set-hostname ansible_host
-> Add remote hosts into /etc/hosts file
# vi /etc/hosts
10.10.10.2 remote_host_2
10.10.10.3 remote_host_3
-> Generate ssh key without passphase
# ssh-keygen
-> Install ssh key into remote servers
# ssh-copy-id remote_host_2
# ssh-copy-id remote_host_3
-> Install ansible rpm packages
# yum install ansible
-> Add remote hosts as nodes into /etc/ansible/hosts file
# vi /etc/ansible/hosts
[remote_hosts]
remote_host_2
remote_host_3
-> Prepare an ansible playbook in /etc/ansible/
# vi my_very_first_playbook.yml
# example playbook
- name: Run the role for me
hosts: remote_hosts
roles:
- example-role
-> Prepare a role for the playbook in /etc/ansible/roles/example-role/
# vi main.yml
- name: checking Command Scheduler service
service:
name=crond.service
state=started
-> Run the playbook in /etc/ansible/
# ansible-playbook my_very_first_playbook.yml
or
# ansible-playbook -i hosts my_very_first_playbook.yml
(i -> inventory, its default location is /etc/ansible/hosts)
-> To check the ansible logs
# tail -f /var/log/ansible.log
Labels:
ansible,
installation,
log
Tuesday, 7 August 2018
usage of "run_once: true" option
If you want to run only once a specific task during all playbook execution, you may add "run_once: true" option into your task to do this.
e.g. example task
- name: prompt for directory name
run_once: true
pause:
prompt: "Please enter directory name: "
register: input_dir_name
- name: show input
debug:
msg="{{ input_dir_name.user_input }}"
e.g. example task
- name: prompt for directory name
run_once: true
pause:
prompt: "Please enter directory name: "
register: input_dir_name
- name: show input
debug:
msg="{{ input_dir_name.user_input }}"
Subscribe to:
Posts (Atom)