@@ -3,6 +3,7 @@ package e2e_test
33import (
44 "fmt"
55 "os"
6+ "os/exec"
67 "path/filepath"
78 "runtime"
89 "strconv"
@@ -98,6 +99,59 @@ var _ = Describe("podman machine init", func() {
9899 }
99100 })
100101
102+ It ("run playbook" , func () {
103+ str := randomString ()
104+
105+ // ansible playbook file to create a text file containing a random string
106+ playbookContents := fmt .Sprintf (`
107+ - name: Simple podman machine example
108+ hosts: localhost
109+ tasks:
110+ - name: create a file
111+ ansible.builtin.copy:
112+ dest: /home/core/foobar.txt
113+ content: "%s\n"
114+ ` , str )
115+
116+ tmpDir , err := os .MkdirTemp ("" , "" )
117+ defer func () { _ = utils .GuardedRemoveAll (tmpDir ) }()
118+ Expect (err ).ToNot (HaveOccurred ())
119+
120+ // create the playbook file
121+ playbookFile , err := os .Create (filepath .Join (tmpDir , "playbook.yaml" ))
122+ Expect (err ).ToNot (HaveOccurred ())
123+
124+ // write the desired contents into the file
125+ _ , err = playbookFile .WriteString (playbookContents )
126+ Expect (err ).To (Not (HaveOccurred ()))
127+
128+ name := randomString ()
129+ i := new (initMachine )
130+ session , err := mb .setName (name ).setCmd (i .withImage (mb .imagePath ).withRunPlaybook (filepath .Join (tmpDir , "playbook.yaml" )).withNow ()).run ()
131+ Expect (err ).ToNot (HaveOccurred ())
132+ Expect (session ).To (Exit (0 ))
133+
134+ // calculate sha256sum of local playbook file
135+ cmd := exec .Command ("sha256sum" , filepath .Join (tmpDir , "playbook.yaml" ))
136+ shasum , err := cmd .Output ()
137+ Expect (err ).ToNot (HaveOccurred ())
138+
139+ // calculate the sha256sum of the playbook file on the guest
140+ ssh := & sshMachine {}
141+ sshSession , err := mb .setName (name ).setCmd (ssh .withSSHCommand ([]string {"sha256sum" , "playbook" })).run ()
142+ Expect (err ).ToNot (HaveOccurred ())
143+
144+ // compare the two and make sure they are the same
145+ Expect (strings .Split (string (shasum ), " " )[0 ]).To (Equal (strings .Split (sshSession .outputToString (), " " )[0 ]))
146+
147+ // output the contents of the file generated by the playbook
148+ // sshSession, err = mb.setName(name).setCmd(ssh.withSSHCommand([]string{"cat", "foobar.txt"})).run()
149+ // Expect(err).ToNot(HaveOccurred())
150+
151+ // check its the same as the random number or string that we generated
152+ // Expect(sshSession.outputToString()).To(Equal(str))
153+ })
154+
101155 It ("simple init with start" , func () {
102156 i := initMachine {}
103157 session , err := mb .setCmd (i .withImage (mb .imagePath )).run ()
0 commit comments