Re: [ansible-project] Using a defined group_var over an undefined host_var (or how to hack variable precedence)

2018-12-18 Thread Branko Majic
On Tue, 18 Dec 2018 08:28:18 -0800 (PST)
Eric Brewer  wrote:

> I have a scenario where I need to be able to specify to use the
> group_vars for a NTP timeserver, unless the host_vars are defined.
> All of the variables are going to be coming out of an intermediary
> document that the customer is going to be filling out, like this:
> 
> vars/customer_vars.yml
> timeserver1_default: 1.1.1.1
> timeserver2_default: 1.1.1.2
> timeserver1_server1: 1.1.1.3
> timeserver2_server1: 1.1.1.4
> timeserver2_server2: ~
> timeserver2_server2: ~

Perhaps you have already thought about it, but any reason why you
wouldn't make this into a list of NTP servers instead?

E.g.

timeservers:
  - 1.1.1.1
  - 1.1.1.2

This lets you easily override values per-group and per-host
basis, and also makes it pretty clear on what's going on.

> But I need to find a way around the fact, that if the host_var is
> defined in any way, even if its empty, that's the one that gets
> used.  Does anyone know a way to default to a group_var if a host_var
> is empty? I could rename the group_var ones and then write 2
> different version of the conf file, pulling one if the host_var is
> empty for a particular server and another if its not, but I would
> really not have to have multiple versions of the same form.  It would
> seem like there is a better way of doing this that I just don't know,
> but maybe not...

This is going to be one of "those" answers, but the way you are
describing it looks to be a bit overcomplicated to me. E.g. even if it
can be done, sounds like it would be rather fiddly and unintuitive when
you decide to make configuration changes.

Best regards

-- 
Branko Majic
XMPP: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
XMPP: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20181218192818.6d3e87d0%40majic.rs.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] How to configure playbook serial value by group var from inventory file?

2018-02-09 Thread Branko Majic
On Fri, 9 Feb 2018 01:35:08 -0800 (PST)
Bing Hsueh <bing.tangb...@gmail.com> wrote:

> > ERROR! The field 'serial' has an invalid value, which includes an   
> >> undefined variable. The error was: 'batch_deploy' is undefined  

Ansible is complaining that you are referencing a variable
"batch_deploy", and that it is not defined anywhere.

> inventory.yml
> ---
> deployservers:
> vars:
>  deploy_batch: 1

Here, the variable is called "deploy_batch".

> playbook.yml
> ---
>   - name: test rolling update by batch size
> hosts: deployservers
> serial: "{{ batch_deploy }}"

Here, the variable is called "batch_deploy". E.g. not the same as in
the inventory file (swapped batch/deploy in the name).

Best regards

-- 
Branko Majic
XMPP: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
XMPP: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20180209134043.594aa837%40majic.rs.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Problem referencing variables

2017-09-21 Thread Branko Majic
On Tue, 19 Sep 2017 10:13:37 -0700 (PDT)
Dave Florek <dave.a.flo...@gmail.com> wrote:

> *Error message I get at execution:*
> 
> ERROR! Syntax Error while loading YAML.
> 
> 
> The error appears to have been in 
> '/opt/ansible/setup_scripts/create_user.yml': line 20, column 1, but
> may be elsewhere in the file depending on the exact syntax problem.

It can easily happen to be an issue elsewhere in the file, but it's
hard to tell since you posted only a very small snippet.

If you comment-out that particular task do you still have the same
issue being reported?

I would double-check the indentation as well, since what you posted as
sample had a bit "deeper" indentation (maybe tabs vs spaces or too much
indentation).

What version of Ansible are you using?

> The offending line appears to be:
> 
> 
>   - lineinfile:
> path: /home/"{{ new_user_acct_name }}"/.ssh/authorized_keys

Any reason you wouldn't be using authorized_key module
(http://docs.ansible.com/ansible/latest/authorized_key_module.html)?

Best regards

-- 
Branko Majic
XMPP: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
XMPP: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20170921120110.5e7791f1%40majic.rs.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] ansible doubt

2017-07-28 Thread Branko Majic
On Fri, 28 Jul 2017 03:30:15 -0700 (PDT)
Sameer Modak <sameer.modak1...@gmail.com> wrote:

