Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
7 views3 pages

Notes

Download as txt, pdf, or txt
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 3

Chap1

A machine acting as a control node must have Python 2.6 or 2.7 installed.
Managed hosts must have Python 2.4 or later installed to run
Ansible, which includes Red Hat Enterprise Linux 5, 6, and 7 hosts.
The winrm Ansible connection plugin allows Microsoft Windows machines to be managed
hosts.

host inventory file


[webservers]
localhost ansible_connection=local
web1.example.com
web2.example.com:1234 ansible_connection=ssh ansible_user=ftaylor
192.168.3.7
[db-servers]
web1.example.com
db1.example.com

The default location for the host inventory file is /etc/ansible/hosts


server[01:20].example.com - all hosts named server01.example.com through
server20.example.com
ansible washington1.example.com --list-hosts
ansible labhost1.example.com,test,192.168.2.2 -i myinventory --list-hosts
ansible '*.example.com' -i myinventory --list-hosts
ansible -h or ansible --help
ansible --version
ansible lab:datacenter1 -i myinventory --list-hosts ; OR of two groups
ansible lab:&datacenter1 -i myinventory --list-hosts ;AND of two groups
ansible 'all:!datacenter1' -i myinventory --list-hosts ;ALL except datacenter1
group.
Define the location of the configuration file with the $ANSIBLE_CONFIG.
Use ansible --version to find the active configuration file or the below
ansible servers --list-hosts -v
export ANSIBLE_CONFIG=/home/student/dep-config/myansible.cfg
---------------------------------------------------------------
[defaults]
remote_user=devops
inventory=inventory
[privilege_escalation]
become=True
become_method=sudo
become_user=root
become_ask_pass=True
-----------------------------------------------
ansible host-pattern -m module -a 'argument1 argument2' [-i inventory]
sudo cat /etc/sudoers.d/devops
devops ALL=(ALL) NOPASSWD: ALL
---------------------------------------
ansible localhost -m copy -a 'content="Managed byAnsible\n" dest=/etc/motd' -u
devops
--become --become-user root

ansible everyone -m command -a 'cat /etc/motd' -u


devops
----------------------------------------------------
chapter 3 Playbooks
ansible-doc -l
ansible-doc yum
ansible-doc -s yum ( snippet option)
ansible localhost -m yum -a "name=tree state=present"
yum list installed tree
ansible localhost -m service -a "name=httpd state=restarted"
ansible localhost -m uri -a "url=http://materials.example.com/"
modules for user and service management can be found under the SystemsModules
and modules for database administration can be found under Database Modules.
ansible localhost -m yum -a "name=tree state=present"
ansible localhost -m service -a "name=httpd state=restarted"
ansible servera.lab.example.com -m service -a "name=httpd enabled=yes
state=started" -b
------------------------------------------------------------------------
- name: Idempotent approach with copy module
copy:
dest: /etc/resolv.conf
content: "nameserver 192.0.2.1\n"
-----------------------------------------------------------
# This is a simple playbook with a single play
- name: a simple play
hosts: managedhost.example.com
user: remoteuser
become: yes
become_method: sudo
become_user: root
tasks:
- name: first task
service: name=httpd enabled=true
- name: second task
service: name=sshd enabled=true
...
-----------------------------------------------------------
tasks:
- name: first task single line formating
service: name=httpd enabled=true state=started
---------------------------------------------------------
tasks:
- name: first task example of Multi Line formating
service: name=httpd
enabled=true
state=started
-----------------------------------------------------
tasks:
- name: first task dictionary format
service:
name: httpd
enabled: true
state: started
---------------------------------------------------------------
----------------------------------------------------------
# This is a simple playbook with two plays
- name: first play
hosts: web.example.com
tasks:
- name: first task
service:
name: httpd
enabled: true
- name: second play
hosts: database.example.com
tasks:
- name: first task
service:
name: mariadb
enabled: true
...
---------------------------------------------------------
ansible-playbook -C webserver.yml ( to execute a dry run )
ansible-playbook --step webserver.yml ( step execution)

You might also like