Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf · Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (2024)

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (1)

Automation with AnsibleFind the latest, print-friendly version of this presentation and tutorial materials at

https://christopherdemarco.com/ansible

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (2)

Copyright © 2017 Christopher DeMarco. All Rights Reserved.

The opinions and mistakes that follow are my own and do not represent my employer, Red Hat, USENIX, or anyone else.

All code samples were believed correct at runtime. Your mileage may vary.

To my grandfather, who taught me how to write.To my father, who taught me why. 2

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (3)

This tutorial is interactive.Please interrupt me!

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (4)

Join us on Slack!#m8-ansiblehttp://lisainvite.herokuapp.com/

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (5)

Who has used Ansible before?

5

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (6)

Lightweight configuration management

Stop managing your tools, start using them.

Possibly pay Red Hat to help.

6

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (7)

Agentless

Install and maintain the client.

Strange firewall ports?

Got SSH?

Got Python >= 2.4? (and maybe not even that!)

7

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (8)

Serverless

Admin SPOF / Yet Another Cluster

Install Ansible, pull configuration codebase, & run locally.

No daemons or databases.

Laptop? Jenkins? On the node itself?

8

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (9)

Stateless

Ship bytecode to the nodes being configured—load is in the targets, not the controller.

Keep static host inventories in source control.

Generate dynamic host inventories; scripts simply output JSON.

9

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (10)

Small DSLYAML

Jinja2

Python

10

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (11)

OTOH

SSH and Python are slow.

YAML is *too* easy.

Ansible is procedural, not declarative.

Ansible’s DSL does not incorporate a general-purpose programming language.

11

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (12)

There’s lots of infrastructure we can’t demo!

AWS

Google Compute Engine

OpenStack

Azure

Kubernetes

Cisco

F5

NetApp

Windows

. . . 12

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (13)

Hello Docker

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (14)

PlaybooksA play consists of tasks.

A groups of plays is called a playbook.

Playbooks are structured as YAML lists and dictionaries.

14

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (15)

`hosts` and `tasks` are required parameters of the play.

The `tasks` parameter contains a list of modules. (`ping` and `apt`)

`state` is a parameter of a module. `with_items` is a parameter of a task. Do not confuse them!

15

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (16)

Inventory

Use INI or YAML.

Or use a script for dynamic inventory.

Set variables.

Set groups.

16

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (17)

Run it! Ansible runs against all hosts in parallel.

Show changes as they’re made, and summarize overall results.

17

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (18)

Re-run it! Ansible will only do what’s necessary.

18

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (19)

Now you try it . . .

19

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (20)

Accessing your lab workstation

Your paper tokens expire.

Do not break your instances.

Everything disappears afterwards.

Beware USENIX Code of Conduct.

Ansible and class materials are installed.

API credentials expire after this session, don’t try anything funny.

20

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (21)

Code samples are provided.

The first “hello docker” example is in `~/class/1330_hello`.

Background `docker-compose up`, use tmux/screen, or open a second SSH session.

Once you’ve provisioned the container, connect to it and play around.

21

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (22)

Docker 101~/class/docker_101.md

22

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (23)

YAML sucks.~/class/yaml_sucks.yml

23

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (24)

DON’T USE TABS IN YAML!

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (25)

http://fortunes.exampleLet’s build it.

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (26)

What do we need to do?

Copy source.

Install requirements.

Set up app.

26

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (27)

Does it work?This docker-compose configuration exposes tcp/80.

Test with curl.

27

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (28)

Tag things to skip them.

28

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (29)

Use the `ansible-playbook --tags=` option to run only selected tags.

Use the `--skip-tags=` option to exclude selected tags.

Separate multiple tags with a comma [and no space].

Use the `ansible-playbook --list-tasks` option to see what tags are defined.

29

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (30)

Variables

30

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (31)

Variables can have default values.

Facts are variables discovered automatically by Ansible.

Interpolate variables using Jinja2 syntax.

Use the `debug` module to print.

31

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (32)

Set variables on the command line with the `-e` argument.

Or define them in inventory.

Or use `include_vars` to load them from a file.

32

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (33)

Yeah, but Docker . . .Let’s build it on a real host.

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (34)

Managing / accessing your lab SSH host

