in Ansible by
Q:
ansible commands cheat sheets

1 Answer

0 votes
by
Here are some commands which are used in Ansible, such as:

To install EPEL repo on Centos/RHEL systems.

[[email protected] ~]# sudo yum install epel-release  

To install Ansible package on Centos/RHEL systems.

[[email protected] ~]# sudo  yum install -y ansible  

To perform an update to the packages on Debian/Ubuntu systems.

$ sudo apt update  

To install the software properties-common-package on Debian/Ubuntu systems.

$ sudo apt install software-properties-common  

To install Ansible personal package archive on Debian/Ubuntu systems.

$ sudo apt-add-repository ppa:ansible/ansible  

To install Ansible on Debian/Ubuntu systems.

$ sudo apt update  

$ sudo apt install ansible  

To issue a ping command on all servers defined in the inventory file named hosts.

[[email protected] test_ansible]# ansible -i hosts all -m ping  

To issue a ping command only on hosts2.

[[email protected] test_ansible]# ansible -i hosts all -m ping --limit host2  

To copy the file "testfile" on all hosts in the inventory file.

[[email protected] test_ansible]# ansible -i hosts all -m copy -a "src=/root/test_ansible/testfile dest=/tmp/testfile"  

To install ncdu package on all hosts.

[[email protected] test_ansible]# ansible -i hosts all -m yum -a 'name=ncdu state=present'  

To remove ncdu package on all hosts.

[[email protected] test_ansible]# ansible -i hosts all -m yum -a 'name=ncdu state=absent'  

To build the directory structure for the role named role1.

[[email protected] test2]# ansible-galaxy init role1  

To dry-run p4.yml playbook.

[[email protected] test_ansible]# ansible-playbook -i hosts p4.yml --check  

To run a p4.yml playbook with password authentication for all hosts.

[[email protected] test_ansible]# ansible-playbook -i hosts p4.yml -k
Click here to read more about Ansible
Click here to read more about Insurance

Related questions

0 votes
asked May 8, 2020 in Ansible by SakshiSharma
0 votes
asked Jan 29, 2020 in Ansible by rajeshsharma
0 votes
asked Jan 29, 2020 in Ansible by rajeshsharma
0 votes
asked Nov 13, 2019 in Ansible by rajeshsharma
0 votes
0 votes
0 votes
asked Aug 24, 2019 in Ansible by rahulsharma
...