> I tried with given command but it does not work.
> 
> I will repeat my question. My question is we have 20 servers in
> inventory file and i want /sbin/vgs data using below command
> 
> 
> ansible -b -k -m shell -a "/sbin/vgs" all
> 
> Now out of 20 server 2 servers does not have smodak account
> in /etc/sudoers file so i m getting below error for those 
> 
> SUDO password[defaults to SSH password]:
> NESBWDA01 | FAILED | rc=0 >>
> MODULE FAILURE
> 
> 
> How we can resolve this without adding smodak account in /etc/sudoers

Not sure why you wouldn't set-up sudoers for somethings like this,
but...

If you have a look at output of ansible --help you will notice there is
a couple of different arguments related to switching users.

In your case, you should try running something similar to:

ansible --ask-become-pass --become-method su -b -k -m shell -a "/sbin/vgs" all

This will prompt you for two passwords - one for SSH connection, and
one for the _root_ user.

Best regards

-- 
Branko Majic
XMPP: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
XMPP: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20170728140852.4584656a%40majic.rs.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] service module doesnt work

2017-07-22 Thread Branko Majic
On Sat, 22 Jul 2017 00:38:10 -0700 (PDT)
Gaurav1212 <gaurav.srivastava.1...@gmail.com> wrote:

> Hi,
> 
> I am trying to restart the cron and httpd services, but unable to do
> so with ansible.
> 
> Output shows OK, but changed=0. See below output.
> 
> [root@slc09vev ansible]# ansible-playbook restart.cron.pb.yml
> 
> PLAY [This is to call the restart_cron role] 
> ***
> 
> TASK [Gathering Facts] 
> *
> ok: [slc11zrn]
> ok: [slc09vev]
> 
> PLAY RECAP 
> *
> host1   : ok=1changed=0unreachable=0
> failed=0 host2   : ok=1changed=0
> unreachable=0failed=0
> 
> 
> Here is my task file:
> 
> [root@slc09vev ansible]# cat roles/restart_cron/tasks/cron_restart.yml
>  - name:"restart crond service"
>  - service:
>  name:crond state:restarted
> 
> What could be the reason for this?

Your task is never executed, you can see that in the output (there is
no mention whatsoever of "restart crond service").

Additionally, the task as you have output it here would never run
because of syntax errors (even if you had it correctly included) -
because it's not valid yaml. It would need to look something similar
to (note the spaces and newlines):

- name: "restart crond service"
- service:
name: crond
state: restarted

Best regards

-- 
Branko Majic
XMPP: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
XMPP: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20170722105124.39a9a474%40majic.rs.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] How to *not* print ansible diagnostic error messages?

2017-07-21 Thread Branko Majic
On Fri, 21 Jul 2017 16:34:53 +0200
Frank Thommen <lists.ansi...@drosera.ch> wrote:

> Hi,
> 
> I have a playbook which executes a local task from which I need the
> exit status in later steps:
> 
> 
>- name: Get exit status of ./run.sh
>  local_action:  command ./run.sh
>  register:  ES
>  ignore_errors: yes
> 
>- name: Do something if ./run.sh failed
>  command:
>   
>  when: ES.rc == 1
> 
> 
> Unfortunately when "./run.sh" fails, ansible prints a whole bunch of 
> diagnostic output to the screen, which I am not interested in.
> 
> How can I tell ansible *not* to print diagnostic error output of a 
> specific step?
> 
> We are running ansible 2.3.0 0 on CentOS 7
> 
> Cheers
> frank

You could use "failed_when: False" on the task. Although, keep in mind
that would make the task treated as successful for all other purposes
(e.g. ES.failed would be set to False).

Best regards

-- 
Branko Majic
XMPP: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
XMPP: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20170721171736.6d65ef1f%40majic.rs.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Loop using with_items twice

2017-07-21 Thread Branko Majic
On Thu, 20 Jul 2017 18:49:55 -0700 (PDT)
Anfield <gareth.has...@gmail.com> wrote:

> What is the correct way to use with_Items to loop over two files? The 
> playbook is failing at the 2nd task
> 
> Getting an error - TASK [Create users from vars users] 
> 
> fatal: [localhost]: FAILED! => {"failed": true, "msg": "the field
> 'args' has an invalid value, which appears to include a variable that
> is undefined. The error was:
> 'ansible.vars.unsafe_proxy.AnsibleUnsafeText object' has no attribute
> 'users'\n\nThe error appears to have been in
> '/etc/ansible/playbooks/exercises/usersgroups.yml': line 15, column
> 6, but may\nbe elsewhere in the file depending on the exact syntax
> problem.\n\nThe offending line appears to be:\n\n\n   - name: Create
> users from vars users\n ^ here\n"}
> 
> users.yml (is below, grouplist.yml is similar)
> ---
> users:
> - jock
> - dejan
> - joel
> 
> Playbook is below -
> 
> - users.yml
> - grouplist.yml
>   tasks:
> 
>- name: Create groups from vars file
>  group:
> name: "{{item}}"
> state: present
>  with_items: "{{grouplist}}"
> 
>- name: Create users from vars users
>  user:
> name: "{{item.users}}"
> state: present
> groups: "{{item.grouplist}}"
>  with_items:
>  - "{{ users}}"
>  - "{{grouplist}}"

Assuming that what you want to do is create a number of groups listed
in the grouplist variable, and then create the users listed in the
users variable, where each user is member of all groups in the
grouplist variable, your second task should be one of the following
(Ansible 2.3 can accept lists directly in "groups" attribute):

- name: Create users from vars users (Ansible 2.3+)
  user:
name: "{{ item }}"
state: present
groups: "{{ grouplist }}"
  with_items: "{{ userlist }}"

- name: Create users from vars users (Ansible <2.3)
  user:
name: "{{ item }}"
state: present
groups: "{{ grouplist | join(',') }}"
  with_items: "{{ userlist }}"

Best regards

-- 
Branko Majic
XMPP: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
XMPP: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20170721143214.2f4a4ee0%40majic.rs.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] elb_target_group module no longer in use?

2017-07-20 Thread Branko Majic
On Thu, 20 Jul 2017 08:48:48 -0700 (PDT)
Trevor Ma <trevorm...@gmail.com> wrote:

> Hi I'm new here and have been doing some ansible. I need to register
> an instance to a target group and ansible is great as it has a module
> for it. However, nothing I do works. The funny thing is that the
> module reference page for it doesn't even exist anymore. Does that
> just mean the module is no longer supported and explains why I can't
> get it to ever work?
> 
> Below is the link to it.
> 
> http://docs.ansible.com/ansible/elb_target_group_module.html
> 
> Thank you in advance

What version of Ansible are you using?

Looking at the Git repo sources for the module (it's definitively
there), it has been marked as being added in version 2.4 of Ansible -
which is not yet released.

So... You would probably need to wait until it gets released, or make a
local copy of it available to your playbooks (which, of course, you
need to remember to remove etc - after testing - once 2.4 comes out :)

Best regards

-- 
Branko Majic
XMPP: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
XMPP: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20170720215129.089f19d5%40majic.rs.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Ask about "side by side" loop

2017-07-20 Thread Branko Majic
On Thu, 20 Jul 2017 08:04:54 -0700 (PDT)
aldyth maharsha <aldyt...@gmail.com> wrote:

> Hi All
> 
> I have question and I'm newbie in ansible...I try to clone multiple
> vm from template in vmware with each of them have different ip
> address.
>
> I can clone 20 vm from template successfully but when I tried to
> assign IP address I dont know how to create side by side loop like
> this
> 
> webapps-1 192.168.10.101
> webapps-2 192.168.10.102
> webapps-3 192.168.10.103
> 
> and so on until 20...So how to create side by side loop with
> different iteration?...Thank you

Did you consider using a bit of arithmetic instead? Or this is not
flexible enough for you?

E.g. you could do "{{ 100 + item | int }}" (take note you need the "|
int" on item because it's a string). Preferably you'd make the "100" a
parameter instead of leaving it in as magic, of course :)

Best regards

-- 
Branko Majic
XMPP: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
XMPP: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20170720214636.18fbcd2a%40majic.rs.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] How to detect which role called an other role in case of role dependency

2017-04-18 Thread Branko Majic
On Mon, 10 Apr 2017 05:58:41 -0700 (PDT)
gabri...@redhat.com wrote:

> Hi,
> 
> I have a playbook with many roles plus a common role that is used by
> each other roles.
> Basically, this common role is used because I have some tasks that
> are applicable for all roles, obviously, I don't want to rewrite
> these tasks as many time as I have a role.
> Recently I encountered a case where I need a task to be played for
> all roles except only one. Therefore, I'm looking for a way to detect
> which role issued the call to the common role due to dependency so I
> could filter when to skip the task or not with a simple `when`
> statement.