Use `~/class/inventory.py` as your Ansible inventory.

Username is `ubuntu`. Password login is not permitted; use the SSH key at `~/.ssh` .

Recreate alpha by running the `~/recreate_alpha.sh` script; don’t forget to remove stale keys from `~/.ssh/known_hosts`.

34

alpha.<your-host>.foam.ninja

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (35)

Docker vs. a real hostHow do we switch these on?

sudo

initscript/service

35

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (36)

How do we become a different user?

`become`

`become_user`

Gotcha: `become` applies to the play—not to the task list, or to individual tasks.

36

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (37)

How do we branch on platform type?

List the available facts: `ansible -m setup -i <inventory> all`.

Use a task’s `when` parameter to restrict its execution.

Gotcha: no Jinja braces in `when`!

37

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (38)

Point your browser at http://alpha.your-workstation.foam.ninja!

38

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (39)

It sure is annoying to set `become_bool` in inventory . . .

39

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (40)

Yeah, but Debian . . .

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (41)

You can set variables in a play.

`packages` is a dictionary. Index using Python syntax.

The `package` module is cross-platform.

41

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (42)

Roles

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (43)

Roles make things modular.Use them as much as possible!

Install and configure an application.

Apply common configuration.

Bundle assets and resources.

Share code.

43

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (44)

UserlandLet’s build it.

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (45)

What do we need to do?

Provide my preferred username and shell.

Authenticate using my GitHub keypair.

Portably install the essentials.

Setup a convenience alias in `~/.ssh/config`.

45

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (46)

Use a role with the `include_role` task.

46

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (47)

Set `roles_path` in `ansible.cfg`.

`ansible-galaxy init <rolename>`.

Put tasks in `tasks/main.yml`. (Note that this is a task list—like you’d put in a play—not a playbook.) Similarly for `handlers/main.yml`.

Put files/templates in their respective directories, and you can use them within the role without an explicit path.

47

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (48)

Set role defaults.

Note that my defaults are probably not what you want!

As a role author, it’s your responsibility to set sane defaults.

48

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (49)

Tasks return data structures.

Provide status, stdout/stderr, etc.

`register` them, then use them like variables.

Output them using `debug`.

49

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (50)

Work locally. `delegate_to: localhost`

50

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (51)

Let’s set a login password. How can we store it securely?

51

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (52)

Keep secrets in `ansible-vault`.

Use the `import_vars` task to pull vars into the current play.

`ansible-vault [create | edit | view]`

It’s encrypted, therefore safe to store in version control.

`ansible-playbook --ask-vault-pass`

52

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (53)

Gotcha!sshd doesn’t permit password logins!

53

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (54)

HandlersHandlers `register` listeners.

Tasks can `notify` handlers.

Put a handler in a play, or in the `handlers` list of a role.

54

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (55)

Use third-party roles.

55

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (56)

But are they any good?

http://galaxy.ansible.com

`ansible-galaxy install user.role`

