Skip to content

Commit 608bf4a

Browse files
committed
more stuff
1 parent d697b47 commit 608bf4a

11 files changed

+155
-4
lines changed

Ansible/3_Playbooks/0_RECAP_THEM_ALL

Whitespace-only changes.

Ansible/3_Playbooks/18_Local Actions

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Run a playbook to execute locally specifying 127.0.0.1
2+
# LOCAL connection to skip SSH
3+
# Skip the USER and ROOT
4+
# The USER that is going to be used is the one that will EXECUTE the playbook
5+
# SUDO can be done at command line
6+
# Present make sure that the package is going to be installed and nothing more
7+
# LATEST instead means that even if it is installed, make sure it is the latest verstion
8+
9+
$vi local.yml
10+
11+
--- # LOCAL ACTION PLAYBOOK
12+
- hosts: 127.0.0.1
13+
connection: local
14+
tasks:
15+
- name: Install telnet
16+
yum: pkg=telnet state=latest
17+
18+
# ONE TO RUN IT
19+
20+
$ansible-playbook -s local.yml

Ansible/3_Playbooks/19_Loops

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Way to LOOP certain commands with variable substitution to run multiple times
2+
# Multiple types
3+
-> # nested loops
4+
-> # loops with index array
5+
# Use the USER module
6+
-> it will ITERATE the ITEMS in "with_items" and add them!
7+
$vi loop.yml
8+
9+
---# LOOP Playbook Example
10+
- hosts: web
11+
user: centos
12+
become: yes
13+
connection: ssh
14+
gather_facts: no
15+
tasks:
16+
- name: Add a list of users
17+
user: name={{ item }} state=present
18+
with_items:
19+
- user1
20+
- user2
21+
- user3

Ansible/3_Playbooks/20_Conditionals

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# CONDITIONAL statements
2+
# Used in case of <something_happen>
3+
# Keyword WHEN to indicate the action
4+
# This case GATHER_FACTS is NEEDED to rely on it
5+
6+
$vi when.yml
7+
8+
--- # WHEN PLAYBOOK
9+
- hosts: nodes
10+
user: vagrant
11+
become: yes
12+
connection: ssh
13+
tasks:
14+
- name: Install apache appropriate to Debian distribution
15+
command: apt-get -y install apache2
16+
when: ansible_os_family == "Debian"
17+
- name: Install apache appropriate to Centos distribution
18+
command: yum -y install httpd
19+
when: ansible_os_family == "RedHat"
20+
21+
# TO CHECK FIRST THE COMMAND
22+
$ansible nodes -m setup -a 'filter=ansible_os_type'

Ansible/3_Playbooks/21_Until

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Run a command until something changes.
2+
# limit the number of time to retry that command
3+
# register the RESULT
4+
# -1 refer to FAILURE
5+
# The "Verify service status" is going to run UNTIL the result will be different
6+
# then -1 (Failure).
7+
# This means that will end when the result will find the Active
8+
# 0 = SUCCESS
9+
# Once is 0 (SUCCESSFULL) will end
10+
# Delay the RETRY of 5 SECONDS
11+
12+
$vi until.yml
13+
--- # Until Playbook
14+
- hosts: nodes
15+
become: yes
16+
remote_user: vagrant
17+
connection: ssh
18+
gather_facts: no
19+
tasks:
20+
- name: Install Apache
21+
yum: pkg=httpd state=latest
22+
- name: Verify service status
23+
shell: systemctl status httpd
24+
register: result
25+
until: result.stdout.find("active (running)") != -1
26+
retries: 5
27+
delay: 5
28+
- debug: var=result
29+
30+
# IT will attempt that the status is "active"
31+
# To do that, in the NODE start apache and check back in the controller the RESULT

Ansible/3_Playbooks/22_Notify

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-> SEE 9_HANDLER SECTION

Ansible/3_Playbooks/23_Vault

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# ENCRYPT THE YAML FILE
2+
# In case we have sensitive information inside the YAML file
3+
4+
$vi account.yml
5+
6+
git_user: gituser
7+
git_pwd: gitpassword
8+
admin_user: admin
9+
admin_pwd: adminpassword
10+
11+
# TO ENCRYPT a file
12+
13+
$ansible-vault encrypt accounts.yml
14+
15+
# To ENCRYPT the file
16+
17+
$ansible-vault create secure.yml
18+
-> Vault password will be asked
19+
20+
value1: somevalue
21+
22+
$cat secure.yml
23+
-> We can see that the file is ENCRYPTED using the password
24+
25+
# To edit the file and UN-ENCRYPT
26+
27+
$ansible-vault edit secure.myl
28+
29+
# To change the PASSWORD used to ENCRYPT the file
30+
31+
$ansible-vault rekey secure.yml
32+
33+
# TO UN-ENCRYPT a file
34+
35+
$ansible-vault decrypt secure.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# TO PROMPT THE USER
2+
# PRIVATE to prompt the input the user types or NOT
3+
# IN DEVOPS (using JENKINS for example) we can get INPUTs that are the OUTPUT of other actions
4+
5+
$vi prompt.yml
6+
7+
--- # PROMPT
8+
- hosts: nodes
9+
...
10+
vars:
11+
playbook_version: 0.01b
12+
vars_prompt:
13+
- name: pkgtoinstall
14+
prompt: Package to install?
15+
default: telnet
16+
private: no
17+
tasks:
18+
- name: Install the package
19+
yum: pkg={{ pkgtoinstall }} state=latest

Ansible/3_Playbooks/25_Basic Include Statements

Whitespace-only changes.

Ansible/3_Playbooks/9_Handler Section

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ability to notify another section when something happens
1+
# ability to NOTIFY another section when something happens
22
# create an Action to install the HTTPD server
33
# use YUM pkg to install apache
44
# NOTIFY Value must mach the HANDLERS name Value
@@ -10,9 +10,9 @@
1010

1111
$vi myfirstplaybook.yml
1212

13-
- hosts: web
14-
user: centos
15-
# UNDERSTAND BECOMING SUDO
13+
- hosts: nodes
14+
user: vagrant
15+
become: yes
1616
connection: ssh
1717
gather_facts: no
1818
vars:

install_docker_version_1.12.3.txt

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ sudo yum install -y yum-utils
33
sudo yum-config-manager --add-repo https://packages.docker.com/1.12/yum/repo/main/centos/7
44
yum list docker-engine.x86_64 --showduplicates |sort -r
55
yum install -y docker-engine-1.12.3.cs4-1.el7.centos
6+
systemctl start docker
7+
chkconfig docker on

0 commit comments

Comments
 (0)