For start, I would suggest looking at this not from perspective of what
role depends on the common role, but instead what task in the common
role needs to be optional. The optional tasks performed could be viewed
as optional "features" of a role.

I.e. when you pass in the parameter to the "common" role, it should be
more along the lines of "enable_BLAH", "operation_mode" or something
similar. You want to put emphasis on what it is that will get run or
not.

> 1/ The fact that I need to hardcode the rolename is not something
> really clean I think.

As mentioned above, use a more logical name for the parameter. In this
specific case you probably want to have a boolean (True/False) value for
it.

> 2/ I'm obliged to declare a default variable for `parent_role` to
> avoid an error message :
> 
> "The error was: 'parent_role' is undefined"
> 
> Indeed, when my common role is played and was not called by my role
> that doesn't need to exclude the task from being played, I'll get
> this error since I do not pass the `parent_role` variable from the
> other roles.

Declaring defaults for roles is a perfectly ok thing to do - just keep
in mind what I wrote above apropos naming the parameter and its syntax.

As a side-note, there are some other ways to handle defaults for
undefined variables, like (although, I would say it is better to
declare values in defaults/main.yml instead):

http://docs.ansible.com/ansible/playbooks_filters.html#defaulting-undefined-variables

There is also the "when: foo is defined" syntax (which can be combined
with logical and/or as well). But you probably don't need it for your
use-case :)

> Maybe someone know a nicer way to do this ?

For an alternative to meta dependencies (although I have not tried this
myself, so take it with a grain of salt), have a look at:

http://docs.ansible.com/ansible/include_role_module.html

I would find the include_role module more useful in cases where you
want to control ordering in more complex way than just the "meta deps
first" -> "then this role".

Finally, you had two replies related to avoid dependencies via meta,
something you should consider as well (I thought it'd be nice to
provide at least one more way to handle things :)

Best regards

-- 
Branko Majic
XMPP: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
XMPP: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20170418203417.2aa4e097%40majic.rs.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Tags as variable inside of playbook

2016-03-15 Thread Branko Majic
Thanks for the input, but that is something that would solve my
requirement only partially.

What I wanted to do was more along the lines of (as someone has
already pointed out, tags do not seem to be exposed in a run):

- name: Run this only and only if the tag was defined
  debug: msg="I am tagged, therefore I run"
  when: myspecialtag in ansible_tags
  tags:
- myspecialtag

For now I think I would need to stick to the --extra-vars in combination
with --tags.

Perhaps a better description of what I want to do is to be able to
rerun handlers only as needed in order to have a way to clean-up
certain broken runs ("meta"-code provided below):

- name: Run handlers only
  include: ../handlers/main.yml
  when: handlers in ansible_tags
  tags:
- handlers

Best regards

On Tue, 15 Mar 2016 18:15:32 +0100
Jean-Yves LENHOF <jean-y...@lenhof.eu.org> wrote:

> If I understand correctly what you want...
> 
> ansible-playbook myplaybook.yml --tags=myspecialtag is what you're 
> looking for...
> 
> A tag can be use in more than one task...
> 
> The doc :
> http://docs.ansible.com/ansible/playbooks_tags.html
> 
> 
> Regards,
> 
> 
> Le 2016-03-15 13:08, Branko Majic a écrit :
> > Hello folks,
> > 
> > Is it possible to use tags as a variable inside of playbook?
> > 
> > Specifically, I would like to have a condition to execute certain task
> > only if a tag has been defined.
> > 
> > I am aware this can be done with an --extra-vars option + checking for
> > variable instead, but I wanted to see if I could abuse the tags system
> > a bit to make the syntax less verbose/clearer.
> > 
> > Best regards
> > 
> > --
> > Branko Majic
> > Jabber: bra...@majic.rs
> > Please use only Free formats when sending attachments to me.
> > 
> > Бранко Мајић
> > Џабер: bra...@majic.rs
> > Молим вас да додатке шаљете искључиво у слободним форматима.
> 



-- 
Branko Majic
Jabber: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
Џабер: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20160315182328.0ec0508b%40zetkin.primekey.se.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Tags as variable inside of playbook

2016-03-15 Thread Branko Majic
Hello folks,

Is it possible to use tags as a variable inside of playbook?

