Modules Flashcards
Create task to install ntpd on CentOS
- yum: name=ntp state=present
Create task to start ntpd on CentOS
- service: name=ntpd state=started enabled=yes
Create a task to install httpd and httpd-devel on CentOS
-yum: name: -httpd -httpd-devel state: present
Create task to copy following files, setting permissions to 644 and group to root and user to root:
httpd.conf to /etc/httpd/conf/httpd.conf
httpd-vhosts.conf to /etc/httpd/conf/httpd-vhosts.conf
-copy:
src: {{item}}
dest: “/etc/httpd/conf/”{{item}}
owner: root
group: root
mode: 644
with_items:
- httpd.conf
- httpd-vhosts.conf
How do you specify the user a playbook should be run as?
ansible-playbook playbook.yml –remote-user=johndoe
How do you define variables when running the play book?
ansible-playbook playbook.yml –extra-vars=”key=value,key=value”
A complete playbook that defines a variable “index.html” and installs nginx
- hosts: all
become: yes
vars:- index_file: “index.html”
tasks: - yum: name=nginx state=present
- index_file: “index.html”
Task to ensure firewalld is stoped
-yum: name=firewalld state=stopped
Create a playbook that logs in as root and installs haproxy using role haproxy.
- name: Installs haxproxy using role
remote_user: root
roles:
- haproxy
Create a playbook that logs in as root and installs mysql and mysqladmin using roles with same names.
- hosts: db
name: install mysql and mysql admin
remote_user: root
roles:
- mysql
- mysqladmin