SlideShare a Scribd company logo
ANSIBLE : INFRASTRUCTURE
AUTOMATION, IDEMPOTENT AND MORE
By
Sabarinath Gnanasekar
Ansible Overview
■ Open source model-driven configuration management tool that leverages
SSH to improve security and simplify management of configuration across
various O/S ,Application, Network ,Storage and Cloud platforms.
■ Designed by considering below
 Ease of use
 Low learning curve
 Comprehensive automation
 Efficiency
 Security
2
Bootstrap Instruction
■ https://geekcontainer.wordpress.com/2016/08/05/configuration-
management-ansible-series-1/
■ https://geekcontainer.wordpress.com/2016/08/06/configuration-
management-ansible-series-2/
■ https://geekcontainer.wordpress.com/2016/08/06/configuration-
management-ansible-series-3/
Architecture
4
Control Node
Features
 Improved network security- it has a very low attack surface (openssh
daemon or winrm and no agent)
 Enabling non-root level access (and sudo)
 Limiting transfer of potentially sensitive data
 Credential segregation
 Central server scalability
 Resource utilization
 Firewall friendly
 Zero bootstrapping
 Parallel by default
 Immutable infrastructure
5
Comparison with Puppet
Entity Ansible Puppet
Agent
Excellent performance
Agent less install and deploy
Uses agent
Components 1) OpenSSH 2) Python
1) Ruby 2) Facter
3) Puppet master 4) agent
Language Based on ubiquitous Python.
Ruby(written by programmers
for programmers)
Method Pull Push
Directive language YAML with Jinja2 template Custom
Bootstrap Child Need Not Needed Required
Remote Execution Built-in and easy Mcollective and challenging
Port 22 - Openssh
8140- Puppet Master
443 - Puppet Console
61613 - Mcollective
8142 - Orchestrator 6
Building an Ansible Inventory:Inventory File
■ defines a collection of hosts that Ansible will manage
■ Define logical groups of managed nodes
■ Default inventory file location: /etc/ansible/hosts
■ INI format
Communication variables:
ansible_connection : local,ssh or paramiko
ansible_ssh_host : name of the host to connect
ansible_ssh_user : ssh user name to use
ansible_ssh_port : ssh password to use
ansible_ssh_pass : ssh port number to use
ansible_ssh_private_key_file : private key file used by ssh
Example for Inventory
Defining Nested Groups
Host Specifications with Ranges
Patterns
 all hosts in the inventory (all or *)
 a specific host name or group name (host1, webservers)
 wildcard configuration (192.168.1.*)
 OR configuration (host1:host2, webservers:dbservers)
 NOT configuration (webservers:dbservers:!production)
 AND configuration (webservers:dbservers:&staging)
 REGEX configuration (~(web|db).*.example.com)
 exclude hosts using limit flag (ansible-playbook site.yml --limit
datacenter2)
Ansible Configuration Files & Precedence
Low
• /etc/ansible/ansible.cfg
• Default a base configuration file located
Medium
• ~/.ansible.cfg
• user's home directory
High
• ./ansible.cfg
• If an ansible.cfg file exists in the directory in which the ansible command is
executed, it is used instead of the global file or the user's personal file.
Very High
• $ANSIBLE_CONFIG
Priority
■ ~]$ ansible --version
ansible 2.3.1.0
config file = /etc/ansible/ansible.cfg
...output omitted...
Configuring Connections
■ Some of the information needed from configuration file .
Setting Description
inventory
The location of the Ansible inventory.
remote_user
The remote user account used to establish connections to
managed hosts
ask_pass
Prompt for a password to use when connecting as the remote
user.
become
Enable or disable privilege escalation for operations on
managed hosts.
become_method The privilege escalation method to use on managed hosts.
become_user
The user account to escalate privileges to on managed hosts.
become_ask_pass
Defines whether privilege escalation on managed hosts should
prompt for a password.
Ad-Hoc commands
■ Would be something that you might type in to do something really
quick, but don’t want to save for later
Playbooks
■ Series of ansible commands(tasks),that are targeted at a specific set
of hosts/groups
■ Expressed in YAML format
■ Each playbooks is composed of one or more ‘plays’ in a list.
■ Playbook goal is to map a group of hosts to well defined plays or
roles.
Tasks: Are executed in order ,one at a time, against all machines
matched by the host pattern, before moving on to the next task.
Handlers: "sleeping" tasks that can be invoked by a task upon
completion (e.g. when config file change, restart service)
Depict : Playbook
Variables
■ Ansible supports variables that can be used to store values that can
be reused throughout files in an entire Ansible project.
■ Variables provide a convenient way to manage dynamic values for a
given environment in your Ansible project.
Three basic scope levels:
• Global scope: Variables set from the command line or Ansible
configuration
• Play scope: Variables set in the play and related structures
• Host scope: Variables set on host groups and individual hosts by the
inventory, fact gathering, or registered tasks
Facts
■ Ansible facts are variables that are automatically discovered by
Ansible on a managed host.
■ Facts contain host-specific information that can be used just like
regular variables in plays, conditionals, loops, or any other statement
that depends on a value collected from a managed host.
$ ansible demo1.example.com -m setup
$ ansible demo1.example.com -m setup -a 'filter=ansible_eth0'
Task control
■ Loops
■ When statement
■ Handlers
■ Tags
■ Handling Errors
■ block, rescue, always
(https://www.pandastrike.com/posts/20160308-ansible-blocks-examples/)
Jinja2 Template
■ Ansible uses the Jinja2 templating system to modify files before
they are distributed to managed hosts. Generally speaking, it is
preferable to avoid modifying configuration files through logic in
templates. However, templates can be useful when systems need
to have slightly modified versions of the same file.
roles
■ Necessary comes as we add more and more functionality to our
playbook.
■ It allows to create very minimal playbook that then look to a
directory structure to determine the actual configuration steps they
need to perform.
■ Enforces modularity so that we can reuse commonly used
tasks(roles) again.
Ansible-galaxy
■ a public library of Ansible roles written by a variety
■ of Ansible administrators and users. It is an archive that contains
thousands of Ansible roles
■ and it has a searchable database that helps Ansible users identify
roles that might help them
■ accomplish an administrative task.
ansible-galaxy init --offline -p roles db
Vault
■ Allows keeping encrypted data in source control
■ Created encrypted files
$ ansible-vault create foo.yml
■ Editing encrypted files
$ ansible-vault edit foo.yml
Encrypting unencrypted files
$ ansible-vault encrypt foo.yml
 Decrypting encrypted files
$ ansible-vault decrypt foo.yml
 Running ad-hoc or playbook with vault
Ansible-playbook site.yml –vault-password-file ~/.vault_pass.txt
Idempotency
An operation is idempotent if the result of performing it once is exactly
the same as the result of performing it repeatedly without any
intervening actions.
Idempotency principle is not applied by default to the command
module. In order to achieve idempotence, you could use the attribute
creates. When present, Ansible will only run the command task if the
file specified by the pattern does not exists.
Every time you run it, it will be detected as “changed” even though nothing
actually changes.
An important line there is the changed_when: false line. Typically ansible
assumes that a command changes the state of the host, but changed_when lets
you set a Jinja2 conditional to specify a different condition. This stops false
alarms from runs that change nothing on the host, which is good for
idempotency.
- name: ensure postgresql hstore extension is created
sudo: yes
sudo_user: postgres
shell: "psql my_database -c 'CREATE EXTENSION hstore;'"
register: psql_result
failed_when: >
psql_result.rc != 0 and ("already exists" not in
psql_result.stderr)
changed_when: "psql_result.rc == 0"
3-Tier Architecture and Deployment
26
Source Build
Test Deploy
Ops
Process tools
Bitbucket
Cheat sheet
■ https://gist.github.com/andreicristianpetcu/b892338de279af9dac06
7891579cad7d
Bitbucket
■ https://bitbucket.org/gsabarinath91/3-tier-flask-app-deploy-
ansible-playbook
■ https://bitbucket.org/gsabarinath91/ansible_playbook_deploy_vsp
here_vm
Thank you
Questions???

More Related Content

What's hot (20)

ODP
Using Ansible at Scale to Manage a Public Cloud
Jesse Keating
 
PPTX
Hands on ansible
sumit23kumar
 
PDF
Ansible 101 - Presentation at Ansible STL Meetup
Jeff Geerling
 
PPTX
Introduction to ansible
Omid Vahdaty
 
PDF
Ansible Meetup Hamburg / Quickstart
Henry Stamerjohann
 
PPTX
Ansible 101, Gennadiy Mykhailiuta
Tetiana Saputo
 
PDF
Testing with Ansible
Bas Meijer
 
PDF
Network Automation: Ansible 101
APNIC
 
PDF
Ansible Automation to Rule Them All
Tim Fairweather
 
PDF
Introduction to ansible
Mukul Malhotra
 
PDF
Ansible, best practices
Bas Meijer
 
PDF
Ansible
Vishal Yadav
 
PPTX
Basics of Ansible - Sahil Davawala
Sahil Davawala
 
PDF
Ansible - Hands on Training
Mehmet Ali Aydın
 
PDF
Getting started with Ansible
Ivan Serdyuk
 
PPT
Fake IT, until you make IT
Bas Meijer
 
PDF
Development of Ansible modules
jtyr
 
PDF
Network Automation: Ansible 102
APNIC
 
PPTX
Vagrant, Ansible, and OpenStack on your laptop
Lorin Hochstein
 
PDF
Ansible roles done right
Dan Vaida
 
Using Ansible at Scale to Manage a Public Cloud
Jesse Keating
 
Hands on ansible
sumit23kumar
 
Ansible 101 - Presentation at Ansible STL Meetup
Jeff Geerling
 
Introduction to ansible
Omid Vahdaty
 
Ansible Meetup Hamburg / Quickstart
Henry Stamerjohann
 
Ansible 101, Gennadiy Mykhailiuta
Tetiana Saputo
 
Testing with Ansible
Bas Meijer
 
Network Automation: Ansible 101
APNIC
 
Ansible Automation to Rule Them All
Tim Fairweather
 
Introduction to ansible
Mukul Malhotra
 
Ansible, best practices
Bas Meijer
 
Ansible
Vishal Yadav
 
Basics of Ansible - Sahil Davawala
Sahil Davawala
 
Ansible - Hands on Training
Mehmet Ali Aydın
 
Getting started with Ansible
Ivan Serdyuk
 
Fake IT, until you make IT
Bas Meijer
 
Development of Ansible modules
jtyr
 
Network Automation: Ansible 102
APNIC
 
Vagrant, Ansible, and OpenStack on your laptop
Lorin Hochstein
 
Ansible roles done right
Dan Vaida
 

Similar to ansible : Infrastructure automation,idempotent and more (20)

PDF
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
Jumping Bean
 
PPTX
Introduction to Ansible
CoreStack
 
PPTX
Ansible as configuration management tool for devops
Puneet Kumar Bhatia (MBA, ITIL V3 Certified)
 
PDF
Introducing Ansible
Francesco Pantano
 
PPTX
Ansible
Afroz Hussain
 
PDF
Ansible Tutorial.pdf
NigussMehari4
 
PPTX
SESSION Ansible how to deploy and push resources
Saravanan68713
 
PPTX
Intro to-ansible-sep7-meetup
Ramesh Godishela
 
PDF
Hands On Introduction To Ansible Configuration Management With Ansible Comple...
SlideTeam
 
PPTX
Introduction to Ansible - (dev ops for people who hate devops)
Jude A. Goonawardena
 
PDF
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
Ihor Banadiga
 
PDF
Ansible
Rahul Bajaj
 
PDF
Ansible automation tool with modules
mohamedmoharam
 
PDF
Getting Started with Ansible - Jake.pdf
ssuserd254491
 
PPTX
Automating with ansible (Part A)
iman darabi
 
PDF
Managing PostgreSQL with Ansible - FOSDEM PGDay 2016
Gulcin Yildirim Jelinek
 
PDF
Ansible at work
Bas Meijer
 
PPTX
Introduction to Ansible - Jan 28 - Austin MeetUp
tylerturk
 
PDF
Dal caos all’automazione di sistemi e infrastrutture IT con Ansible
Commit University
 
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
Jumping Bean
 
Introduction to Ansible
CoreStack
 
Ansible as configuration management tool for devops
Puneet Kumar Bhatia (MBA, ITIL V3 Certified)
 
Introducing Ansible
Francesco Pantano
 
Ansible
Afroz Hussain
 
Ansible Tutorial.pdf
NigussMehari4
 
SESSION Ansible how to deploy and push resources
Saravanan68713
 
Intro to-ansible-sep7-meetup
Ramesh Godishela
 
Hands On Introduction To Ansible Configuration Management With Ansible Comple...
SlideTeam
 
Introduction to Ansible - (dev ops for people who hate devops)
Jude A. Goonawardena
 
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
Ihor Banadiga
 
Ansible
Rahul Bajaj
 
Ansible automation tool with modules
mohamedmoharam
 
Getting Started with Ansible - Jake.pdf
ssuserd254491
 
Automating with ansible (Part A)
iman darabi
 
Managing PostgreSQL with Ansible - FOSDEM PGDay 2016
Gulcin Yildirim Jelinek
 
Ansible at work
Bas Meijer
 
Introduction to Ansible - Jan 28 - Austin MeetUp
tylerturk
 
Dal caos all’automazione di sistemi e infrastrutture IT con Ansible
Commit University
 
Ad

Recently uploaded (20)

PDF
Simplify React app login with asgardeo-sdk
vaibhav289687
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PPTX
iaas vs paas vs saas :choosing your cloud strategy
CloudlayaTechnology
 
PPTX
Customise Your Correlation Table in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
Dipole Tech Innovations – Global IT Solutions for Business Growth
dipoletechi3
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Get Started with Maestro: Agent, Robot, and Human in Action – Session 5 of 5
klpathrudu
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PPTX
Smart Doctor Appointment Booking option in odoo.pptx
AxisTechnolabs
 
PPTX
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
PDF
Salesforce Experience Cloud Consultant.pdf
VALiNTRY360
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
PDF
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PDF
Add Background Images to Charts in IBM SPSS Statistics Version 31.pdf
Version 1 Analytics
 
Simplify React app login with asgardeo-sdk
vaibhav289687
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
iaas vs paas vs saas :choosing your cloud strategy
CloudlayaTechnology
 
Customise Your Correlation Table in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Dipole Tech Innovations – Global IT Solutions for Business Growth
dipoletechi3
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Get Started with Maestro: Agent, Robot, and Human in Action – Session 5 of 5
klpathrudu
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Smart Doctor Appointment Booking option in odoo.pptx
AxisTechnolabs
 
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
Salesforce Experience Cloud Consultant.pdf
VALiNTRY360
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
Add Background Images to Charts in IBM SPSS Statistics Version 31.pdf
Version 1 Analytics
 
Ad

ansible : Infrastructure automation,idempotent and more

  • 1. ANSIBLE : INFRASTRUCTURE AUTOMATION, IDEMPOTENT AND MORE By Sabarinath Gnanasekar
  • 2. Ansible Overview ■ Open source model-driven configuration management tool that leverages SSH to improve security and simplify management of configuration across various O/S ,Application, Network ,Storage and Cloud platforms. ■ Designed by considering below  Ease of use  Low learning curve  Comprehensive automation  Efficiency  Security 2
  • 3. Bootstrap Instruction ■ https://geekcontainer.wordpress.com/2016/08/05/configuration- management-ansible-series-1/ ■ https://geekcontainer.wordpress.com/2016/08/06/configuration- management-ansible-series-2/ ■ https://geekcontainer.wordpress.com/2016/08/06/configuration- management-ansible-series-3/
  • 5. Features  Improved network security- it has a very low attack surface (openssh daemon or winrm and no agent)  Enabling non-root level access (and sudo)  Limiting transfer of potentially sensitive data  Credential segregation  Central server scalability  Resource utilization  Firewall friendly  Zero bootstrapping  Parallel by default  Immutable infrastructure 5
  • 6. Comparison with Puppet Entity Ansible Puppet Agent Excellent performance Agent less install and deploy Uses agent Components 1) OpenSSH 2) Python 1) Ruby 2) Facter 3) Puppet master 4) agent Language Based on ubiquitous Python. Ruby(written by programmers for programmers) Method Pull Push Directive language YAML with Jinja2 template Custom Bootstrap Child Need Not Needed Required Remote Execution Built-in and easy Mcollective and challenging Port 22 - Openssh 8140- Puppet Master 443 - Puppet Console 61613 - Mcollective 8142 - Orchestrator 6
  • 7. Building an Ansible Inventory:Inventory File ■ defines a collection of hosts that Ansible will manage ■ Define logical groups of managed nodes ■ Default inventory file location: /etc/ansible/hosts ■ INI format Communication variables: ansible_connection : local,ssh or paramiko ansible_ssh_host : name of the host to connect ansible_ssh_user : ssh user name to use ansible_ssh_port : ssh password to use ansible_ssh_pass : ssh port number to use ansible_ssh_private_key_file : private key file used by ssh
  • 8. Example for Inventory Defining Nested Groups Host Specifications with Ranges
  • 9. Patterns  all hosts in the inventory (all or *)  a specific host name or group name (host1, webservers)  wildcard configuration (192.168.1.*)  OR configuration (host1:host2, webservers:dbservers)  NOT configuration (webservers:dbservers:!production)  AND configuration (webservers:dbservers:&staging)  REGEX configuration (~(web|db).*.example.com)  exclude hosts using limit flag (ansible-playbook site.yml --limit datacenter2)
  • 10. Ansible Configuration Files & Precedence Low • /etc/ansible/ansible.cfg • Default a base configuration file located Medium • ~/.ansible.cfg • user's home directory High • ./ansible.cfg • If an ansible.cfg file exists in the directory in which the ansible command is executed, it is used instead of the global file or the user's personal file. Very High • $ANSIBLE_CONFIG Priority
  • 11. ■ ~]$ ansible --version ansible 2.3.1.0 config file = /etc/ansible/ansible.cfg ...output omitted... Configuring Connections ■ Some of the information needed from configuration file .
  • 12. Setting Description inventory The location of the Ansible inventory. remote_user The remote user account used to establish connections to managed hosts ask_pass Prompt for a password to use when connecting as the remote user. become Enable or disable privilege escalation for operations on managed hosts. become_method The privilege escalation method to use on managed hosts. become_user The user account to escalate privileges to on managed hosts. become_ask_pass Defines whether privilege escalation on managed hosts should prompt for a password.
  • 13. Ad-Hoc commands ■ Would be something that you might type in to do something really quick, but don’t want to save for later
  • 14. Playbooks ■ Series of ansible commands(tasks),that are targeted at a specific set of hosts/groups ■ Expressed in YAML format ■ Each playbooks is composed of one or more ‘plays’ in a list. ■ Playbook goal is to map a group of hosts to well defined plays or roles. Tasks: Are executed in order ,one at a time, against all machines matched by the host pattern, before moving on to the next task. Handlers: "sleeping" tasks that can be invoked by a task upon completion (e.g. when config file change, restart service)
  • 16. Variables ■ Ansible supports variables that can be used to store values that can be reused throughout files in an entire Ansible project. ■ Variables provide a convenient way to manage dynamic values for a given environment in your Ansible project. Three basic scope levels: • Global scope: Variables set from the command line or Ansible configuration • Play scope: Variables set in the play and related structures • Host scope: Variables set on host groups and individual hosts by the inventory, fact gathering, or registered tasks
  • 17. Facts ■ Ansible facts are variables that are automatically discovered by Ansible on a managed host. ■ Facts contain host-specific information that can be used just like regular variables in plays, conditionals, loops, or any other statement that depends on a value collected from a managed host. $ ansible demo1.example.com -m setup $ ansible demo1.example.com -m setup -a 'filter=ansible_eth0'
  • 18. Task control ■ Loops ■ When statement ■ Handlers ■ Tags ■ Handling Errors ■ block, rescue, always (https://www.pandastrike.com/posts/20160308-ansible-blocks-examples/)
  • 19. Jinja2 Template ■ Ansible uses the Jinja2 templating system to modify files before they are distributed to managed hosts. Generally speaking, it is preferable to avoid modifying configuration files through logic in templates. However, templates can be useful when systems need to have slightly modified versions of the same file.
  • 20. roles ■ Necessary comes as we add more and more functionality to our playbook. ■ It allows to create very minimal playbook that then look to a directory structure to determine the actual configuration steps they need to perform. ■ Enforces modularity so that we can reuse commonly used tasks(roles) again.
  • 21. Ansible-galaxy ■ a public library of Ansible roles written by a variety ■ of Ansible administrators and users. It is an archive that contains thousands of Ansible roles ■ and it has a searchable database that helps Ansible users identify roles that might help them ■ accomplish an administrative task. ansible-galaxy init --offline -p roles db
  • 22. Vault ■ Allows keeping encrypted data in source control ■ Created encrypted files $ ansible-vault create foo.yml ■ Editing encrypted files $ ansible-vault edit foo.yml Encrypting unencrypted files $ ansible-vault encrypt foo.yml  Decrypting encrypted files $ ansible-vault decrypt foo.yml  Running ad-hoc or playbook with vault Ansible-playbook site.yml –vault-password-file ~/.vault_pass.txt
  • 23. Idempotency An operation is idempotent if the result of performing it once is exactly the same as the result of performing it repeatedly without any intervening actions. Idempotency principle is not applied by default to the command module. In order to achieve idempotence, you could use the attribute creates. When present, Ansible will only run the command task if the file specified by the pattern does not exists.
  • 24. Every time you run it, it will be detected as “changed” even though nothing actually changes. An important line there is the changed_when: false line. Typically ansible assumes that a command changes the state of the host, but changed_when lets you set a Jinja2 conditional to specify a different condition. This stops false alarms from runs that change nothing on the host, which is good for idempotency. - name: ensure postgresql hstore extension is created sudo: yes sudo_user: postgres shell: "psql my_database -c 'CREATE EXTENSION hstore;'" register: psql_result failed_when: > psql_result.rc != 0 and ("already exists" not in psql_result.stderr) changed_when: "psql_result.rc == 0"