Specifically, I would like to have a condition to execute certain task
only if a tag has been defined.

I am aware this can be done with an --extra-vars option + checking for
variable instead, but I wanted to see if I could abuse the tags system
a bit to make the syntax less verbose/clearer.

Best regards

-- 
Branko Majic
Jabber: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
Џабер: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20160315130854.73ee524b%40zetkin.primekey.se.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Re: Dealing with inconsistencies after failed runs

2016-03-15 Thread Branko Majic
On Wed, 9 Mar 2016 09:22:40 -0500
Josh Smift <j...@care.com> wrote:

> Would a
> 
>   - meta: flush_handlers
> 
> task, immediately after the copy task (or whatever populates /etc/aliases,
> and does the notify), do what you want in this case? It still wouldn't
> help if the SSH connection dies immediately after the copy task, but
> there's not a whole lot you *can* do in that case. If it's important
> enough, maybe come up with a single shell task that populates the file and
> runs the handler, so the whole thing will happen even if SSH dies after
> the task, but that seems ugly unless it's essential that a particular
> task+handler combo be as close to atomic as possible.
>

Hm... Well, would make the window of opportunity smaller, so possibly
one way to about it. I wonder how people out there handle this when
using a lot of VMs (my use-case will be under 10).

Another thing that popped to my mind just now is to have a set of
tagged tasks within a role that would not execute unless tag is
provided that duplicate any handler/task that may need to be re-run to
fix possible inconsistencies. That way in case I detect a failed run, I
could rerun those tasks to fix things up. Any opinions on this? I just
wonder if I could abuse tags in this way, though (i.e. having a when:
tag defined syntax).

Best regards

-- 
Branko Majic
Jabber: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
Џабер: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20160315115355.64e092fd%40zetkin.primekey.se.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Dealing with inconsistencies after failed runs

2016-03-09 Thread Branko Majic
Hello all,

I have been running on occasion into situations where an incomplete run
could leave a system in inconsistent state. This has mostly happened in
cases where handlers are in use.

As an example, let's say you have a task populating /etc/aliases for
Postfix. In order for Postfix to be able to use the data, /etc/aliases
has to be compiled using the newaliases command. This is a natural fit
for a single Ansible task + handler (this is a very simple case, I've
had some more complex cases too).

The problem stems from the fact that Ansible playbook run could fail
before the handler fires off - leaving the /etc/aliases file updated,
but not the /etc/aliases.db (created via newaliases command).

I am aware of the "force_handlers = True" option, however that won't
help in cases where failure is, say, due to SSH connection dropping
etc.

>From what I can tell, this scenario possibly happens exclusively when
using handlers, since those are rather stateless (I'm sure you could
also trigger such behaviour with poorly designed command/shell
combination of tasks).

How do folks usually handle such situations?

Best regards

-- 
Branko Majic
Jabber: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
Џабер: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20160309100943.247d01f8%40zetkin.primekey.se.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] boot script

