ansible-2.x

How to add a callback plugin to a PlaybookExecutor in Ansible 2

依然范特西╮ 提交于 2019-12-06 03:51:43
How to specify a callback when calling ansible via its API? I have a callback plugin database_write.py for ansible 2.0.0.2 that logs into a database when this is run: ansible-playbook -i inventory.txt playbook.yml # callback is fired ok This works ok because in my $PWD i have ansible.cfg with this line: callback_plugins = ./src/callback Now I'm trying to make ansible to execute my playbook and my callback using the python API. I've basically copied what the ansible-playbook cli tool does # based on https://github.com/ansible/ansible/blob/v2.0.0.2-1/lib/ansible/cli/playbook.py pbex =

Ansible - managing multiple SSH keys for multiple users & roles

蹲街弑〆低调 提交于 2019-12-06 02:40:30
问题 The Problem I am managing a number of different servers with Ansible. Each server has multiple Linux users, such as readonly , admin , etc. I also have a number of files inside my Ansible project which contain all SSH keys for a particular group of people - eg. AppDevelopersPublicKeys , DbaPublicKeys , etc. Different groups of people have different access levels on different servers. Eg. on a WebServer, AppDevelopers have admin access, and DBAs might only have read access. On Database servers

Ansible playbook fails to lock apt

微笑、不失礼 提交于 2019-12-05 10:25:56
I took over a project that is running on Ansible for server provisioning and management. I'm fairly new to Ansible but thanks to the good documentation I'm getting my head around it. Still I'm having an error which has the following output: failed: [build] (item=[u'software-properties-common', u'python-pycurl', u'openssh-server', u'ufw', u'unattended-upgrades', u'vim', u'curl', u'git', u'ntp']) => {"failed": true, "item": ["software-properties-common", "python-pycurl", "openssh-server", "ufw", "unattended-upgrades", "vim", "curl", "git", "ntp"], "msg": "Failed to lock apt for exclusive

Ansible ad-hoc command with direct host specified - no hosts matched

旧巷老猫 提交于 2019-12-04 18:29:35
问题 I am running a 16.04 Ubuntu desktop machine using VirtualBox. This VM has Ansible 2.4.0 installed. I am trying to run an ad-hoc ansible command just to prove it works (I am doing an online course). To simulate a small server farm, I use lxc (linux containters) and have three of them running: root@tomasz-VirtualBox:/home/tomasz/ansible# lxc-ls --fancy NAME STATE AUTOSTART GROUPS IPV4 IPV6 db1 RUNNING 0 - 10.0.3.248 - web1 RUNNING 0 - 10.0.3.110 - web2 RUNNING 0 - 10.0.3.226 - I can SSH to any

iteration using with_items and register

大憨熊 提交于 2019-12-04 18:01:32
问题 Looking for help with a problem I've been struggling with for a few hours. I want to iterate over a list, run a command, register the output for each command and then iterate with debug over each unique registers {{ someregister }}.stdout For example, the following code will spit out "msg": "1" and "msg": "2" --- - hosts: localhost gather_facts: false vars: numbers: - name: "first" int: "1" - name: "second" int: "2" tasks: - name: Register output command: "/bin/echo {{ item.int }}" register:

Run Ansible playbook programmatically?

北慕城南 提交于 2019-12-04 13:45:12
I have a python application that calls the code below with the plan to run an Ansible playbook programmatically via the Ansible API versus using something like subprocess. The code below runs but nothing actually seems to get executed. Grabbing the output of results just gives me a dictionary that looks like: [{'plays': [localhost], 'playbook': 'playbooks/asg_elb_example.yml'}] I am not sure where I am going wrong or what I am missing. Here is the code I am running. import os import sys SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) ROOT_DIR = os.path.dirname(SCRIPT_DIR) import json

Ansible - managing multiple SSH keys for multiple users & roles

爱⌒轻易说出口 提交于 2019-12-04 06:49:33
The Problem I am managing a number of different servers with Ansible. Each server has multiple Linux users, such as readonly , admin , etc. I also have a number of files inside my Ansible project which contain all SSH keys for a particular group of people - eg. AppDevelopersPublicKeys , DbaPublicKeys , etc. Different groups of people have different access levels on different servers. Eg. on a WebServer, AppDevelopers have admin access, and DBAs might only have read access. On Database servers, vice versa. To achieve the above, I have different Ansible roles for different types of server (eg.

Correct way to create dynamic lists in Ansible

耗尽温柔 提交于 2019-12-03 12:53:42
I'm looking for advice. I have the following code that creates a list dynamically that I can then later use in a template. This is a copy of the test code I put together - for the actual role I just added the admins|regex_replace variable into the j2 template. --- - hosts: localhost gather_facts: false vars: # define empty admins var first so ansible doesn't complain admins: admin_accounts: - name: john uid: 1000 group: sysadmin shell: /bin/bash comment: "Unix Administrator" - name: paul uid: 1001 group: sysadmin shell: /bin/bash comment: "Unix Administrator" - name: george uid: 1002 group:

Ansible ad-hoc command with direct host specified - no hosts matched

妖精的绣舞 提交于 2019-12-03 11:56:05
I am running a 16.04 Ubuntu desktop machine using VirtualBox. This VM has Ansible 2.4.0 installed. I am trying to run an ad-hoc ansible command just to prove it works (I am doing an online course). To simulate a small server farm, I use lxc (linux containters) and have three of them running: root@tomasz-VirtualBox:/home/tomasz/ansible# lxc-ls --fancy NAME STATE AUTOSTART GROUPS IPV4 IPV6 db1 RUNNING 0 - 10.0.3.248 - web1 RUNNING 0 - 10.0.3.110 - web2 RUNNING 0 - 10.0.3.226 - I can SSH to any of these servers, however when I try to run a one-off ansible command, for example: root@tomasz

How to use ansible 'expect' module for multiple different responses?

蹲街弑〆低调 提交于 2019-12-03 11:27:46
Here I am trying to test my bash script where it is prompting four times. #!/bin/bash date >/opt/prompt.txt read -p "enter one: " one echo $one echo $one >>/opt/prompt.txt read -p "enter two: " two echo $two echo $two >>/opt/prompt.txt read -p "enter three: " three echo $three echo $three >>/opt/prompt.txt read -p "enter password: " password echo $password echo $password >>/opt/prompt.txt for this script I wrote the code below, and it is working fine - hosts: "{{ hosts }}" tasks: - name: Test Script expect: command: sc.sh responses: enter one: 'one' enter two: 'two' enter three: 'three' enter