Re: Post about ansible + Fedora 23

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



$ sudo dnf install pandoc
$ pandoc --to=html -i post.rst -o post.html

<3 Pandoc 4 eva

Give it a look to make sure nothing was lost in translation, but it should have gotten the draft pretty close.

Happy Hacking,
--RemyD.

On Wed, Nov 4, 2015 at 1:04 AM, Justin W. Flory <jflory7@xxxxxxxxx> wrote:
On 11/03/2015 11:04 PM, Dusty Mabe wrote:
Hi all,

I thought it would be useful to educate people on Ansible with a Fed Mag
post. I wrote up something at the link below. Take a look and let me
know what you think.

https://gist.github.com/dustymabe/e844bc6d7ab15017d38b

Hi Dusty,

This looks like something that would be pretty useful for the Magazine - do you think you could work on converting it into a WordPress draft? I definitely think this is something we add to the upcoming publishing queue!

Cheers,
------------

Justin W. Flory
jflory7@xxxxxxxxx


--
marketing mailing list
marketing@xxxxxxxxxxxxxxxxxxxxxxx
List info or to change your subscription:
https://admin.fedoraproject.org/mailman/listinfo/marketing

Inspired mostly from this post by Lars Kellogg-Stedman.

Intro

Fedora 23 is using python 3 as the default python version that gets installed (see changes), but Ansible still requires python 2. For that reason Ansible errors out when you try to run it because it assumes python 2 by default:

GATHERING FACTS *
failed: [f23] => {"failed": true, "parsed": false}
/bin/sh: /usr/bin/python: No such file or directory

Fortunately there are a few steps you can add to your playbooks in order to fully workaround this problem. You can either choose to apply then in a single play or in mulitple plays as shown below.

Workaround - Single All-in-One Play

In the case of a single play, which is something I use often when applying configuration to vagrant boxes you can workaround this problem by taking the following steps:

The gathering of facts that happens by default on ansible execution will try to use python 2. We must disable this or it will fail before executing the raw ssh commands to install python 2. Fortunately we can still use facts in our single play, though, by explicitly calling the setup module after python2 is installed.

So with these minor changes applied a simple all in one play might look like:

- hosts: f23
  remote_user: fedora
  gather_facts: false
  become_user: root
  become: yes
  tasks:
    - name: install python and deps for ansible modules
      raw: dnf install -y python2 python2-dnf libselinux-python
    - name: gather facts
      setup:
    - name: use facts
      lineinfile: dest=/etc/some-cfg-file line="myip={{ ansible_eth0.ipv4.address }}" create=true

And the output of running the play should be successful:

PLAY [f23] **************************************************************** 

TASK: [install python and deps for ansible modules] *************************** 
ok: [f23]

TASK: [gather facts] ********************************************************** 
ok: [f23]

TASK: [use facts] ************************************************************* 
changed: [f23]

PLAY RECAP ******************************************************************** 
f23                        : ok=3    changed=1    unreachable=0    failed=0

Workaround - Multiple Plays

If you use multiple plays in your playbooks then you can simply have one of them do the python 2 install in raw mode while the others can remain unchanged; you don't have to explicitly gather facts because python 2 is now installed. So for the first play you would have something like:

- hosts: f23
  remote_user: fedora
  gather_facts: false
  become_user: root
  become: yes
  tasks:
    - name: install python and deps for ansible modules
      raw: dnf install -y python2 python2-dnf libselinux-python

And, re-using the code from the sample above the second play would look like:

- hosts: f23
  remote_user: fedora
  become_user: root
  become: yes
  tasks:
    - name: use facts
      lineinfile: dest=/etc/some-cfg-file line="myip={{ ansible_eth0.ipv4.address }}" create=true

Conclusion

So using these small changes you should be back up and running until Ansible adds first class support for python 3.

Enjoy!
Dusty

-- 
marketing mailing list
marketing@xxxxxxxxxxxxxxxxxxxxxxx
List info or to change your subscription:
https://admin.fedoraproject.org/mailman/listinfo/marketing

[Index of Archives]     [Fedora Mentors]     [Kernel Developers]     [Fedora Packaging]     [Fedora Desktop]     [PAM]     [Gimp Users]     [Yosemite Camping]

  Powered by Linux