2015-02-09 Thread Branko Majic
On Mon, 9 Feb 2015 03:27:34 -0800 (PST)
aditya patnaik aditya@gmail.com wrote:

 Hi Folks,
 
 I am new to Ansible .I need help to create a boot script something like 
 kickstart file using  Ansible
 
 I already have a kickstart file (shown below)  to install centos   KVM on 
 a physicall host. The script will run on network (PXE)  i want in yaml 
 format But dont know how do i go ahead :-(
 
 when i use http://www.yamllint.com/ to test --it does not show any result. 
 :-(
 
 Please help!
 

Do you want to generate the Anaconda kickstart files using Ansible for
multiple servers, or something else?

If you wish to generate Anaconda kickstart files using Ansible, you
can easily do so using the template module (see
http://docs.ansible.com/template_module.html). Just figure out what
options you need to parametrise in the kickstart file, and pass those
in to your playbook.

You should go through the Ansible tutorials first, of course.

If you're trying to do something different, some more information about
what you are trying to achieve, how you have tried to do it, and what
issues you are having would be useful in order for people to be able to
help you.

Best regards

-- 
Branko Majic
Jabber: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
Џабер: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.

-- 
You received this message because you are subscribed to the Google Groups 
Ansible Project group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20150209130316.201f14d0%40zetkin.primekey.se.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: PGP signature


Re: [ansible-project] how to add custom jinja filters

2014-11-26 Thread Branko Majic
On Wed, 26 Nov 2014 08:58:48 -0800 (PST)
Ilin itatabitov...@gmail.com wrote:

 Hi,
 
 Is there a good example how to extend ansible with custom jinja filters?
 
 I have added this, but my filter is not found
 http://docs.ansible.com/intro_configuration.html#filter-plugins
 
 Adding the function to core.py works, but it just looks wrong
 
 

As it turns out, I played around a bit with this just a couple of weeks
ago, and it's quite simple.

The easiest way is to simply create a directory where your top-level
playbook is (site.yml?) called filter_plugins. Within that directory
you simply put .py files with content similar to (% is just to
show where file begins/ends, don't copy that :):

%
def uppercase_all(arg):
return arg.upper()


class FilterModule(object):
def filters(self):
return {'uppercase_all': uppercase_all}
%

With the above in place, you can simply use the filter uppercase_all
within your playbooks, roles etc. Note that you don't necessarily need
to have the same name for function and filter, but it's probably better
to do it that way.

If you look at the page you posted, it will direct you to
http://docs.ansible.com/developing_plugins.html which describes most of
I wrote (although, in a bit of a less verbose way, and without
examples).

I hope this helps.

Best regards

-- 
Branko Majic
Jabber: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
Џабер: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.

-- 
You received this message because you are subscribed to the Google Groups 
Ansible Project group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20141126230152.52d18fcb%40zetkin.primekey.se.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: PGP signature


[ansible-project] Role encapsulation, DRY, and convention over configuration

2014-10-25 Thread Branko Majic
Hello all,

I am still quite new to Ansible (but coming from Puppet background, so
my perspective might be a bit skewed to top it off), and I am currently
trying to figure out what would be the best way to layout roles while
attempting to apply DRY (don't repeat yourself) principles as much as
possible. Plus, I'm trying to have somewhat complex deployment with
providing as little input as possible (kind of convention over
configuration).

My current goal is to deploy one or more Django projects on a single
host/group of hosts. Currently I have the following roles:

- common - Sets-up some basic things on the OS, amongst
  other things the OS users and groups. Users and groups are read from
  two list variables.

- virtualenv - Sets-up Python virtual environments. Virtual
  environments are read from a single list variable that includes info
  about mode for files/dirs, users that should own the virtual
  environment, destination directory etc.

- supervisor - Sets-up supervisor for running (in this case) one or
  more WSGI applications. List of supervisor configurations (apps to
  monitor) is passed via list, with each item containing info about
  what user should run the command, command itself etc.

Now, the above should be mostly enough to deploy all the things
necessary for a project (bits and pieces missing, but I'm sure I can
handle those). From here, though, I am finding some issues on how to
properly encapsulate this.

For start, I do have an idea of a convention I want to apply for my
deployments. This includes specific user/group naming based on a
project name, destination directory for virtualenv etc. What I'm looking
into would be being able to pass in only a couple of values via
variables (let's say name, user and group) to my high-level role (or
perhaps playbook), and calculate the non-specified parameters (required
by roles common, virtualenv, and supervisor) from those. I would also
want to deploy multiple Django projects (this is the important part) on
the same host/group.

From my (perhaps naive) understanding, I have the following options:

1. Try to create a new role, called django, which would basically
iterate over a list of projects. The problem is that I need to pass in
some relatively complex (with calculations included) structures to
roles common, virtualenv, and supervisor, and variable manipulation is a
bit limited within the yml files. I think I would probably be able to
use include directive in combination with a custom lookup plugin. I
have tried using set_fact with with_items to try to append to lists, but
that didn't work for me (only the last item from with_items got
appended).

2. Ditch the effort for DRY and separation, and simply have one
monolithic django role that'll deploy user/group, virtualenv,
supervisor etc. Still, there might be some rather similar set-ups where
I'd end-up duplicating all of the tasks and logic.

3. Instead of deploying through a single site.yml, use
deployment-specific (one-timish) playbook. I would, however, need to
somehow keep track of what Django project gets deployed where. What
would be the best way to do this with Ansible?

4. Something else someone suggests from this list :)

Any recommendations on what would be the best way to proceed with this?
I'm open to all suggestions. If someone has a good link to share, which
demonstrates solution for such a deployment, that'd be appreciated as
well :)

Best regards

-- 
Branko Majic
Jabber: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
Џабер: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.


signature.asc
Description: PGP signature