├── Chapter01
└── No Files
├── Chapter02
└── No Files
├── Chapter12
└── No Files
├── Chapter03
├── HelloWorld.yml
├── Verify Ansible.txt
├── Debian APT Install.txt
├── Gentoo Install.txt
├── RedHat-Yum Install.txt
├── PlayBook.yml
├── Solaris PacMan Install.txt
└── Vagrantfile
├── Chapter04
├── Example6.Complete.Inventory.yml
├── Example4.VariableFileInPlaybook.yml
├── Example1.JinjaCopyFile.yml
├── Example3.VariablesInPlaybook.yml
├── Example5.VariablesJinjaPlaybook.yml
├── Example2.YAMLFormat.yml
├── Example6.Complete.playbook.yml
└── Example.ManageUsers.yml
├── Chapter05
├── Example7.Register.yml
├── Example5.PlayInclude.yml
├── Example4.WithItemsPlayHosts.yml
├── Example8.Register2.yml
├── Example3.Iteratorfilecontents.yml
├── Example9.ExampleHandler.yml
├── Example8.RegisterIterate.yml
├── Example2.Iterators.yml
├── Example6.LAMP.yml
├── Example1.Iterators.yml
└── Example3.Iteratorkeyvalue.yml
├── Chapter10
├── Example1.DockerCreateImage
├── Example1.DockerInstallNginx
├── Example1.DockerFile
└── Example1.DockerFile2
├── Chapter11
├── Example2.InputParamsHelloWorld.yml
├── Example1.HelloWorld.py
├── Example2.InputParamsHelloWorld.py
├── Example3.ActionPlugin.py
└── Example4.LookUpPlugin.py
├── Chapter07
└── Example1.CopySensitiveData.yml
├── Chapter06
├── Example.JinjaInAnsible
├── Example.JinjaIterations
├── Example.JinjaVarSubstitution
├── Example.JinjaBasics
├── Example.JinjaLoops
├── Example.JinjaConditionals
└── Example.JinjaTemplate
├── Chapter09
├── Example2.Vagrantfile
└── Example1.Jenkins
├── Chapter08
└── Example1.DockerContainerCLI.yml
├── LICENSE
└── README.md
/Chapter01/No Files:
--------------------------------------------------------------------------------
1 | There are no code files in Chapter 1
2 |
--------------------------------------------------------------------------------
/Chapter02/No Files:
--------------------------------------------------------------------------------
1 | There are no code files in Chapter 1
2 |
--------------------------------------------------------------------------------
/Chapter12/No Files:
--------------------------------------------------------------------------------
1 | There are no code files in Chapter 1
2 |
--------------------------------------------------------------------------------
/Chapter03/HelloWorld.yml:
--------------------------------------------------------------------------------
1 | # File name: HelloDevOpsWorld.yml
2 | ---
3 | - hosts: all
4 | tasks:
5 | - shell: echo "hello DevOps world"
--------------------------------------------------------------------------------
/Chapter03/Verify Ansible.txt:
--------------------------------------------------------------------------------
1 | # Display Ansible command line options available
2 | $ ansible --help
3 | # Show the Ansible version number
4 | $ ansible --version
--------------------------------------------------------------------------------
/Chapter04/Example6.Complete.Inventory.yml:
--------------------------------------------------------------------------------
1 | # Example Ansible hosts file with two defined groups
2 |
3 | [WEB]
4 | 192.168.10.10
5 | [DATABASE]
6 | 192.168.10.11
--------------------------------------------------------------------------------
/Chapter05/Example7.Register.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: A Simple Ansible Register Example
3 | hosts: all
4 | tasks:
5 | - shell: tail -n 100 /etc/motd
6 | register: motd_contents
--------------------------------------------------------------------------------
/Chapter03/Debian APT Install.txt:
--------------------------------------------------------------------------------
1 | $ sudo apt-get install software-properties-common
2 | $ sudo apt-add-repository ppa:ansible/ansible
3 | $ sudo apt-get update
4 | $ sudo apt-get install ansible
--------------------------------------------------------------------------------
/Chapter10/Example1.DockerCreateImage:
--------------------------------------------------------------------------------
1 | ---
2 | - hosts: all
3 | remote_user: root
4 | tasks:
5 |
6 | - name: Build Docker Image
7 | docker_image:
8 | path: /opt/test
9 | name: myimage
--------------------------------------------------------------------------------
/Chapter11/Example2.InputParamsHelloWorld.yml:
--------------------------------------------------------------------------------
1 | - name: Hello World
2 | hosts: localhost
3 | connection: local
4 | tasks:
5 | - name: Tell the Ansible Community Hello
6 | helloworld: param1=hello
--------------------------------------------------------------------------------
/Chapter03/Gentoo Install.txt:
--------------------------------------------------------------------------------
1 | # The first command is optional, you may need to unmask the Ansible package prior to running emerge:
2 | $ echo 'app-admin/ansible' >> /etc/portage/package.accept_keywords
3 | $ emerge -av app-admin/ansible
--------------------------------------------------------------------------------
/Chapter04/Example4.VariableFileInPlaybook.yml:
--------------------------------------------------------------------------------
1 | # Example: Simple Variables File in Ansible.
2 | ---
3 | - hosts: all
4 | vars_files:
5 | - my_vars_file.yml
6 |
7 | tasks:
8 | - name: ping target server
9 | ping: $ping_server
--------------------------------------------------------------------------------
/Chapter07/Example1.CopySensitiveData.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - include_vars: sensitive_data.yml
3 | - name: Copy sensitive data file from Ansible control server to target hosts
4 | copy:
5 | content="{{secret_text}}"
6 | dest=/tmp/secret_text.txt
--------------------------------------------------------------------------------
/Chapter04/Example1.JinjaCopyFile.yml:
--------------------------------------------------------------------------------
1 | # Example Jinja Playbook
2 | - hosts: all
3 | vars:
4 | foo: "{{ lookup('env', 'FOO' }}"
5 | tasks:
6 | - Name: Copy file
7 | copy: src="{{ foo }}" dest=/some/path mode=0775 owner=user group=user
--------------------------------------------------------------------------------
/Chapter06/Example.JinjaInAnsible:
--------------------------------------------------------------------------------
1 | ---
2 | - name: Simple Ansible Playbook that loops over hosts within Jinja
3 | vars:
4 | say_hello
5 | say_something: "{{ say_hello }}"
6 |
7 | tasks:
8 | - debug:
9 | msg: "{{ say_something }}"
--------------------------------------------------------------------------------
/Chapter04/Example3.VariablesInPlaybook.yml:
--------------------------------------------------------------------------------
1 | # Example: Simple Key/Value Variables in Ansible.
2 | ---
3 | - hosts: all
4 | vars:
5 | # Single Variable(s) Example
6 | myvar: helloworld
7 |
8 | tasks:
9 | - name: $myvar
10 | ping:
--------------------------------------------------------------------------------
/Chapter06/Example.JinjaIterations:
--------------------------------------------------------------------------------
1 | # Example Ansible playbook using an iterating loop
2 | ---
3 | - name: Hello World Iterator within Ansible
4 | user: root
5 | hosts: all
6 | tasks:
7 | - debug:
8 | msg: "{% for x in range (0,10) %} {{x}} {% endfor %}"
--------------------------------------------------------------------------------
/Chapter05/Example5.PlayInclude.yml:
--------------------------------------------------------------------------------
1 | # This is an example of a 'play' include
2 |
3 | - include: myplaybook.yml
4 | - name: some play
5 | hosts: all
6 | tasks:
7 | - debug: msg=hello
8 |
9 | # An Example of a task level include
10 | - include: additionaltasks.yml
--------------------------------------------------------------------------------
/Chapter03/RedHat-Yum Install.txt:
--------------------------------------------------------------------------------
1 | # NOTE: Before installing Ansible you may need to install the epel-release repo
2 | # for RHEL or
3 | # Scientific Linux. Additional details on how to install EPEL can be found at
4 | # http://fedoraproject.org/wiki/EPEL
5 | $ sudo yum install ansible
6 |
7 |
--------------------------------------------------------------------------------
/Chapter05/Example4.WithItemsPlayHosts.yml:
--------------------------------------------------------------------------------
1 | ---
2 | -
3 | hosts: webserver
4 | name: "Iteration Example using With_Items and Play_Hosts"
5 | tasks:
6 | -
7 | debug: ~
8 | msg: "Host Identified: {{ item }}"
9 | with_items:
10 | - "{{ play_hosts }}"
11 |
--------------------------------------------------------------------------------
/Chapter04/Example5.VariablesJinjaPlaybook.yml:
--------------------------------------------------------------------------------
1 | # Example: Simple Variables File in Ansible.
2 | ---
3 | - hosts: all
4 | vars_files:
5 | - my_vars_file.yml
6 | - "/opt/varsfiles/{{ env_vars }}.yml"
7 |
8 | tasks:
9 | - name: ping target server
10 | ping: $ping_server
11 |
--------------------------------------------------------------------------------
/Chapter11/Example1.HelloWorld.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # The following Python code converts a simple "Hello Ansible" message into a json object
3 | # for use with an Ansible module call
4 |
5 | import json
6 |
7 | message = "Hello Ansible"
8 | print(json.dumps({
9 | "Message" : message
10 | }))
--------------------------------------------------------------------------------
/Chapter06/Example.JinjaVarSubstitution:
--------------------------------------------------------------------------------
1 | # Example playbook using simple JINJA2 variable substitution
2 | --
3 | - hosts: 127.0.0.1
4 | user: root
5 | vars:
6 | motd: ‘Welcome to your Linux Box’
7 | tasks:
8 | - name: Update the /etc/motd
9 | copy: content=‘{{motd}}’ dest='/etc/motd’ force='yes'
--------------------------------------------------------------------------------
/Chapter04/Example2.YAMLFormat.yml:
--------------------------------------------------------------------------------
1 | # Example YAML formatting with Comments and multiple entries
2 | ---
3 | - hosts: all
4 | vars :
5 | http_port : 80
6 | tasks:
7 | - name: Install nginx web server
8 | apt: pkg=nginx state=installed update_cache=true
9 | notify:
10 | - start nginx
--------------------------------------------------------------------------------
/Chapter06/Example.JinjaBasics:
--------------------------------------------------------------------------------
1 | # Example Ansible Jinja2 Template
2 | - hosts: all
3 | vars:
4 | my_var: ‘Hello’
5 | my_var2: ‘World’
6 | tasks:
7 | - name: Simple Ansible MOTD Template Example
8 | template:
9 | src: motdexample.j2
10 | dest: /etc/motd
11 | mode: 0777
--------------------------------------------------------------------------------
/Chapter06/Example.JinjaLoops:
--------------------------------------------------------------------------------
1 | # Example of loops using Jinja
2 | --
3 | - name: Simple Ansible Playbook that loops over hosts within Jinja
4 | vars:
5 | servers_to_configure: "{{ groups['databaseservers'] }}"
6 | tasks:
7 | - template:
8 | src: configfile.j2
9 | dest: configfile.conf
10 |
--------------------------------------------------------------------------------
/Chapter04/Example6.Complete.playbook.yml:
--------------------------------------------------------------------------------
1 | # Example Ansible Playbook, which targets the 'WEB' group
2 | ---
3 | - hosts: WEB
4 | vars :
5 | http_port : 80
6 | tasks:
7 | - name: Install nginx web server
8 | apt: pkg=nginx state=installed update_cache=true
9 | notify:
10 | - start nginx
--------------------------------------------------------------------------------
/Chapter05/Example8.Register2.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: A Simple Ansible Register Example
3 | hosts: all
4 | tasks:
5 | - shell: tail -n 100 /etc/motd
6 | register: motd_contents
7 |
8 | - shell: echo "Our MOTD file contains the word Bugs Bunny"
9 | when: motd_contents.stdout.find('bugs bunny') != -1
--------------------------------------------------------------------------------
/Chapter10/Example1.DockerInstallNginx:
--------------------------------------------------------------------------------
1 | ---
2 | - hosts: all
3 | tasks:
4 | - name: Installs NGINX web server on a Docker Image
5 | apt: pkg=nginx state=installed update_cache=true
6 | notify:
7 | - start nginx
8 |
9 | handlers:
10 | - name: start nginx
11 | service: name=nginx state=started
--------------------------------------------------------------------------------
/Chapter03/PlayBook.yml:
--------------------------------------------------------------------------------
1 | #Playbook.yml
2 | ---
3 | - hosts: all
4 | tasks:
5 | - name: "Install Apache"
6 | apt: name={{ item }} state=present
7 | with_items:
8 | - apache2
9 |
10 | - name: "Turn on Apache and set it to run on boot"
11 | service: name={{ item }} state=started enabled=yes
12 | with_items:
13 | - apache2
--------------------------------------------------------------------------------
/Chapter06/Example.JinjaConditionals:
--------------------------------------------------------------------------------
1 | # Conditional Logic Playbook Example
2 | ---
3 | - name: Hello World Conditional Logic
4 | user: root
5 | hosts: all
6 | vars:
7 | hello: true
8 | say_something: "{% if hello == true %} Hello Jinja {% else %} Goodbye Ansible {% endif %}
9 | tasks:
10 | - debug:
11 | msg: "{{ say_something }}"
12 |
13 |
--------------------------------------------------------------------------------
/Chapter03/Solaris PacMan Install.txt:
--------------------------------------------------------------------------------
1 | pkgadd -d http://get.opencsw.org/now
2 | /opt/csw/bin/pkgutil -i ansiblePacman for Arch Linux
3 | # Installing Ansible for Arch Linux is quite simple. The following command should help accomplish this task:
4 |
5 | # Note: If you have Python3 selected you must set
6 | # ansible_python_interpreter = /usr/bin/python2 # in your inventory variables
7 | $> pacman -S ansible
--------------------------------------------------------------------------------
/Chapter05/Example3.Iteratorfilecontents.yml:
--------------------------------------------------------------------------------
1 | # Example Playbook which Iterates Over the Contents of Two Files (iterator_file_contents.yml)
2 | ---
3 | - name: Say hello to our favorite Looney Toons
4 | hosts: all
5 |
6 | tasks:
7 | - name: Say Hello to Our Favorite Looney Toons
8 | debug:
9 | msg: "{{ item }}"
10 | with_file:
11 | - hello.txt
12 | - favorite_toons.txt
--------------------------------------------------------------------------------
/Chapter09/Example2.Vagrantfile:
--------------------------------------------------------------------------------
1 | # This is an example Vagrantfile which can be used with
2 | # Vagrant 1.7 and greater to provision an Ubuntu Box
3 | # using Ansible
4 |
5 | Vagrant.require_version ">= 1.7.0"
6 | Vagrant.configure(2) do |config|
7 |
8 | config.vm.box = "ubuntu/trusty64"
9 | config.vm.provision "ansible" do |ansible|
10 | ansible.verbose = "v"
11 | ansible.playbook = "playbook.yml"
12 | end
13 | end
--------------------------------------------------------------------------------
/Chapter08/Example1.DockerContainerCLI.yml:
--------------------------------------------------------------------------------
1 | ---
2 | - name: Build a docker container using the command line
3 | hosts: all
4 |
5 | tasks:
6 | - name: build a docker container
7 | command: docker build -t build-a-docker-container:ex2b ./site
8 |
9 | - name: run a site within a docker container
10 | docker:
11 | name: mysite
12 | image: "build-a-docker-container:ex2b"
13 | state: reloaded
14 | publish_all_ports: yes
15 | use_tls: encrypt
--------------------------------------------------------------------------------
/Chapter10/Example1.DockerFile:
--------------------------------------------------------------------------------
1 | # This DOCKERFILE creates a docker image with Ubuntu 14.04 and Ansible installed
2 | # It also executes a playbook upon startup
3 | FROM ansible/ubuntu14.04-ansible:stable
4 |
5 | # This Defines the location for Ansible playbooks as /srv/example
6 | ADD ansible /srv/example
7 | WORKDIR /srv/example
8 |
9 | # Execute Ansible with the playbook's primary entry point as myplaybook.yml
10 | RUN ansible-playbook myplaybook.yml -c local
11 | CMD ["--help"]
--------------------------------------------------------------------------------
/Chapter10/Example1.DockerFile2:
--------------------------------------------------------------------------------
1 | # This DOCKERFILE creates a docker image with Ubuntu 14.04 and Ansible installed
2 | # It also executes a playbook upon startup
3 | FROM ansible/ubuntu14.04-ansible:stable
4 |
5 | # This Defines the location for Ansible playbooks as /srv/example
6 | ADD ansible /srv/example
7 | WORKDIR /srv/example
8 |
9 | # Execute Ansible with the playbook's primary entry point as myplaybook.yml
10 | RUN ansible-playbook myplaybook.yml -c local
11 | CMD ["--help"]
--------------------------------------------------------------------------------
/Chapter05/Example9.ExampleHandler.yml:
--------------------------------------------------------------------------------
1 | --
2 | - name: Example Handler
3 | hosts: all
4 | tasks:
5 | - command: service httpd restart
6 | notify: restart service
7 |
8 | - command: service mysqld restart
9 | notify: restart service
10 |
11 | - command: service cron.d restart
12 | notify: restart service
13 |
14 | - command: service iptables restart
15 | notify: restart service
16 |
17 | handlers:
18 | - name: restart service
19 | include: tasks/restart_verify.yml
--------------------------------------------------------------------------------
/Chapter05/Example8.RegisterIterate.yml:
--------------------------------------------------------------------------------
1 | --
2 | - name: registered variable usage as a with_items list
3 | hosts: all
4 |
5 | tasks:
6 |
7 | - name: retrieve the list of home directories
8 | command: ls /home
9 | register: home_dirs
10 |
11 | - name: add home dirs to the backup spooler
12 | file: path=/mnt/bkspool/{{ item }} src=/home/{{ item }} state=link
13 | with_items: "{{ home_dirs.stdout_lines }}"
14 | # same as with_items: "{{ home_dirs.stdout.split() }}"
15 |
--------------------------------------------------------------------------------
/Chapter05/Example2.Iterators.yml:
--------------------------------------------------------------------------------
1 | # Demo of Nested Loops Using Ansible. To execute use the following command:
2 | # > ansible-playbook -i 'localhost,' -c local nested_loops.yml
3 |
4 | ---
5 | - name: Demo of nested loops using with_nested
6 | hosts: all
7 | remote_user: root
8 | vars:
9 | listA: [1, 2]
10 | listB: [a, b]
11 | tasks:
12 | - name: Say Hello using Nested Loops
13 | debug: msg=“The values in the array are {{item[0]}} and {{item[1]}}"
14 | with_nested:
15 | - listA
16 | - listB
--------------------------------------------------------------------------------
/Chapter06/Example.JinjaTemplate:
--------------------------------------------------------------------------------
1 | # Example Ansible playbook & Jinja Template
2 | ---
3 | - name: Hello World Conditional Logic within a Jinja template
4 | user: root
5 | hosts: all
6 | vars:
7 | vhost:
8 | servername: my.server
9 | documentroot: /var/www
10 | serveradmin: bob
11 | tasks:
12 |
13 | # Jinja template file example
14 | - template:
15 | src: /jinjatemplates/httpdconf.j2
16 | dest: /etc/httpd/httpd.conf
17 | owner: root
18 | group: wheel
19 | mode: "u=rw,g=r,o=r"
--------------------------------------------------------------------------------
/Chapter04/Example.ManageUsers.yml:
--------------------------------------------------------------------------------
1 | # Create a User 'dortiz'
2 | ---
3 | - hosts: all
4 |
5 | tasks:
6 | - name: Add David Ortiz User to the System
7 | user:
8 | name: dortiz
9 | comment: "David Ortiz has entered the building"
10 |
11 | # Create a User 'jdaemon' and add to group baseballplayers
12 | ---
13 | - hosts: all
14 |
15 | tasks:
16 | - name: Add Johnny Daemon User to the System
17 | user:
18 | name: jdaemon
19 | comment: "Johnny Daemon has entered the building"
20 | groups: baseballplayers
--------------------------------------------------------------------------------
/Chapter11/Example2.InputParamsHelloWorld.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python#!/usr/bin/python
2 | import json
3 | def main():
4 |
5 | module = AnsibleModule(argument_spec=dict( param1 = dict(required=True, type='str') ) )
6 | message = module.params['param1']
7 |
8 | print(json.dumps({
9 | "Message" : message
10 | }))
11 |
12 | module.exit_json(changed=True, keyword=value)
13 | module.exit_json(changed=False, msg='error message ', keyword=value)
14 |
15 | from ansible.module_utils.basic import *
16 | if __name__ = '__main__':
17 | main()
--------------------------------------------------------------------------------
/Chapter05/Example6.LAMP.yml:
--------------------------------------------------------------------------------
1 | # playbook.yml
2 | ---
3 | - hosts: all
4 | tasks:
5 | - name: Install Apache
6 | apt: name=apache2 state=present
7 |
8 | - name: Install PHP module for Apache
9 | apt: name=libapache2-mod-php5 state=present
10 |
11 | - name: Install PHP
12 | apt: name=libapache2-mod-php5 state=present
13 |
14 | - name: Install MySQL
15 | apt: name=libapache2-mod-php5 state=present
16 |
17 | - name: 3. start Apache
18 | service: name=apache2 state=running enabled=yes
19 |
20 | - name: 4. install Hello World PHP script
21 | copy: src=index.php dest=/var/www/index.php
--------------------------------------------------------------------------------
/Chapter09/Example1.Jenkins:
--------------------------------------------------------------------------------
1 | - jenkins_job:
2 | config: "{{ lookup('file', 'templates/example.xml') }}"
3 | name: HelloJenkins
4 | password: admin
5 | url: "http://localhost:8080"
6 | user: admin
7 |
8 |
9 | # Delete a jenkins job using the Ansible Jenkins_Job Module
10 | - jenkins_job:
11 | name: AnsibleExample
12 | password: admin
13 | state: absent
14 | url: http://localhost:8080
15 | user: admin
16 |
17 | # Disable a Jenkins job using the Ansible Jenkins_Job module
18 | - jenkins_job:
19 | name: AnsibleExample
20 | password: admin
21 | enabled: False
22 | url: http://localhost:8080
23 | user: admin
--------------------------------------------------------------------------------
/Chapter11/Example3.ActionPlugin.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 |
3 | # Import the Ansible Runner return data lib
4 | from ansible.runner.return_data import ReturnData
5 |
6 | # Define our ActionModule class (MUST BE NAMED ActionModule)
7 | class ActionModule(object):
8 |
9 | # Define our Calss constructor method (Must be present)
10 | def __init__(self, runner):
11 | self.runner = runner
12 |
13 | # Define our run method (must be present)
14 | def run(self, conn, tmp, module_name, module_args, inject, complex_args=None, **kwargs):
15 | return ReturnData(conn=conn, comm_ok=True, result=dict(failed=False, changed=False, msg="Hello Ansible"))
--------------------------------------------------------------------------------
/Chapter03/Vagrantfile:
--------------------------------------------------------------------------------
1 | # This guide is optimized for Vagrant 1.7 and above.
2 | # Although versions 1.6.x should behave very similarly, it is recommended
3 | # to upgrade instead of disabling the requirement below.
4 | Vagrant.require_version ">= 1.7.0"
5 |
6 | Vagrant.configure(2) do |config|
7 |
8 | config.vm.box = "ubuntu/trusty64"
9 |
10 | # Disable the new default behavior introduced in Vagrant 1.7, to
11 | # ensure that all Vagrant machines will use the same SSH key pair.
12 | # See https://github.com/mitchellh/vagrant/issues/5005
13 | config.ssh.insert_key = false
14 |
15 | config.vm.provision "ansible" do |ansible|
16 | ansible.verbose = "v"
17 | ansible.playbook = "playbook.yml"
18 | end
19 | end
--------------------------------------------------------------------------------
/Chapter05/Example1.Iterators.yml:
--------------------------------------------------------------------------------
1 | # playbook.yml without list based iterators
2 | ---
3 | - hosts: all
4 | tasks:
5 | - name: Install Apache2
6 | apt: name=apache2 state=installed
7 |
8 | - name: Install VIM
9 | apt: name=vim state=installed
10 |
11 | - name: Install TMUX
12 | apt: name=tmux state=installed
13 |
14 | - name: Install MOSH
15 | apt: name=mosh state=installed
16 |
17 | # playbook.yml using an Iterator to install packages
18 | ---
19 | - hosts: all
20 | tasks:
21 | - name: Install list of packages
22 | apt: name={{item}} state=installed
23 | with_items:
24 | - apache2
25 | - vim
26 | - tmux
27 | - mosh
--------------------------------------------------------------------------------
/Chapter05/Example3.Iteratorkeyvalue.yml:
--------------------------------------------------------------------------------
1 | # Example of iterating over a YAML dictionary (iterator_keyvalue.yml)
2 | # To execute save this as a YML file and run the following command
3 | # > ansible-playbook -i 'localhost,' -c local iterator_keyvalue.yml
4 | ---
5 | - name: Say Hello to our Favorite Looney Tune Characters
6 | hosts: all
7 |
8 | vars:
9 | looney_tunes_characters:
10 | bugs:
11 | full_name: Bugs A Bunny
12 | daffy:
13 | full_name: Daffy E Duck
14 | wiley:
15 | full_name: Wiley E Coyote
16 |
17 | tasks:
18 | - name: Show Our Favorite Looney Tunes
19 | debug:
20 | msg: "Hello there: {{ item.key }} your real name is {{ item.value.full_name }}"
21 | with_dict: "{{ looney_tunes_charachters }}"
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Packt
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Chapter11/Example4.LookUpPlugin.py:
--------------------------------------------------------------------------------
1 | # This Code Example Comes from the Official Ansible Documentation Set (http://www.ansible.com/)
2 |
3 | from ansible.errors import AnsibleError, AnsibleParserError
4 | from ansible.plugins.lookup import LookupBase
5 |
6 | try:
7 | from __main__ import display
8 | except ImportError:
9 | from ansible.utils.display import Display
10 | display = Display()
11 |
12 | # This is the standard class for the LookupModule implementation it is required to be this name
13 | class LookupModule(LookupBase):
14 |
15 | # As with all our other plugins, the run method MUST be there
16 | def run(self, terms, variables=None, **kwargs):
17 |
18 | ret = []
19 | # Perform iteration
20 | for term in terms:
21 |
22 | display.debug("File lookup term: %s" % term)
23 |
24 | # Find the file in the expected search path
25 | lookupfile = self.find_file_in_search_path(variables, 'files', term)
26 | display.vvvv(u"File lookup using %s as file" % lookupfile)
27 | try:
28 | if lookupfile:
29 | contents, show_data = self._loader._get_file_contents(lookupfile)
30 | ret.append(contents.rstrip())
31 | else:
32 | raise AnsibleParserError()
33 |
34 | except AnsibleParserError:
35 | raise AnsibleError("could not locate file in lookup: %s" % term)
36 | return ret
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | # Implementing DevOps with Ansible 2
5 | This is the code repository for [Implementing DevOps with Ansible 2](https://www.packtpub.com/networking-and-servers/implementing-devops-ansible-2?utm_source=github&utm_medium=repository&utm_campaign=9781787120532), published by [Packt](https://www.packtpub.com/?utm_source=github). It contains all the supporting project files necessary to work through the book from start to finish.
6 | ## About the Book
7 | Thinking about adapting the DevOps culture for your organization using a very simple, yet powerful automation tool, Ansible 2? Then this book is for you!
8 |
9 | In this book, you will start with the role of Ansible in the DevOps module, which covers fundamental DevOps practices and how Ansible is leveraged by DevOps organizations to implement consistent and simplified configuration management and deployment. You will then move on to the next module, Ansible with DevOps, where you will understand Ansible fundamentals and how Ansible Playbooks can be used for simple configuration management and deployment tasks. After simpler tasks, you will move on to the third module, Ansible Syntax and Playbook Development, where you will learn advanced configuration management implementations, and use Ansible Vault to secure top-secret information in your organization. In this module, you will also learn about popular DevOps tools and the support that Ansible provides for them (MYSQL, NGINX, APACHE and so on). The last module, Scaling Ansible for the enterprise, is where you will integrate Ansible with CI and CD solutions and provision Docker containers using Ansible.
10 |
11 | By the end of the book you will have learned to use Ansible to leverage your DevOps tasks.
12 |
13 | ## Instructions and Navigation
14 | All of the code is organized into folders. Each folder starts with a number followed by the application name. For example, Chapter02.
15 |
16 |
17 |
18 | The code will look like the following:
19 | ```
20 | ---
21 | - include_vars: sensitive_data.yml
22 | - name: Copy sensitive data file from Ansible control server to target hosts
23 | copy:
24 | content="{{secret_text}}"
25 | dest=/tmp/secret_text.txt
26 | ```
27 |
28 |
29 |
30 | ## Related Products
31 | * [Implementing DevOps with Microsoft Azure](https://www.packtpub.com/networking-and-servers/implementing-devops-microsoft-azure?utm_source=github&utm_medium=repository&utm_campaign=9781787127029)
32 |
33 | * [Ansible 2 for Beginners [Video]](https://www.packtpub.com/networking-and-servers/ansible-2-beginners-video?utm_source=github&utm_medium=repository&utm_campaign=9781786465719)
34 |
35 | * [Implementing DevOps on AWS](https://www.packtpub.com/virtualization-and-cloud/implementing-devops-aws?utm_source=github&utm_medium=repository&utm_campaign=9781786460141)
36 |
37 | ### Download a free PDF
38 |
39 | If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.
Simply click on the link to claim your free PDF.
40 |