Gotcha! `ansible-galaxy` ignores `ansible.cfg` and installs to ~/.ansible/roles` unless you set `ANSIBLE_ROLES_PATH`.

Check them into source control?

Read them!

OK for prototyping . . . but you’ll probably rewrite ‘em . . .

56

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (57)

Keep things organized.

Playbooks go in the top level.

Directories for inventory, roles, variables, etc.

`roles_path`

Use version control!

Manage third-party modules!

57

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (58)

Password-protect fortunes.Let’s build it.

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (59)

Templates

59

`template` is just another module. Syntax is basically like `copy`.

Use the familiar variable interpolation syntax—including filters.

Wrap Python code with `{% %}`.

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (60)

What do we need to do?

Install Apache2.

Template the config.

Enable the config and modules, restart `apache2`.

Set up htpasswd.

60

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (61)

The Apache template is simple with just a single variable expansion.

61

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (62)

The htpasswd template shows an inline Python code block, and a filter.

62

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (63)

Automate tmuxinator.

63

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (64)

Because this is a bogus example, we need to limit execution to localhost.

The magic `ansible_env` variable is a dictionary containing the env vars of the host *on which the play was run*.

The `delegate_to` parameter specifies which host will run the task.

64

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (65)

`groups` is a variable like any other.

Note that interpolation braces are not required within a Python block.

`hostvars` lets you reference an arbitrary host’s variables!

65

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (66)

Jevgr phfgbz svygref.

66

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (67)

Write plugins in Python. Each plugin implements a class whose `filters` method returns a function implementing the actual filter.

Put your Python in a `filter_plugins/` directory adjacent to your playbook or inside your role.

67

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (68)

Documentation tourBeware the bright light . . .

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (69)

breakreturn at 1530

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (70)

Grouping and limiting

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (71)

Inventory groups can include other groups.

Variables are inherited via group membership.

71

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (72)

Group membership can use complex pattern syntax.

Limit what will be operated on with the `-l` argument to `ansible-playbook`, or in a play’s `hosts` attribute.

Use the same pattern syntax on the command line or in playbooks.

72

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (73)

73

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (74)

Dynamic inventory

74

Let’s build it.

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (75)

Dynamic inventory: AWS

75

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (76)

Scale

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (77)

77

Use `strategy: free` to keep hosts from waiting for each other.

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (78)

78

Use the default strategy with the `serial` directive to define batches of hosts.

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (79)

Melt your laptop.

Set `forks` in `ansible.cfg` to scale the number of remote connections.

79

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (80)

Gotchas

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (81)

Gotcha! Install & setup

Install your OS’s package.

Scatter stuff all over your machine?

How stale is the version?

81

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (82)

Instead, run from a git repo.

https://github.com/ansible/ansible.git But don’t commit it to your source control!

Better yet, use a git submodule.

82

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (83)

But you’ll need a virtualenv.

http://docs.python-guide.org/en/latest/dev/virtualenvs/

Prefer OS packages for the various virtualenv methods; don’t `pip install` system-wide.

83

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (84)

84

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (85)

Gotcha! SSH details

Use SSH-specific variables in inventory and on the command line.

`host_key_checking`

`remote_port`

`remote_user`

`ssh_args`

`--extra-vars @aws.var`

85

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (86)

Gotcha!It won’t work?

Can’t auth? Can’t sudo?

Use `-vvvv` to watch the SSH stream.

Is SSH doing what you expect?

86

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (87)

Gotcha!So many `.retry`!

`retry_files_enabled`

`retry_files_save_path`

87

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (88)

Gotcha!YAML parsing

88

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (89)

Gotcha!YAML parsing

89

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (90)

Gotcha!Interpolation

90

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (91)

Gotcha!Firewall

91

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (92)

Gotcha!No Python!

92

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (93)

Gotcha!Python3

:-\

93

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (94)

Gotcha!GitHub keysThou shalt not transport thine public key.

94

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (95)

Gotcha!GitHub keys(cont.)

95

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (96)

Gotcha!`sudo` password?!

Add the `-K` flag to make Ansible prompt for a sudo password.

Store the `ansible_become_pass` variable in Vault.

96

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (97)

Gotcha!JSON

97

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (98)

Gotcha!Variable precedence!

Don’t get into a position where you need to know this! KISS!

Defaults are lowest priority: role defaults and inventory vars.

Then facts, play vars, task vars.

Then include_vars.

Then set facts.

Then `-e` extra vars.

Basically, the narrowest scope wins.

98

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (99)

Q & A

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf· Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (100)

Thank you.Lab systems are being destroyed now.

Please fill out your surveys.

Automation with Ansible - christopherdemarco.comchristopherdemarco.com/ansible/M8-Automation-With-Ansible.pdf · Automation with Ansible Find the latest, print-friendly version of - [PDF Document] (2024)

References

Top Articles
Latest Posts
Article information

Author: Kerri Lueilwitz

Last Updated:

Views: 5926

Rating: 4.7 / 5 (47 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Kerri Lueilwitz

Birthday: 1992-10-31

Address: Suite 878 3699 Chantelle Roads, Colebury, NC 68599

Phone: +6111989609516

Job: Chief Farming Manager

Hobby: Mycology, Stone skipping, Dowsing, Whittling, Taxidermy, Sand art, Roller skating

Introduction: My name is Kerri Lueilwitz, I am a courageous, gentle, quaint, thankful, outstanding, brave, vast person who loves writing and wants to share my knowledge and understanding with you.