0 votes
in Ansible by
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.

[root@ansible-server ~]# sudo yum install epel-release  

To install Ansible package on Centos/RHEL systems.

[root@ansible-server ~]# 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.

[root@ansible-server test_ansible]# ansible -i hosts all -m ping  

To issue a ping command only on hosts2.

[root@ansible-server test_ansible]# ansible -i hosts all -m ping --limit host2  

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

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

To install ncdu package on all hosts.

[root@ansible-server test_ansible]# ansible -i hosts all -m yum -a 'name=ncdu state=present'  

To remove ncdu package on all hosts.

[root@ansible-server test_ansible]# ansible -i hosts all -m yum -a 'name=ncdu state=absent'  

To build the directory structure for the role named role1.

[root@ansible-server test2]# ansible-galaxy init role1  

To dry-run p4.yml playbook.

[root@ansible-server test_ansible]# ansible-playbook -i hosts p4.yml --check  

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

[root@ansible-server test_ansible]# ansible-playbook -i hosts p4.yml -k

Related questions

0 votes
asked May 8, 2020 in Ansible by SakshiSharma
0 votes
asked Jan 29, 2020 in Ansible by rajeshsharma
...