Ansible Project Workflow

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

ANSIBLE PROJECT WORKFLOW

***check ufw for listening port for hhtpd/apache if webserver not running in host machine***

1) Have 1 server as the main Ansible server.


2) Establish ssh token using pub key connection to all the dependent servers to the main
Ansible server.
3) Establish ssh token using private key connection to all the dependent servers to the main
Ansible server. This is the one that will allow ansible to configure the infra in the dependent
servers.
4) Create a git repository for the main Ansible server.
5) Create an inventory file containing all the dependent ip addresses and push to the git repo.
6) Install Epel repository and then install Ansible
7) To connect ansible to all the dependent server(hosts) use :
a. Use command :
i. ansible all –key-file <path to key file> -i (inventory file)<inventory file> -
m(module) ping  ansible all –key-file ~/.ssh/ansible -I inventory -m ping
8) Add ansible config file inside the git repo directory:
a. Inside it include  [defaults] -> inventory, private_key_file
b. By doing this the command at 7a. will be shortened to  ansible all -m ping
9) Other commands include:
a. List of hosts  ansible all –list-hosts
b. Facts about hosts  ansible all -m gather_facts --limit <ip address>
10) Sudo yum update to other host with sudo privileges ansible all -m(module) <package (yum
for rhel)(apt for debian)> -a(argument)=true –become(sudo) –ask-become-pass(ask sudo
pw)  ansible all -m yum -a update_cache=true –become –ask-become-pass
[check docs.ansible.com for yum module or apt module arguments]
11) Installing other packages (vim-nox)  ansible all -m yum -a name=vim-nox --become –ask-
become-pass
12) To check logs of installation  in the hosts, cd /var/log/apt(Debian) or dnf.log(rhel)
13) Making sure all packages are up to date  ansible all -m yum -a “name=* state=latest” –
becom –ask-become-pass
14) Create a yaml file for your ansible playbook. Then you can run your playbook using ansible-
playbook –ask-become-pass <playbook name>
15) To remove a package, update the state in the yaml file  state: absent
16) If you configure tags in your playbook, you can use the tags to target specific plays 
ansible-playbook –tags < ”tag name1, tag name2” > --ask-become-pass
<playbookname>.yml
17) Regular expressions(regexp)?
18) Other modules:
a. Ansible.builtin.systemd
b. Lineinfile
c. Package/yum/apt
d. Unarchive
e. user
19) Register is used to make a variable for change (system)
INVENTORY FORMAT

[webserver]

54.243.18.36

[docker-server]

50.17.85.226

ANSIBLE CONFIGURATION FILE FORMAT

[defaults]

inventory = /home/ansibleadmin/ansible2.0/inventory

remote_user = ansibleadmin

private_key_file = /home/ansibleadmin/ansible

become = True

for reference = https://gist.github.com/alivx/2a4ca3e577ead4bd38d247c258e6513b

ANSIBLE PLAYBOOK FILE FORMAT

You might also like