# How to make and run Ansible Playbooks in CentOS 7?

**URL:** <https://forum.ansible.com/t/how-to-make-and-run-ansible-playbooks-in-centos-7/33792>\
**Category:** Ansible Project\
**Created:** [September 11, 2020, 2:51pm UTC](https://forum.ansible.com/t/how-to-make-and-run-ansible-playbooks-in-centos-7/33792 "2020-09-11T14:51:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prabhakaran\_Karuppai](https://avatars.discourse-cdn.com/v4/letter/p/c4cdca/32.png) [@Prabhakaran\_Karuppai](https://forum.ansible.com/u/Prabhakaran_Karuppai)\
**Post date:** [September 11, 2020, 2:51pm UTC](https://forum.ansible.com/t/how-to-make-and-run-ansible-playbooks-in-centos-7/33792/1 "2020-09-11T14:51:04Z")

</div>

Hi All,  
I am reading a book to install and work on Asterisk 16.  
I am a beginner to both Linux and Asterisk but started reading the book properly and got stuck on a place in the book

In that book, the Author just mentioned the below task:  
Create an Ansible playbook in the file ~/ansible/playbooks/starfish.yml

As I am new to Linux and Ansible, I need your help in this…

It is better if someone teaches me the steps to create, edit and save the “starfish.yml” file.

Thanks a lot…  
-Prabhakaran

---

<div class="post-metadata">

**Author:** ![Antony\_Stone](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Antony\_Stone](https://forum.ansible.com/u/Antony_Stone)\
**Post date:** [September 11, 2020, 3:26pm UTC](https://forum.ansible.com/t/how-to-make-and-run-ansible-playbooks-in-centos-7/33792/2 "2020-09-11T15:26:38Z")

</div>

> Hi All,  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I am reading a book to install and work on Asterisk 16.  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I am a beginner to both Linux and Asterisk but started reading  
> the book properly and got stuck on a place in the book
> 
> In that book, the Author just mentioned the below task:  
> Create an Ansible playbook in the file ~/ansible/playbooks/starfish.yml
> 
> As I am new to Linux and Ansible, I need your help in this...

So, you're trying to learn all three of Ansible, Asterisk and Linux at the  
same time!?

That doesn't sound good to me - depending on what operating system/s you're  
previously familiar with, Linux can be enough of a challenge to get  
comfortable with (and I'm assuming you're not an experienced Unix admin), and  
I recommend you start with that before tackling anything else as potentially  
even more complicated as Ansible and Asterisk (and certainly not both at the  
same time).

> It is better if someone teaches me the steps to create, edit and save the  
> "starfish.yml" file.

The simple answer to that is that you need a text editor.

Popular ones are vi, nano and emacs. My preference is vi, but I believe  
beginners often seem to prefer nano.

The slightly longer answer to your question about how to "Create an Ansible  
playbook in the file ~/ansible/playbooks/starfish.yml" and assuming you choose  
vi as your editor is:

$ cd ~  
$ mkdir -p ansible/playbooks  
$ vi starfish.yml

Press insert, and you can enter whatever content the book tells you should be  
in that file.

When done, press Escape, and then :wq to save the file and exit.

However, your question makes me feel that you're really getting rather ahead  
of yourself by asking this on the ansible mailing list, and you should  
consider joining a list helping newcomers to whichever Linux distribution  
you're using (presumably CentOS, Ubuntu or something related to either of  
those), and get to know about package management, basic configuration file  
editing, and system log files etc., before trying to run ahead and get involved  
with things as complex as Asterisk and Ansible.

I'm not trying to put you off - I'm just saying that you may find things a lot  
easier to understand if you take things in stages rather than attempting to  
learn several new things all at the same time.

Regards,

Antony.

---

<div class="post-metadata">

**Author:** ![sajal\_tiwari](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sajal_tiwari/32/2755_2.png) [@sajal\_tiwari](https://forum.ansible.com/u/sajal_tiwari)\
**Post date:** [September 11, 2020, 3:27pm UTC](https://forum.ansible.com/t/how-to-make-and-run-ansible-playbooks-in-centos-7/33792/3 "2020-09-11T15:27:04Z")

</div>

There are many videos on Youtube which can help you for that.

---

<div class="post-metadata">

**Author:** ![Samuel\_Mwangi](https://avatars.discourse-cdn.com/v4/letter/s/d78d45/32.png) [@Samuel\_Mwangi](https://forum.ansible.com/u/Samuel_Mwangi)\
**Post date:** [September 11, 2020, 4:03pm UTC](https://forum.ansible.com/t/how-to-make-and-run-ansible-playbooks-in-centos-7/33792/4 "2020-09-11T16:03:29Z")

</div>

For a start (and assuming it’s not been previously suggested before), would recommend following:

1. Jeff Geerling’s Ansible 101 series
2. LearnLinuxTv’s Getting Started With Ansible Series on YouTube.

Best of luck

---

<div class="post-metadata">

**Author:** ![Bruno\_loss\_Pegorari](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@Bruno\_loss\_Pegorari](https://forum.ansible.com/u/Bruno_loss_Pegorari)\
**Post date:** [September 14, 2020, 4:45pm UTC](https://forum.ansible.com/t/how-to-make-and-run-ansible-playbooks-in-centos-7/33792/5 "2020-09-14T16:45:56Z")

</div>

Hello everyone!

Found this discussion in google after facing the same issue as the topic creator.

The point here is that he’s not trying to learn everything at the same time. We are reading the book “Asterisk: Definitive Guide 5th Edition”, and to set up an Asterisk environment, instead of doing everything manually, the book offers a playbook which installs everything you need to start following the book. Asterisk only runs in Linux, but previous Linux knowledge is not obligatory (although recommended). The problem here is that they don’t provide the playbook file online and we have to copy it manually (or through a PDF book), however both ways are easy to misspell or add unwanted spaces.

Well, I’ve tried to write the file manually and I’m getting stuck due to an syntax error, but I can’t find where the error is. This is the whole file. The part that returns an error is the bold one. Can someone help us to figure out how to fix this playbook? Thanks in advance!

- hosts: starfish  
become: yes  
vars:

# Use these on the first run of this playbook

current\_mysql\_root\_password: “”  
updated\_mysql\_root\_password: “root”  
current\_mysql\_asterisk\_password: “”  
updated\_mysql\_asterisk\_password: “root”

# Comment the above out after the first run

# Uncomment these for subsequent runs

# current\_mysql\_root\_password: “YouNeedAReallyGoodPassword”

# updated\_mysql\_root\_password: “{{ current\_mysql\_root\_password }}”

# current\_mysql\_asterisk\_password: “YouNeedAReallyGoodPasswordHereToo”

# updated\_mysql\_asterisk\_password: “{{ current\_mysql\_asterisk\_password }}”

tasks:

- name: Install epel-release  
dnf:  
name: epel-release  
state: present

- name: Install dependencies  
dnf:  
name: [‘vim’, ‘wget’, ‘MySQL-python’]  
state: present

- name: Install the MySQL repo.  
dnf:  
name: [http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm](http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm)  
state: present

- name: Install mysql-server  
dnf:  
name: mysql-server  
state: present

- name: Override variables for MySQL (RedHat).  
set\_fact:  
mysql\_daemon: mysqld  
mysql\_packages: [‘mysql-server’]  
mysql\_log\_error: /var/log/mysqld.err  
mysql\_syslog\_tag: mysqld  
mysql\_pid\_file: /var/run/mysqld/mysqld.pid  
mysql\_socket: /var/lib/mysql/mysql.sock  
when: ansible\_os\_family == “RedHat”

- name: Ensure MySQL server is running  
service:  
name: mysqld  
state: started  
enabled: yes

- name: update mysql root pass for localhost root account from local servers  
mysql\_user:  
login\_user: root  
login\_password: “{{ current\_mysql\_root\_password }}”  
name: root  
host: “{{ item }}”  
password: “{{ updated\_mysql\_root\_password }}”  
with\_items:

- localhost

- name: update mysql root password for all other local root accounts  
mysql\_user:  
login\_user: root  
login\_password: “{{ updated\_mysql\_root\_password }}”  
name: root  
host: “{{ item }}”  
password: “{{ updated\_mysql\_root\_password }}”  
with\_items:

- “{{ inventory\_hostname }}”

- 127.0.0.1

- ::1

- localhost.localdomain

- name: create asterisk database  
mysql\_db:  
login\_user: root  
login\_password: “{{ updated\_mysql\_root\_password }}”  
name: asterisk  
state: present

- name: asterisk mysql user  
mysql\_user:  
login\_user: root  
login\_password: “{{ updated\_mysql\_root\_password }}”  
name: asterisk  
host: “{{ item }}”  
password: “{{ updated\_mysql\_asterisk\_password }}”  
priv: “asterisk.\*:ALL”  
with\_items:

- “{{ inventory\_hostname }}”

- 127.0.0.1

- ::1

- localhost

- localhost.localdomain

- name: remove anonymous user  
mysql\_user:  
login\_user: root  
login\_password: “{{ updated\_mysql\_root\_password }}”  
name: “”  
state: absent  
host: “{{ item }}”  
with\_items:

- localhost

- “{{ inventory\_hostname }}”

- 127.0.0.1

- ::1

- localhost.localdomain

- name: remove test database  
mysql\_db:  
login\_user: root  
login\_password: “{{ updated\_mysql\_root\_password }}”  
name: test  
state: absent

- user:  
name: asterisk  
state: present  
createhome: yes

- group:  
name: asterisk  
state: present

- user:  
name: astmin  
groups: asterisk,wheel  
state: present

**- name: Install other dependencies**  
**dnf:**  
name:

- unixODBC
- unixODBC-devel
- mysql-connector-odbc
- MySQL-python
- tcpdump
- ntp
- ntpdate
- jansson
- bind-utils  
state: present

#Tweak the firewall for UDP/SIP

- firewalld:  
port: 5060/udp  
permanent: true  
state: enabled

#Tweak firewall for UDP/RTP

- firewalld:  
port: 10000-20000/udp  
permanent: true  
state: enabled

- name: Ensure NTP is running  
service:  
name: ntpd  
state: started  
enabled: yes

# The libmyodbc8a.so file is versioned, so if you don’t have version 8, see what the

# /usr/lib64/libmyodbca.so file is, and refer to that instead

# on your ‘Driver64’ line, and then run the playbook again

- name: update odbcinst.ini  
lineinfile:  
dest: /etc/odbcinst.ini  
regexp: “{{ item.regexp }}”  
line: “{{ item.line }}”  
state: present  
with\_items:

- regexp: “^Driver64”  
line: “Driver64 = /usr/lib64/libmyodbc8a.so”

- regexp: “^Setup64”  
line: “Setup64 = /usr/lib64/libodbcmyS.so”

- name: create odbc.ini  
blockinfile:  
path: /etc/odbc.ini  
create: yes  
block: |  
[asterisk]  
Driver = MySQL  
Description = MySQL connection to ‘asterisk’ database  
Server = localhost  
Port = 3306  
Database = asterisk  
UserName = asterisk  
Password = {{ updated\_mysql\_asterisk\_password }}  
#Socket = /var/run/mysqld/mysqld.sock  
Socket = /var/run/mysqld/mysqld.sock  
Socket = /var/lib/mysql/mysql.sock

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [September 14, 2020, 5:49pm UTC](https://forum.ansible.com/t/how-to-make-and-run-ansible-playbooks-in-centos-7/33792/6 "2020-09-14T17:49:27Z")

</div>

> Hello everyone!
> 
> Found this discussion in google after facing the same issue as the topic creator.
> 
> The point here is that he's not trying to learn everything at the same time. We are reading the book "Asterisk: Definitive Guide 5th Edition", and to set up an Asterisk environment, instead of doing everything manually, the book offers a playbook which installs everything you need to start following the book. Asterisk only runs in Linux, but previous Linux knowledge is not obligatory (although recommended). The problem here is that they don't provide the playbook file online and we have to copy it manually (or through a PDF book), however both ways are easy to misspell or add unwanted spaces.

This sure sounds like a tedious exercise. What would be the reason  
they do not provide the file (I wonder).

> Well, I've tried to write the file manually and I'm getting stuck due to an syntax error, but I can't find where the error is. This is the whole file. The part that returns an error is the bold one. Can someone help us to figure out how to fix this playbook? Thanks in advance!

Pasting YAML into an HTML mail (with colours - really?) will probably  
add even more errors.  
Rather than eyeballs I would suggest using a more appropriate tool for  
this, such as yamllint or ansible-lint.  
They were meant to do exactly what you want.

---

<div class="post-metadata">

**Author:** ![Antony\_Stone](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Antony\_Stone](https://forum.ansible.com/u/Antony_Stone)\
**Post date:** [September 14, 2020, 9:13pm UTC](https://forum.ansible.com/t/how-to-make-and-run-ansible-playbooks-in-centos-7/33792/7 "2020-09-14T21:13:20Z")

</div>

> We are reading the book "Asterisk: Definitive Guide 5th Edition", and to set  
> up an Asterisk environment, instead of doing everything manually, the book  
> offers a playbook which installs everything you need to start following the  
> book.

Sounds good so far.

> The problem here is that they don't provide the playbook file online

That's weird.

> and we have to copy it manually (or through a PDF book), however both ways  
> are easy to misspell or add unwanted spaces.

Have you tried a PDF to text converter?

That would be my first approach to getting code from a PDF publication onto a  
machine, without typos.

Antony.
